-1
我必須創建一個程序,允許用戶輸入包含名稱,地址,城市,州,郵政編碼和年齡的信息。數據結構ArrayList將用於存儲信息。創建用於創建對象的類以及用於訪問信息的類方法。使用ArrayList存儲信息並訪問信息
- 創建一個名爲GroupArrayProject的類,它將包含main方法。
- 您將爲名稱,地址,城市,州,郵編和年齡變量創建一個名爲People use ArrayList的類。
- 創建一個名爲AddRecord的方法
- AddRecord將調用添加記錄的方法,其目的是調用將要使用的其他方法。
- 這些其他方法(例如addName())將被調用並用於輸入上述每個ArrayList的信息。
- 創建一個菜單,允許程序:
一個。顯示您輸入的所有記錄
b。以顯示最早或最年輕
c。使用名字或姓氏查找記錄。
public class people {
String name, address, city, state, zipcode, age;
public people() {
name = null;
address = null;
city = null;
state = null;
zipcode = null;
age = null;
}
public void setpeople(String n, String ad, String c, String s, String z, String a) {
name = n;
address = ad;
city = c;
state = s;
zipcode = z;
age = a;
}
public string AddRecord
public String getpeople() {
String p = "name:" + name + "\n" + "address:" + address + "\n" + "city:" + city + "\n" + "state:" + state + "\n" + "zip code:" + zipcode + "\n" + "age:" + age;
return p;
}
}
public class GroupArrayProject {
public static void main(String[] args) {
{
ArrayList <String> list = new ArrayList <String>();
people two = new people();
Scanner one = new Scanner(System.in);
System.out.println("type in your name,address,city,state,zipcode and age ");
String a = one.next();
String b = one.next();
String c = one.next();
String d = one.next();
String e = one.next();
String f = one.next();
two.setpeople(a, b, c, d, e, f);
System.out.println(two.getpeople());
}
}
}
這是我到目前爲止,我真的不知道下一步
可能首先使用變量,類和方法的專有名稱?只是一個想法..然後你的問題究竟是什麼? – xander