public static void main(String[] args) {
// (三)无返回,有参数的方法:
// 设置当前狗的姓名的方法,要求传入狗的新姓名,修改当前姓名。
// 设置当前狗的性别的方法,要求传入狗的新性别,修改当前性别。
// 设置当前狗的品种的方法,要求传入狗的新品种,修改当前品种。
// 写一个测试类,要求首先生成一只狗,使用设置方法将狗的属性设上值,再调用狗跑步的方法,
// 调用狗长大的方法。再调用得到狗姓名的方法,接收返回,并输出返回的姓名。
// 最后使用输出,将这只狗的所有 信息输出。
// Dog w=new Dog();
// w.name="看看";
// w.sex="公";
// w.pz="柯基";
// w.run();
// w.grow();
// System.out.println(w.getName);
// System.out.println(w);
//
// /**
// * 控制台版的方法测试
// */
// MyClass ma = new MyClass();
// Scanner mys = new Scanner(System.in);
// ma.names = new String[10];
// while(true) {
// System.out.println("欢迎来到学生管理系统");
// System.out.println("请输入你的选择:1.增加名字;2.删除名字;3.修改名字;4.查询名字;5.打印所有名字;"
// + "6.退出");
// /**
// * 用户选择的功能
// */
// int x = mys.nextInt();
// if(x == 1) {//增加名字
// System.out.println("请输入你要增加的名字:");
// String name =mys.next();
// /**
// * 调用MyClass类里面增加名字的
// */
// ma.insert(name);
// }else if (x == 2) {//删除名字
// System.out.println("请输入你要删除的名字:");
// String name =mys.next();
// /**
// * 调用MyClass类里面删除名字的方法
// */
// System.out.println(ma.delete(name));
// }else if (x == 3) {//修改名字
// System.out.println("请输入修改前的名字:");
// String oldName = mys.next();
// System.out.println("请输入修改后的名字:");
// String newName = mys.next();
// /**
// * 调用MyClass类里面修改名字的方法
// */
// System.out.println(ma.update(oldName, newName));
// }else if (x == 4) {//查询名字
// System.out.println("请输入你要查询的名字:");
// String name = mys.next();
// /**
// * 调用MyClass类里面查询名字的方法
// */
// System.out.println(ma.querySingle(name));
// }else if (x == 5) {//打印所有名字
// /**
// * 调用MyClass类里面打印所有名字的的方法
// */
// ma.printAll();
// }else if (x == 6) {//退出系统
// System.out.println("你确定要退出吗?yes/no");
// String as = mys.next();
// if(as.equals("yes")) {
// System.out.println("退出系统");
// break;
// }
// }else {
// System.out.println("请正常操作!");
// }
//
-------------------------------------------------------------------------------------------------------------------
/定义班级
public String abb="T288";
//定义班级的花名册-数组
public String[]name;
/**
*
* @param name
* @return
*/
public String querySingle(String name) {
String message=null ;// 用来保存信息
boolean a = false;// 假设要查询的名字不存在花名册里面
if (names!=null) {// 如果数组有名字才开始查找。
// 开始遍历花名册数组 names
for (int i = 0; i < this.name.length; i++) {
if (names[i]=null) {//如果这个位置有名字,才开始判断这个名字是不是我们要找的名字
if (names[i].equals(name)) {// 开始判断这个位置的名字是不是我们要找的名字
message= "你要查询的名字【"+name+"】的下标是:"+i;
a=ture;//找到名字
break;// 找到之后后面的就不用再判断了。
}
}
}
//如果f的值还是false没有改变,则要查询的名字不存在
if (a==false) {
message = "你要查询的名字【"+name+"】不存在!";
}
}else {//数组为空
message="花名册为空!";
}
return message;// 最后返回查询的结果信息
/**
* 增加名字方法
* 未考虑情况:
* 1.未判断数组是否为null;
*
*/
public void abc(String name) {
for (int i = 0; i <this. name.length; i++) {
if (name[i]==null) {// 如果这个座位为null
names[i]=name;//给该位置赋值
System.out.println("名字【"+name+"】添加成功!");
break;// 后面的位置就不用再判断
}
}
}
/**
* 3.删除名字方法
* @param name
* @return
*/
public String de(String name) {
boolean f = false;// 假设要删除的名字不存在
String message = null; // 保存删除的提示信息
if(names != null) {// 数组不为null
for (int i = 0; i < names.length; i++) {
if(names[i] != null) {// 有名字,才开始判断是不是要删除的名字
if(names[i].equals(name)) {// 如果找到了要删除的名字
names[i] = null;// 删除名字
f = true;// 找到了要删除的名字
message = "名字【"+name+"】删除成功!";
break;// 删除成功后,后面的就不用再判断了。
}
}
}
if(f == false) {
message = "要删除的名字【"+name+"】不存在!";
}
}else {
message = "数组为空!";
}
return message;
}
/**
*
* @param oldName
* @param newName
* @return
*/
public String up(String oldName,String newName) {
String message = null;// 保存修改提示信息
boolean f = false;// 假设要修改的名字不存在
if(names != null) {
for (int i = 0; i < names.length; i++) {
if(names[i] != null) {//这个位置有人
if(names[i].equals(oldName)) {// 如果找到要修改的名字
f = true;
names[i] = newName;// 开始修改,就是重新给该位置赋值。
message = "名字【"+oldName+"】修改成功!";
break;// 修改成功后,后面的就不用再进行判断。
}
}
}
if(f == false) {
message = "你要修改的名字【"+oldName+"】不存在!";
}
}else {
message = "数组为空!";
}
return message;
}
/**
public void printAll() {
if(names != null) {
// 遍历数组
System.out.println("******************数组里面的名字如下:******************");
for (String na : names) {
if(na != null) {// 位置有名字才打印
System.out.println(na);
}
}
}else {
System.out.println("数组为null!");
}
}