import java.util.ArrayList;
import java.io.DataOutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.*;
import java.util.Scanner;
class AddressBook{
private String name;
private String class1;
private String cellphone;
private String telphone;
private String email;
private String address;
private String postCode;
public AddressBook(String name,String class1,String cellphone,String telphone,String email,String address,String postCode){
this.name=name;
this.class1=class1;
this.cellphone=cellphone;
this.telphone=telphone;
this.email=email;
this.address=address;
this.postCode=postCode;
}
public String getClass1(){
return this.class1;
}
public void setClass1(String class1){
this.class1=class1;
}
public String getName(){
return this.name;
}
public void setName(String name){
this.name=name;
}
public String getCellphone(){
return this.cellphone;
}
public void setCellphone(String celllphone){
this.cellphone=cellphone;
}
public String getTelphone(){
return telphone;
}
public void setTelphone(String telphone){
this.telphone=telphone;
}
public String getEmail(){
return email;
}
public void setEmail(String email){
this.email=email;
}
public String getAddress(){
return address;
}
public void setAddress(String address){
this.address=address;
}
public String getPostCode(){
return postCode;
}
public void setPostCode(String postCode){
this.postCode=postCode;
}
public void output(){
DataOutputStream dataOutput=null;
try{
dataOutput =new DataOutputStream(new FileOutputStream("e:\\ping.txt"));
dataOutput.writeUTF("班级:"+class1+";姓名:"+name+";手机:"+cellphone+";家庭电话:"+telphone+";电子邮件:"+email+";地址"+address+";邮编"+postCode);
}catch(FileNotFoundException e){
e.printStackTrace();
}catch(IOException e){
e.printStackTrace();
}finally{
if(dataOutput!=null){
try{
dataOutput.close();
}catch(IOException e){}
}
}
}
}
class ClassAddressBook{
private String class1Name;
private int studentNumber;
private ArrayList addressBook=new ArrayList();
public AddressBook getAddressBook(AddressBook addres){
int location=this.addressBook.indexOf(addres);
return (AddressBook)this.addressBook.get(location);
}
public void add(AddressBook addres){
this.addressBook.add(addres);
}
public void remove(AddressBook addres){
this.addressBook.remove(addres);
}
public boolean contains(AddressBook addres){
return this.addressBook.contains(addres);
}
public void change(AddressBook address1,String name,String class1,String cellphone,String telphone,String email,String address,String postCode){
int loc = addressBook.indexOf(address1);
AddressBook address2=(AddressBook)addressBook.get(loc);
address2.setName(name);
address2.setClass1(class1);
address2.setCellphone(cellphone);
address2.setTelphone(telphone);
address2.setEmail(email);
address2.setAddress(address);
address2.setPostCode(postCode);
}
public void output(){
int i;
AddressBook address=null;
for(i=0;i<addressBook.size();i++)
{
address=(AddressBook)this.addressBook.get(i);
address.output();
}
}
}
public class Test {
AddressBook a=null;
ClassAddressBook b=new ClassAddressBook();
void input(){
try{
InputStreamReader name=new InputStreamReader(System.in);
BufferedReader inputName =new BufferedReader(name);
System.out.println("姓名:");
String strname=inputName.readLine();
InputStreamReader class1=new InputStreamReader(System.in);
BufferedReader inputclass1 =new BufferedReader(class1);
System.out.println("班级:");
String strclass1=inputclass1.readLine();
InputStreamReader cellphone=new InputStreamReader(System.in);
BufferedReader inputCellphone =new BufferedReader(cellphone);
System.out.println("手机:");
String strcellphone=inputCellphone.readLine();
InputStreamReader telphone=new InputStreamReader(System.in);
BufferedReader inputTelphone =new BufferedReader(telphone);
System.out.println("家庭电话:");
String strtelphone=inputTelphone.readLine();
InputStreamReader email=new InputStreamReader(System.in);
BufferedReader inputEmail =new BufferedReader(email);
System.out.println("电子邮件:");
String stremail=inputEmail.readLine();
InputStreamReader address=new InputStreamReader(System.in);
BufferedReader inputAddress =new BufferedReader(address);
System.out.println("地址:");
String straddress=inputAddress.readLine();
InputStreamReader postCode=new InputStreamReader(System.in);
BufferedReader inputpostCode =new BufferedReader(postCode);
System.out.println("邮编:");
String strpostCode=inputpostCode.readLine();
a=new AddressBook(strname,strclass1,strcellphone,strtelphone,stremail,straddress,strpostCode);
}catch(Exception e){}
}
public static void main(String[] args)throws IOException{
System.out.println("通讯录:");
System.out.println("1.添加同学信息:");
System.out.println("2.修改信息");
System.out.println("3.删除信息:");
System.out.println("4.查找信息:");
Test c=new Test();
int i=1;
while(i!=0){
System.out.println("请选择操作:");
int ch;
Scanner in = new Scanner(System.in);
ch=in.nextInt();
if(ch==0) break;
switch(ch){
case 1:
System.out.println("1.请输入同学通讯录信息:");
c.input();
c.b.add(c.a);
break;
case 2:
System.out.println("2.修改信息:");
c.b.change(c.a,"wangpingping","1ban","183531231008","3824031","232@323","weifang","262509");
c.b.output();
break;
case 3:
System.out.println("3.删除信息:");
c.b.remove(c.a);
c.b.output();
break;
case 4:
System.out.println("4.查找信息:");
c.b.contains(c.a);
c.b.output();
break;
default:
System.out.println("Error!");
}
}
}
}
tongxunlu.rar_java 通讯录
版权申诉
190 浏览量
2022-09-21
18:10:19
上传
评论
收藏 6KB RAR 举报
JaniceLu
- 粉丝: 84
- 资源: 1万+
最新资源
- 基于python的图书推荐管理系统设计与实现
- 基于STM32F072C8T6单片机PWM波控制蜂鸣器实验软件例程 KEIL工程源码+核心板硬件PDF原理图.zip
- debian package
- Redis 命令脑图.zip
- 机器学习使用Stable Diffusion实现潜在空间搜索
- 基于Python+tkinter+MySQL的图书管理系统+设计报告+PPT(课程设计高分项目).zip
- 更改网易云音乐云盘歌曲ID
- 机器学习使用Stable Diffusion实现潜在空间搜索
- 大作业基于python+tkinter学生成绩管理系统带登录界面完整源代码.zip
- UtilJson.unitypackage
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈