java实现电话本管理系统

时间:2022-09-03 15:54:53

java实现一个简单的电话本管理系统,能存储100个人的姓名、性别、年龄、电话等信息,并能对此系统进行增删改查的操作。

部分代码如下:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
public class phbook {
public static void main(string[] args) {
       person personarray[] = new person[100];
       int index = 0;
       for (int i = 0; i < 100; i++) {
          system.out.println("电话本管理系统");
          system.out.println("1.添加   2.删除   3.修改   4.查询所有   5.根据姓名查询   0.退出");
          system.out.println("请选择业务");
          scanner input = new scanner(system.in);
          int a = input.nextint();
     switch (a) {
    case 0: {
      system.out.println("退出系统");
      i = 101;
    }
      ;
      break;
    case 1: {
      system.out.println("添加电话本");
      system.out.print("姓名:");
      scanner n = new scanner(system.in);
      string name = n.next();
      system.out.print("性别:");
      scanner s = new scanner(system.in);
      string sex = s.next();
      system.out.print("年龄:");
      scanner ag = new scanner(system.in);
      string age = ag.next();
      system.out.print("电话:");
      scanner tel = new scanner(system.in);
      string telnum = tel.next();
      system.out.print("qq:");
      scanner q = new scanner(system.in);
      string qq = q.next();
      system.out.print("地址:");
      scanner add = new scanner(system.in);
      string address = add.next();
      personarray[index] = new person(name, sex, age, telnum, qq,
          address);
      index = index + 1;
    }
      ;
      break;
    case 2: {
      system.out.println("删除电话本");
      system.out.println("需要删除的姓名:");
      scanner name0 = new scanner(system.in);
      string namedel = name0.next();
      for (int j = 0; j < index; j++) {
        if (namedel.equals(personarray[j].name) == true) {
          for (int n = j; n < index - 1; n++) {
            personarray[n] = personarray[n + 1];
          }
          index = index - 1;
          break;
        }
        if (j == index - 1) {
          system.out.println("查无此人");
        }
      }
    }
      ;
      break;
    case 3: {
      system.out.println("修改电话本");
      system.out.println("需要修改的姓名:");
      scanner name00 = new scanner(system.in);
      string nameedit = name00.next();
      for (int k = 0; k < index; k++) {
        if (nameedit.equals(personarray[k].name) == true) {
          system.out.print("姓名:");
          scanner xm1 = new scanner(system.in);
          string name1 = xm1.next();
          system.out.print("性别:");
          scanner xb1 = new scanner(system.in);
          string sex1 = xb1.next();
          system.out.print("年龄:");
          scanner nl1 = new scanner(system.in);
          string age1 = nl1.next();
          system.out.print("电话:");
          scanner dh1 = new scanner(system.in);
          string telnum1 = dh1.next();
          system.out.print("qq:");
          scanner q1 = new scanner(system.in);
          string qq1 = q1.next();
          system.out.print("地址:");
          scanner dz1 = new scanner(system.in);
          string address1 = dz1.next();
          personarray[k] = new person(name1, sex1, age1, telnum1,
              qq1, address1);
          break;
        }
        if (k == index - 1) {
          system.out.println("查无此人");
        }
      }
    }
      ;
      break;
    case 4: {
      system.out.println("显示所有电话本");
      for (int l = 0; l < index; l++) {
        system.out.println(personarray[l].tostring());
      }
    }
      ;
      break;
    case 5: {
      system.out.println("查询电话本");
      system.out.println("需要查询的姓名:");
      scanner na = new scanner(system.in);
      string nameprint = na.next();
      for (int m = 0; m < index; m++) {
        if (nameprint.equals(personarray[m].name) == true) {
          system.out.println(personarray[m].tostring());
          break;
        }
        if (m == index - 1) {
          system.out.println("查无此人");
        }
      }
    }
      ;
      break;
    default: {
      system.out.println("无此功能");
    }
      ;
      break;
    }
  }
public person(string name, string sex, string age, string telnum,
    string qq, string address) {
  this.name = name;
  this.sex = sex;
  this.age = age;
  this.telnum = telnum;
  this.qq = qq;
  this.address = address;
 
}
 
public string tostring() {
  return " [姓名=" + name + ", 性别=" + sex + ", 年龄=" + age + ", 电话="
      + telnum + ",qq=" + qq + ", 地址=" + address + "]";
}

下面是程序运行的结果:

java实现电话本管理系统java实现电话本管理系统

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。

原文链接:http://blog.csdn.net/hpepm6_2/article/details/48245823