欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

java实现电话本管理系统

程序员文章站 2022-05-03 10:28:25
用java实现一个简单的电话本管理系统,能存储100个人的姓名、性别、年龄、电话等信息,并能对此系统进行增删改查的操作。 部分代码如下: public clas...

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

部分代码如下:

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实现电话本管理系统

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