java期末考试手写编程题1

为君一笑 提交于 2020-01-06 17:22:00

通讯录管理:姓名 公司 电话 邮编 


//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("----------------");
		}
		//显示 
	}
}

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!