java获取用户信息_java问题!!获取用户信息!!

main需要按照用户输入的contacts,来获取多少次用户的信息(姓名,电话和邮箱);privatestaticContact[]readContacts(){Contact[]result;intnumContacts;Stringname,phone,email;Sys...

main需要按照用户输入的contacts,来获取多少次用户的信息(姓名,电话和邮箱);

private static Contact[] readContacts() {

Contact[] result;

int numContacts;

String name, phone, email;

System.out.println();

System.out.print("How many contacts do you have? ");

numContacts = KBD.nextInt();

KBD.nextLine();

System.out.println();

// create the array

result = new Contact[numContacts];

// Let the user know what they need to do

System.out.println("For each contact, enter their name.");

System.out.println("Optionally add a phone or email.");

// ACTIVITY 1: read in all the contacts' information

System.out.println();

System.out.print("Enter a contact's name: ");

System.out.print("Enter the contact's phone number (optional): ");

System.out.print("Enter the contact's e-mail address (optional): ");

// return the result

return result;

}

下面是class:

public Contact(String reqName, String reqPhone, String reqEmail) {

if ("".equals(reqName)) {

throw new IllegalArgumentException(

"Cannot create a contact with no name!");

}

name = reqName;

phone = reqPhone;

email = reqEmail;

}

// ----- getters --------------------------------------------------- //

public String getName() {

return name;

}

public String getPhone() {

return phone;

}

public String getEmail() {

return email;

}

// ----- setters --------------------------------------------------- //

public void setName(String req) {

name = req;

}

public void setPhone(String req) {

phone = req;

}

public void setEmail(String req) {

email = req;

}

展开

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值