Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Class 需要在多个类中调用方法的帮助吗_Class_Object - Fatal编程技术网

Class 需要在多个类中调用方法的帮助吗

Class 需要在多个类中调用方法的帮助吗,class,object,Class,Object,所以我有3门课相互交织在一起,我不知道我在哪里搞砸了。如有任何建议或帮助,将不胜感激 我使用的第一个类是callcustomer,它具有客户名字、街道地址、城市、州、邮政编码和电话号码的典型信息的所有getter和setter private String firstName; private String lastName; private String streetAddress; private String city; private String state; private Stri

所以我有3门课相互交织在一起,我不知道我在哪里搞砸了。如有任何建议或帮助,将不胜感激

我使用的第一个类是callcustomer,它具有客户名字、街道地址、城市、州、邮政编码和电话号码的典型信息的所有getter和setter

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;
}
第二个类是我调用方法并读取用户输入的地方。 这是我的假期家庭输入类

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);

}
之后,我有一个类,它是我的主要方法,它将调用并创建customer对象,该对象将提示用户在下面输入并显示其信息

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

你能详细说明一下什么是错误的,它应该做什么,预期的输出是什么吗?我应该在main方法中创建一个customer对象,然后它会提示输入用户的所有信息,并且应该以customer类中formatLabel()方法的格式返回显示的信息