您的位置:首页 > 其它

TelephoneBook-method包-TelephoneBookDB类

2015-09-01 11:20 316 查看
public class TelephoneBookDB {

TelephoneMain tel = new TelephoneMain();
public String[] peoples = new String[100];
private int i = 0;
Scanner sc = new Scanner(System.in);
/**
* 添加联系人信息
*/
public void toAdd(String name, String sex, String age, String phone, String qq, String address) {

while (i < 100) {

String people = "姓名:" + name + ",性别:" + sex + ",年龄:" + age + ",电话:" + phone + ",QQ:" + qq + ",地址:"
+ address;
peoples[i] = people;
System.out.println(people);
i++;
break;
}
System.out.println("添加成功");
System.out.println("————————————————————华丽分割线————————————————————");
tel.mainTelephone();
}

/**
* 修改联系人信息
*/
public void toUpdate(String name) {
int temp = 1;
for (int j = 0; j < i; j++) {
if (peoples[j].contains(name)) { // 根据输入的名字,查找所在的条数
System.out.println("你要修改联系人的信息如下:");
System.out.println(peoples[j]);
System.out.println("请输入新的信息:");

System.out.print("姓名:");
String newName = sc.nextLine();

System.out.print("性别:");
String newSex = sc.nextLine();

System.out.print("年龄:");
String newAge = sc.nextLine();

System.out.print("电话:");
String newPhone = sc.nextLine();

System.out.print("QQ:");
String newQq = sc.nextLine();

System.out.print("地址:");
String newAddress = sc.nextLine();

String newPeople = "姓名:" + newName + ",性别:" + newSex + ",年龄:" + newAge + ",电话:" + newPhone + ",QQ:" + newQq + ",地址:"
+ newAddress;
peoples[j] = newPeople;
System.out.println(newPeople);
System.out.println("修改成功!");
temp = 0;
System.out.println("————————————————————华丽分割线————————————————————");
tel.mainTelephone();
break;
}
}

if (temp == 1) {
System.out.println("查无此人!");
System.out.println("————————————————————华丽分割线————————————————————");
tel.mainTelephone();
}
}

/**
* 按照姓名查找联系人信息
*/
public void toQuery(String name) {
int temp = 1;
for (int j = 0; j < i; j++) {
if (peoples[j].contains(name)) { // 根据输入的名字,查找所在的条数
System.out.println("你要查询联系人的信息如下:");
System.out.println("————————————————————华丽分割线————————————————————");
System.out.println(peoples[j]);
temp = 0;
System.out.println("————————————————————华丽分割线————————————————————");
tel.mainTelephone();
break;
}
}
if (temp == 1) {
System.out.println("查无此人!");
System.out.println("————————————————————华丽分割线————————————————————");
tel.mainTelephone();
}
}

/**
* 查找所有联系人信息
*/
public void toQueryAll() {
System.out.println("所有联系人列表信息如下:");
System.out.println("————————————————————华丽分割线————————————————————");
for (int j = 0; j < i; j++) {
System.out.println(peoples[j]);
}
System.out.println("————————————————————华丽分割线————————————————————");
tel.mainTelephone();
}

/**
* 删除联系人信息
*/
public void toDele(String name) {
int temp = 1;
for (int j = 0; j < i; j++) {
if (peoples[j].contains(name)) { // 根据输入的名字,查找所在的条数
System.out.println("你要删除联系人的信息如下:");
System.out.println(peoples[j]);
System.out.println("确定要删除该联系人吗?1(是)0(否)");
int isDele = sc.nextInt();
if (isDele == 1) {
peoples[j] = ""; // 重新赋值,作为删除该条信息
System.out.println("删除成功!");
System.out.println("————————————————————华丽分割线————————————————————");
tel.mainTelephone();
}else{
System.out.println("————————————————————华丽分割线————————————————————");
tel.mainTelephone();
}
temp = 0;
break;
}
}
if (temp == 1) {
System.out.println("查无此人!");
System.out.println("————————————————————华丽分割线————————————————————");
tel.mainTelephone();
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: