榨汁机
package com.itheima.fiest;
public class zuoye3 {
String type;
public String zuoye3(String fruit) {
String juice=fruit+"汁";
return juice;
}
}
package com.itheima.fiest;
public class lianxi {
public static void main(String[] args) {
zuoye3 zz=new zuoye3();
zz.type="电动榨汁机";
String fruit="芒果";
String juice=zz.zuoye3(fruit);
System.out.println(juice);
}
}
CuctomerBiz与Test
package com.itheima.fiest;
public class CustomerBiz {
String[] names=new String[19];
public void addName(String name) {
for(int i=0;i<19;i++) {
if(names[i]==null) { //
names[i]=name;
break;
}
}
}
public void showNames() {
System.out.println("*******************");
System.out.println(" 客户列表 ");
System.out.println("*******************");
for(int i=0;i<19;i++) {
if(names[i]!=null) {
System.out.print(names[i]+" ");
}
}
}
}
Student与Test
package com.itheima.fiest;
public class Student {
String[] names=new String[19];
public void addName(String name) { //添加学生姓名
for(int i=0;i<19;i++) {
if(names[i]==null) {
names[i]=name;
break;
}
}
}
public boolean Studentname(String oldname,String newname) { //修改学生姓名
boolean find=false;
for(int i=0;i<19;i++) {
if(names[i]!=null&&names[i].equals(oldname)) { //
names[i]=newname;
find=true;
break;
}
}
return find;
}
//显示学生姓名
public void showname() {
System.out.println("本班学生列表:");
for(int i=0;i<19;i++) {
if(names[i]!=null) {
System.out.print(names[i]+" ");
}
}
System.out.println();
}
}
package com.itheima.fiest;
import java.util.*;
public class Test {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
Student student=new Student(); //
System.out.print("请输入学生姓名:");
String name1=input.next();
student.addName(name1); //
System.out.print("请输入学生姓名:");
String name2=input.next();
student.addName(name2);
System.out.print("请输入学生姓名:");
String name3=input.next();
student.addName(name3); //
student.showname();
System.out.print("请输入要修改的学生姓名:");
String oldname=input.next();
System.out.print("请输入新的学生姓名:");
String newname=input.next();
boolean find=student.Studentname(oldname, newname); //
if(find) {
System.out.println("***修改结果***");
System.out.println("找到并修改成功!");
}else {
System.out.println("***修改结果***");
System.out.println("没有找到!");
}
student.showname();
}
}