通讯录管理系统设计用JAVA实现以下代码 1)录入成员信息。基本信息:姓名、现就读大学名称及班级名、专业、家庭住址、家庭联系电话、邮编、本人联系电话等。2)删除一个成员信息。3)修改成员信息并保存 4)能够按姓名对成员信息进行检索并将检索结果显示在屏幕上。 5)能够按专业对成员信息进行检索并将检索结果显示在屏幕上。6)显示所有成员信息。 7)要求利用菜单的形式进行管理。
时间: 2024-04-04 15:35:18 浏览: 46
好的,我可以为您提供一个通讯录管理系统的JAVA实现代码,但是由于篇幅较长,建议您将其保存至本地进行查看。以下是代码:
```
import java.util.ArrayList;
import java.util.Scanner;
public class AddressBook {
public static void main(String[] args) {
ArrayList<Member> members = new ArrayList<>();
Scanner scanner = new Scanner(System.in);
int option = 0;
do {
System.out.println("请选择操作:");
System.out.println("1. 录入成员信息");
System.out.println("2. 删除成员信息");
System.out.println("3. 修改成员信息");
System.out.println("4. 按姓名检索成员信息");
System.out.println("5. 按专业检索成员信息");
System.out.println("6. 显示所有成员信息");
System.out.println("7. 退出系统");
option = scanner.nextInt();
switch (option) {
case 1:
addMember(members, scanner);
break;
case 2:
deleteMember(members, scanner);
break;
case 3:
modifyMember(members, scanner);
break;
case 4:
searchByName(members, scanner);
break;
case 5:
searchByMajor(members, scanner);
break;
case 6:
showAllMembers(members);
break;
case 7:
System.out.println("退出系统");
break;
default:
System.out.println("无效选项,请重新选择");
}
} while (option != 7);
}
private static void addMember(ArrayList<Member> members, Scanner scanner) {
System.out.println("请输入成员信息:");
System.out.print("姓名:");
String name = scanner.next();
System.out.print("现就读大学名称及班级名:");
String school = scanner.next();
System.out.print("专业:");
String major = scanner.next();
System.out.print("家庭住址:");
String address = scanner.next();
System.out.print("家庭联系电话:");
String phone = scanner.next();
System.out.print("邮编:");
String postalCode = scanner.next();
System.out.print("本人联系电话:");
String selfPhone = scanner.next();
Member member = new Member(name, school, major, address, phone, postalCode, selfPhone);
members.add(member);
System.out.println("成员信息添加成功");
}
private static void deleteMember(ArrayList<Member> members, Scanner scanner) {
System.out.println("请输入要删除的成员姓名:");
String name = scanner.next();
for (int i = 0; i < members.size(); i++) {
if (members.get(i).getName().equals(name)) {
members.remove(i);
System.out.println("成员信息删除成功");
return;
}
}
System.out.println("未找到成员信息");
}
private static void modifyMember(ArrayList<Member> members, Scanner scanner) {
System.out.println("请输入要修改的成员姓名:");
String name = scanner.next();
for (int i = 0; i < members.size(); i++) {
if (members.get(i).getName().equals(name)) {
System.out.println("请输入新的成员信息:");
System.out.print("姓名:");
name = scanner.next();
System.out.print("现就读大学名称及班级名:");
String school = scanner.next();
System.out.print("专业:");
String major = scanner.next();
System.out.print("家庭住址:");
String address = scanner.next();
System.out.print("家庭联系电话:");
String phone = scanner.next();
System.out.print("邮编:");
String postalCode = scanner.next();
System.out.print("本人联系电话:");
String selfPhone = scanner.next();
Member member = new Member(name, school, major, address, phone, postalCode, selfPhone);
members.set(i, member);
System.out.println("成员信息修改成功");
return;
}
}
System.out.println("未找到成员信息");
}
private static void searchByName(ArrayList<Member> members, Scanner scanner) {
System.out.println("请输入要检索的成员姓名:");
String name = scanner.next();
for (Member member : members) {
if (member.getName().equals(name)) {
System.out.println(member);
return;
}
}
System.out.println("未找到成员信息");
}
private static void searchByMajor(ArrayList<Member> members, Scanner scanner) {
System.out.println("请输入要检索的成员专业:");
String major = scanner.next();
boolean flag = false;
for (Member member : members) {
if (member.getMajor().equals(major)) {
System.out.println(member);
flag = true;
}
}
if (!flag) {
System.out.println("未找到成员信息");
}
}
private static void showAllMembers(ArrayList<Member> members) {
for (Member member : members) {
System.out.println(member);
}
}
}
class Member {
private String name;
private String school;
private String major;
private String address;
private String phone;
private String postalCode;
private String selfPhone;
public Member(String name, String school, String major, String address, String phone, String postalCode, String selfPhone) {
this.name = name;
this.school = school;
this.major = major;
this.address = address;
this.phone = phone;
this.postalCode = postalCode;
this.selfPhone = selfPhone;
}
public String getName() {
return name;
}
public String getSchool() {
return school;
}
public String getMajor() {
return major;
}
public String getAddress() {
return address;
}
public String getPhone() {
return phone;
}
public String getPostalCode() {
return postalCode;
}
public String getSelfPhone() {
return selfPhone;
}
@Override
public String toString() {
return "姓名:" + name + "\t" +
"现就读大学名称及班级名:" + school + "\t" +
"专业:" + major + "\t" +
"家庭住址:" + address + "\t" +
"家庭联系电话:" + phone + "\t" +
"邮编:" + postalCode + "\t" +
"本人联系电话:" + selfPhone;
}
}
```
希望这份代码可以帮助到您。
阅读全文