我正在对Java类进行介绍,并且坚持从事我的实验室工作。
我们正在建立一个继承类。教授为我们提供了Main
,Address
,PersonName
,PhoneNumber
和PersonRecord
。
我们的任务是创建一个包含客户ID,creditCardType,creditCardNumber和creditCardDate的类CustomerRecord
。我们指示我们制作一个类,并对“ CustomerRecord而不是Main”进行必要的更改
我继续为该课程设置了所有内容,但继续遇到以下相同错误:
Error:(20, 20) java: constructor CustomerRecord in class edu.cscc.CustomerRecord cannot be applied to given types;
required: java.lang.String,java.lang.String,java.lang.String,java.lang.String
found: edu.cscc.PersonName,edu.cscc.Address,edu.cscc.PhoneNumber,edu.cscc.PhoneNumber,edu.cscc.PhoneNumber,java.lang.String,java.lang.String,java.lang.String,java.lang.String
reason: actual and formal argument lists differ in length
下面是主要部分:
public class Main {
public static void main(String[] args) {
// Initialize test data
Address address = new Address("120 North Tulip Tree Drive",
"Jackson", "OH", "45640");
PersonName name = new PersonName("Dr.", "Adelaide", "Penelope",
"Aardvark", null);
PhoneNumber homephone = new PhoneNumber(740, 555, 1005);
PhoneNumber workphone = new PhoneNumber(740, 555, 2356);
PhoneNumber cellphone = new PhoneNumber(614, 555, 9723);
// TODO - after creating CustomerRecord class, uncomment the following code.
// Create sample customer record
CustomerRecord customer;
customer = new CustomerRecord (name, address, homephone, workphone, cellphone,
"123456","Visa","4111-1111-1111-1111", "12/25");
// Print customer record report
String namerpt = "Name: " + customer.getName().toString();
String addressrpt = "Address: " + address.getStreetAddress() + "\n" +
"\t" + address.getCity() + ", " + address.getState() + " " + address.getZip();
String phonerpt = "Home Phone: " + customer.getHomePhone().toString() + "\n" +
"Work Phone: " + customer.getWorkPhone().toString() + "\n" +
"Mobile Phone: " + customer.getCellPhone().toString();
System.out.println(namerpt+"\n"+addressrpt+"\n"+phonerpt+"\n"+
"Customer ID: "+customer.getCustomerID() + "\n"+
"Credit card type: "+customer.getCreditCardType() + "\n"+
"Credit card number: "+customer.getCreditCardNumber() + "\n"+
"Credit card date: "+customer.getCreditCardDate());
}
}
下面是我创建的Customer类:
public class CustomerRecord {
private String customerID;
private String creditCardType;
private String creditCardNumber;
private String creditCardDate;
public CustomerRecord(String customerID, String creditCardType, String creditCardNumber, String creditCardDate) {
this.customerID = customerID;
this.creditCardType = creditCardType;
this.creditCardNumber = creditCardNumber;
this.creditCardDate = creditCardDate;
}
//Accesor//Mutator
public String getCustomerID() {
return customerID;
}
public void setCustomerID(String customerID) {
this.customerID = customerID;
}
public String getCreditCardType() {
return creditCardType;
}
public void setCreditCardType(String creditCardType) {
this.creditCardType = creditCardType;
}
public String getCreditCardNumber() {
return creditCardNumber;
}
public void setCreditCardNumber(String creditCardNumber) {
this.creditCardNumber = creditCardNumber;
}
public String getCreditCardDate() {
return creditCardDate;
}
public void setCreditCardDate(String creditCardDate) {
this.creditCardDate = creditCardDate;
}
}
答案 0 :(得分:1)
由于您不应该更改{
...
"parent": "http://localhost:8080/categories/{id}",
...
}
类,因此请在Main
类中添加必要的字段并编辑构造函数,如下所示:
CustomerRecord
这样,private PersonName name;
private Address address;
private PhoneNumber homephone;
private PhoneNumber workphone;
private PhoneNumber cellphone;
private String customerID;
private String creditCardType;
private String creditCardNumber;
private String creditCardDate;
public CustomerRecord(PersonName name, Address address, PhoneNumber homephone, PhoneNumber workphone, PhoneNumber cellphone, String customerID, String creditCardType, String creditCardNumber, String creditCardDate) {
this.name = name;
this.address = address;
this.homephone = homephone;
this.workphone = workphone;
this.cellphone = cellphone;
this.customerID = customerID;
this.creditCardType = creditCardType;
this.creditCardNumber = creditCardNumber;
this.creditCardDate = creditCardDate;
}
构造函数的所有参数都得到处理。
答案 1 :(得分:0)
您有一个仅包含String
个参数的构造函数:
public CustomerRecord(String customerID, String creditCardType, String creditCardNumber, String creditCardDate) {
您必须构造一个带有9个参数的构造函数:
前五个是PersonName
,Address
,PhoneNumber
,PhoneNumber
和PhoneNumber
接下来的4个是您的String
参数
由于您的Main方法具有:
CustomerRecord customer;
customer = new CustomerRecord(name, address, homephone, workphone, cellphone,
"123456", "Visa", "4111-1111-1111-1111", "12/25");