电话本管理系统(使用数组)
来源:互联网 发布:占领中环 知乎 编辑:程序博客网 时间:2024/05/23 19:13
import java.util.Scanner;
public class Main {
private static Person[] persons = new Person[100];
private static Scanner input = new Scanner(System.in);
static boolean exist = true;
public static void main(String[] args) {
boolean isExit = false;
while (!isExit) {
System.out.println("-------------电话本管理系统--------------");
System.out.println("1.添加2.修改3.删除4.查询所有5.根据姓名查询0.退出");
System.out.println("-------------电话本管理系统--------------");
System.out.println("请输入选项:");
int choose = input.nextInt();
switch (choose) {
case 1:
add();
break;
case 2:
System.out.println("请输入要修改的姓名:");
reset(input.next());
break;
case 3:
System.out.println("请输入要删除的姓名:");
del(input.next());
break;
case 4:
show();
break;
case 5:
System.out.println("请输入要查询的姓名:");
find(input.next());
break;
case 0:
isExit = true;
break;
default:
break;
}
}
}
public static void add() {
Person person = new Person();
System.out.println("姓名:");
person.setName(input.next());
System.out.println("性别:");
person.setSex(input.next());
System.out.println("年龄:");
person.setAge(input.nextInt());
System.out.println("电话:");
person.setTellphone(input.nextLong());
System.out.println("qq:");
person.setQq(input.nextLong());
System.out.println("地址:");
person.setAddress(input.next());
for (int i = 0; i < persons.length; i++) {
if (persons[i] == null) {
persons[i] = person;
System.out.println(persons[i].toString());
break;
}
}
}
public static void reset(String name) {
for (int i = 0; i < persons.length; i++) {
if (persons[i] != null) {
if (persons[i].getName().equals(name)) {
exist = false;
System.out.println("请重新输入:");
Person person = new Person();
System.out.println("姓名:");
person.setName(input.next());
System.out.println("性别:");
person.setSex(input.next());
System.out.println("年龄:");
person.setAge(input.nextInt());
System.out.println("电话:");
person.setTellphone(input.nextLong());
System.out.println("qq:");
person.setQq(input.nextLong());
System.out.println("地址:");
person.setAddress(input.next());
persons[i] = person;
System.out.println(persons[i].toString());
break;
}
}
}
if (exist) {
System.out.println("查无此人");
}
exist = true;
}
public static void del(String name) {
for (int i = 0; i < persons.length; i++) {
if (persons[i] != null) {
if (persons[i].getName().equals(name)) {
exist = false;
System.out.println("确认要删除吗?1.确认2.取消");
int j = input.nextInt();
if (j == 1) {
persons[i] = null;
System.out.println("删除成功");
break;
}
}
}
}
if (exist) {
System.out.println("查无此人");
}
exist = true;
}
public static void show() {
for (int i = 0; i < persons.length; i++) {
if (persons[i] != null) {
System.out.println(persons[i].toString());
}
}
}
public static void find(String name) {
for (int i = 0; i < persons.length; i++) {
if (persons[i] != null) {
if (persons[i].getName().equals(name)) {
exist = false;
System.out.println(persons[i].toString());
break;
}
}
}
if (exist) {
System.out.println("查无此人");
}
exist = true;
}
}
class Person {
private String name ;
private String sex;
private int age;
private long tellphone;
private long qq;
private String address;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public long getTellphone() {
return tellphone;
}
public void setTellphone(long tellphone) {
this.tellphone = tellphone;
}
public long getQq() {
return qq;
}
public void setQq(long qq) {
this.qq = qq;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String toString() {
return "姓名:" + name + ", 性别" + sex + ", 年龄:" + age
+ ", 电话:" + tellphone + ", qq:" + qq + ", 地址:"
+ address ;
}
}
- 电话本管理系统(使用数组)
- 数组电话本管理系统
- 电话本管理系统(数组版)
- Java电话本管理系统(数组版)
- 电话本管理系统
- 电话本管理系统
- 电话本管理系统
- 电话本管理系统
- JAVA实现电话本管理系统
- Java面向对象练习-电话本管理系统
- 电话本管理系统集合框架版
- HashSet集合实现电话本管理系统
- 基于java的电话本管理系统
- 电话本系统
- VC++ 完整的例子(电话本管理)
- DOS电话本(数组的练习)
- 简述利用list实现简易电话本管理系统
- 【自学笔记】简单java电话本管理系统v1.0源码
- HDU 4274 - Spy's Work(树形DP)
- 第2周项目0-宣告“主权” 初识数据结构
- Android 使用极光推送自定义消息打造个性的消息推送效果
- 滑动窗口_单调队列入门 (白书P241)
- 二分查找
- 电话本管理系统(使用数组)
- Hello JSP!——<jsp:include>动作元素篇
- 问题记录
- LeetCode Delete Node in a Linked List
- JDK5至JDK8的新特性
- 正则表达式炼级攻略
- Spring mvc的相关问题
- 迭代器模式(一):销售管理系统中数据的遍历
- TCP&UDP部分细节