编写通讯录的简单JAVA类(AddList),要求如下
发布网友
发布时间:2022-04-09 05:09
我来回答
共2个回答
热心网友
时间:2022-04-09 06:38
public class LinkNote {
private int listId;
private String name;
private int num;
private String listtype;
public int getListId() {
return listId;
}
public void setListId(int listId) {
this.listId = listId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
public String getListtype() {
return listtype;
}
public void setListtype(String listtype) {
this.listtype = listtype;
}
public LinkNote(int listId, String name, int num, String listtype) {
super();
this.listId = listId;
this.name = name;
this.num = num;
this.listtype = listtype;
}
public LinkNote() {
super();
}
private void editName(String name){
this.setName(name);
}
private void editNum(int num){
this.setNum(num);
}
private void editType(String type){
this.setListtype(type);
}
private void showAll(List<LinkNote> links){
for (int i = 0; i < links.size(); i++) {
System.out.println(links.get(i).name + ","
+ links.get(i).listId + ","
+ links.get(i).num + ","
+ links.get(i).listtype);
}
}
}
热心网友
时间:2022-04-09 07:56
package test;
/**
* 1) 用private封装属性:编号、姓名、号码、类别(listid、name、num、listtype) 2)
* 设置要求1相关getter、setter方法(如getListId、setListId) 3) 设置相关构造方法 4)
* 添加修改姓名、号码、类别的方法(如editName) 5) 添加显示所有信息方法
*
* @author Retror
*
*/
public class AddList {
private int listId;
private String name;
private int num;
private String listType;
public AddList() {
}
public AddList(int listId, String name, int num, String listType) {
this.listId = listId;
this.name = name;
this.num = num;
this.listType = listType;
}
public int getListId() {
return listId;
}
public void setListId(int listId) {
this.listId = listId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
public String getListType() {
return listType;
}
public void setListType(String listType) {
this.listType = listType;
}
public void editName(String name) {
this.name = name;
}
public void editListType(String listType) {
this.listType = listType;
}
public void editListId(int listId) {
this.listId = listId;
}
public void editNum(int num) {
this.num = num;
}
@Override
public String toString() {
return "AddList [listId=" + listId + ", name=" + name + ", num=" + num
+ ", listType=" + listType + "]";
}
}
代码如上,希望能帮到你。