所以我有3个课程交织在一起,我不知道我在哪里弄乱。任何建议或帮助将不胜感激。
我正在使用的第一堂课是致电客户,并拥有所有获取者和设置者,以获取客户姓氏,街道地址,城市,州,邮编和电话号码的典型信息。
private String firstName;
private String lastName;
private String streetAddress;
private String city;
private String state;
private String zipCode;
private String phoneNumber;
public Customer() {
}
public Customer(String firstName, String lastName, String streetAddress,
String city, String state, String zipCode, String phoneNumber) {
this.firstName = firstName;
this.lastName = lastName;
this.streetAddress = streetAddress;
this.city = city;
this.state = state;
this.zipCode = zipCode;
this.phoneNumber = phoneNumber;
}
public String formatLabel() {
return firstName + " " + lastName + "\n" + streetAddress + "\n" + city
+ ", " + state + " " + zipCode + "\n" + formatPhoneNumber();
}
public String formatPhoneNumber(){
return String.valueOf(phoneNumber).replaceFirst("(\\d{3})(\\d{3})(\\d+)", "($1)-$2-$3");
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getStreetAddress() {
return streetAddress;
}
public void setStreetAddress(String streetAddress) {
this.streetAddress = streetAddress;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getZipCode() {
return zipCode;
}
public void setZipCode(String zipCode) {
this.zipCode = zipCode;
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
第二个类是我调用方法的地方,我正在读取用户输入。 它是我的VacationHomeInput类
public class VacationHomeInput {
Scanner scan = new Scanner(System.in);
public void readRentalOrder(){
VacationHomeRental info = new VacationHomeRental();
System.out.print("Enter start date in form mm/dd/yyyy: ");
String rentalDate = scan.nextLine();
info.setRentalDate(rentalDate);
System.out.print("Enter number of rental homes: ");
int numberOfVacationHomesRented = scan.nextInt();
info.setNumberOfVacationHomesRented(numberOfVacationHomesRented);
System.out.print("Enter number of days: ");
int numberOfDaysRented = scan.nextInt();
info.setNumberOfDaysRented(numberOfDaysRented);
}
public Customer readCustomer(){
Customer customer = new Customer();
System.out.print("Enter first Name: ");
String firstName = scan.nextLine();
customer.setFirstName(firstName);
System.out.print("Enter last name: ");
String lastName = scan.nextLine();
customer.setLastName(lastName);
System.out.print("Enter street address:");
String streetAddress = scan.nextLine();
customer.setStreetAddress(streetAddress);
System.out.print("Enter city: ");
String city = scan.nextLine();
customer.setCity(city);
System.out.print("Enter state: ");
String state = scan.nextLine();
customer.setState(state);
System.out.print("Enter zip code: ");
String zipCode = scan.nextLine();
customer.setZipCode(zipCode);
System.out.print("Enter phone number in form 999999999: ");
String phoneNumber = scan.nextLine();
customer.setPhoneNumber(phoneNumber);
return customer = new Customer(firstName, lastName, streetAddress, city, state, zipCode, phoneNumber);
}
之后我有一个类是我的主要方法,它将调用并创建客户对象,提示用户输入并在下面显示其信息
public static void main(String[] args) {
VacationHomeOutput output = new VacationHomeOutput();
Customer hotelInfo = new Customer(null,
"Holday Resort Vacation Home Rentals", "239 E. Hwy 98",
"Cocoa Beach", "FL", "32540", "8507291000");
Customer customer = new Customer();
output.displayCustomer();
customer.formatLabel();
hotelInfo.formatLabel();
}
这是输出:
Customer:
Enter first Name: rem
Enter last name: reyes
Enter street address:123 main
Enter city: normla
Enter state: il
Enter zip code: 60108+
Enter phone number in form 999999999: 6305046204
null null
null
null, null null
null