Date类
import java.util.Scanner;
/**
*
*/
/**
* @author 周雪飞_15K
* @time 2015年9月1日
*/
public class Date {
int i;
String[][] arr1 = new String[10][6];
String[] arr2 = { "姓名:", "性别:", "年龄:", "电话:", "QQ:", "地址:" };
public void assign() {
Scanner scanner = new Scanner(System.in);
for (int j = 0; j < arr2.length; j++) {
System.out.print(arr2[j]);
arr1[i][j] = scanner.next();
}
}
public void print() {
for (int j = 0; j < arr2.length - 1; j++) {
System.out.print(arr2[j] + arr1[i][j] + ",");
}
System.out.println(arr2[5] + arr1[i][5]);
}
public void update() {
String name;
System.out.print("请输入要修改的姓名:");
Scanner sc = new Scanner(System.in);
name = sc.next();
i = 0;
int ii = 0;
while (arr1[i][0] != null) {
if (name.equals(arr1[i][0])) {
print();
System.out.println("请重新输入信息");
assign();
print();
System.out.println("修改成功!");
ii = 1;
break;
}
i++;
}
if (ii == 0)
System.out.println("查无此人!");
}
public void append() {
i = 0;
int ii = 0;
while (ii == 0) {
if (arr1[i][0] == null) {
assign();
print();
System.out.println("添加成功!");
ii = 1;
}
i++;
}
}
public void select() {
i = 0;
while (arr1[i][0] != null) {
print();
i++;
}
}
public void delete() {
String name;
System.out.print("请输入要删除的姓名:");
Scanner sc = new Scanner(System.in);
name = sc.next();
i = 0;
int ii = 0;
while ((arr1[i][0] != null)) {
if (name.equals(arr1[i][0])) {
print();
System.out.println("确认要删除吗? 1(是)0(否)");
int iii = sc.nextInt();
if (iii == 0) {
ii = 1;
break;
} else if (iii == 1) {
init00();
System.out.println("删除成功!");
ii = 1;
break;
}
}
i++;
}
if (ii == 0)
System.out.println("查无此人!");
}
public void init00() {
while (arr1[i + 1][0] != null) {
for (int j = 0; j < arr2.length; j++) {
arr1[i][j] = arr1[i + 1][j];
}
i++;
}
for (int j = 0; j < arr2.length; j++)
arr1[i][j] = null;
}
}
log类
<p>import java.util.Scanner;</p><p>/**
*
*/</p><p>/**
* @author 周雪飞_15K
* @time 2015年9月1日
*/
public class log {</p><p> /**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Date date=new Date();
int nn = 0;
while (nn == 0) {
System.out.println("——————————————————电话本管理系统——————————————————");
System.out.println("1.添加 2.删除 3.查询所有 4.根据姓名查询 0退出");
System.out.println("—————————————————电话本管理系统——————————————————");
System.out.print("请选择:");
Scanner scanner = new Scanner(System.in);
int s = scanner.nextInt();
switch (s) {
case 1:
System.out.println("————————添加电话本————————");
date.append();
break;
case 2:
System.out.println("————————删除电话本————————");
date.delete();
break;
case 3:
System.out.println("————————打印电话本————————");
date.select();
break;
case 4:
System.out.println("————————修改电话本————————");
date.update();
break;
case 0:
System.exit(0);
break;
}
}
}
}
</p>