通讯录管理:姓名 公司 电话 邮编
//Test
package javatest;
public class Test {
public static void main(String[] args) {
Commus boo = new Commus();
boo.add();
boo.output();
}
}
//CommEntry
package javatest;
public class CommEntry {
private String name;
private String company;
private String tel;
private String postcode;
public CommEntry(String name,String company,String tel,String postcode){
this.name = name;
this.company = company;
this.tel = tel;
this.postcode = postcode;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCompany() {
return company;
}
public void setCompany(String company) {
this.company = company;
}
public String getTel() {
return tel;
}
public void setTel(String tel) {
this.tel = tel;
}
public String getPostcode() {
return postcode;
}
public void setPostcode(String postcode) {
this.postcode = postcode;
}
}
//Commus
package javatest;
import java.util.ArrayList;
import java.util.Scanner;
import java.io.*;
public class Commus {
ArrayList<CommEntry> list = new ArrayList<CommEntry>();
public void add()
{
String name;
String company;
String tel;
String postcode;
Scanner input = new Scanner(System.in);
System.out.println("请输入姓名:");
name = input.nextLine();
System.out.println("请输入公司:");
company = input.nextLine();
System.out.println("请输入电话:");
tel = input.nextLine();
System.out.println("请输入邮编:");
postcode = input.nextLine();
CommEntry con = new CommEntry(name,company,tel,postcode);
list.add(con);
//添加
}
public void output()
{
for(int i=0;i<list.size();i++)
{
CommEntry c = list.get(i);
System.out.println("姓名:"+c.getName());
System.out.println("公司:"+c.getCompany());
System.out.println("电话:"+c.getTel());
System.out.println("邮编:"+c.getPostcode());
System.out.println("----------------");
}
//显示
}
}