您想创建一个用于管理电话簿的程序。 为每个人提供了以下个人信息:Surname Name Title E-mail address (can not contain spaces and must contain the @ symbol) Company Position对于每一个可以存储以下电话号码的人(每个类别)Home Office Mobile Phone.还可以存储其他电话号码列表。对于每个其他号码,您必须存储电话号码 数字的描述。
这是我今晚必须在Java中做的作业。 我的问题是我如何实现各种类别:家庭,办公室,ecc ...哪个是实现这些类别的最佳解决方案?也许是一个枚举?在Java中实现类别的解决方案
这是我的实现:
import java.util.*;
public class Persona {
private String Name;
private String surname;
private String title;
private String mail_addr;
private String company
private String position;
private Phone homePhone;
private Phone officePhone;
private Phone mobilePhone;
private Collection<Phone> otherphonesList
public Persona(String n,String s,String t,String m,String c,String p,Phone hp,Phone of,Phone mp,Collection<Phone> otherphones)
{
name=n;
surname=s;
title=t;
mail_addr=m;
company=c;
position=p;
homePhone=hp;
officePhone=of;
mobilePhone=mp;
otherphonesList=new ArrayList<Phone>(otherphones);
}
public String getName()
{
return name;
}
public String getSurname()
{
return surname;
}
public String getTitle()
{
return title;
}
public String getMail()
{
return mail_addr;
}
public String getCompany()
{
return company;
}
public String getPosition()
{
return position;
}
}
public class Phone {
private String phone;
private String description;
public Phone(String phone,String description)
{
this.phone=phone;
this.description=description;
}
public String getPhone()
{
return phone;
}
public String getDescription()
{
return description;
}
}
并且不要忘记'title'字段:) – Matten
并且,请遵循[Java Code Conventions](http://www.oracle.com/technetwork/java/codeconv-138413.html)。 S /姓名/名称。 – Artem