这是一个添加/删除不同类型客户的简单程序。
我知道这可能很简单,但我已经有一段时间了。
不断收到错误,
constructor Customer in class Customer cannot be applied to the given types; required; java.lang. String, Address, char found:no arguments reason: actual and formal argument lists differ in length
我猜这与客户构造函数有关,但不知道。
public class Address
{
private String street,town;
/**
* Constructor for Address
*
* @param street The street
* @param town The town
*/
public Address (String street, String town)
{
this.street = street;
this.town = town;
}
/**
* @return The street
*/
public String getStreet()
{
return street;
}
/**
* @return The town
*/
public String getTown()
{
return town;
}
/**
* Change the street part of the address
*
* @param street The new street
*/
public void setStreet(String street)
{
this.street = street;
}
/**
* Change the town part of the address
*
* @param street The new town
*/
public void setTown(String town)
{
this.town = town;
}
public String toString()
{
return street + "\n" + town;
}
}
public class Name
{
private String fName, lName;
/**
* Constructor for Name
*
* @param fName The first name
* @param lName The last name
*/
public Name(String fName, String lName)
{
this.fName = fName;
this.lName = lName;
}
/**
* @return The first name
*/
public String getFName()
{
return fName;
}
/**
* @return The last name
*/
public String getLName()
{
return lName;
}
/**
* Amend the first name
*
* @param fName The new first name
*/
public void setFName(String fName)
{
this.fName = fName;
}
/**
* Amend the last name
*
* @param lName The new last name
*/
public void setLName(String lName)
{
this.lName = lName;
}
public String toString()
{
return fName + " " + lName;
}
}
public class Customer
{
// instance variables - replace the example below with your own
private String accountNumber;
private Address address;
private int balance;
private char customerType;
/**
* Constructor for objects of class Customer
*/
public Customer(String accountNumber, Address address, char customerType)
{
// initialise instance variables
this.accountNumber= accountNumber;
this.address= address;
balance = 0;
this.customerType=customerType;
}
/**
* Adds money to the ammount in the account
*/
public void credit(int amt)
{
balance= balance + amt;
}
/**
* removes money from the ammount in the account
*/
public void debit(int amt)
{
balance= balance - amt;
}
/**
* Returns the account number of the customer
*/
public String getAccountNumber()
{
return accountNumber;
}
/**
* returns the address of the customer
*/
public Address getAddress()
{
return address;
}
/**
* returns the balance of the customer
*/
public int getBalance()
{
return balance;
}
/**
* Returns the type of customer Bussiness or Personal
*/
public char getCustomerType()
{
return customerType;
}
public void setAddress(Address address)
{
this.address=address;
}
public String toString()
{
String output ="Account Number: " + accountNumber + "Customer Type: " + customerType + "balance: " + getBalance() + "Address: " + super.toString();
return output;
}
}
public class PersonalCustomer extends Customer
{
// instance variables
private Name name;
public PersonalCustomer(String accountNumber, Address address, Name name)
{
// initialise instance variables
this.accountNumber= accountNumber;
this.address=address;
this.name= Name;
}
public Name getName()
{
return + "Address: " + super.toString();
}
public void print()
{
System.out.println(toString());
}
public String toString()
{
String output = getFName() + getLName() + "\n" + "Account Number: " + accountNumber + "\n"
+ "Customer Type: " + customerType + "\n" + "Address: " + super.toString() + "\n"
+ "balance: " + getBalance();
return output;
}
}