我必須製作程序,詢問用戶姓名,地址,電話號碼,客戶號碼以及客戶是否希望添加到郵件列表(顯示爲true或假),然後顯示用戶信息我已經完成了整個程序的工作,唯一的問題是在我的toString()方法之間有一個空白區域。分配要求我,使整個程序在一個文件中沒有此空格是一個示例輸出:如何從超類調用toString
例
Customer:
Name: Julia Stevens
Address: 77 Massachusetts Ave Cambridge, MA 02139
Phone·Number: 617-777-7777
Customer·Number: 928734502
Recieve·Mail?: false
這裏是我的代碼: 代碼
public static void main(String[] args)
{
String personInput;
String customerInput;
Person A = new Person("", "", "");
Customer B = new Customer("", false, "", "", "");
Scanner input = new Scanner(System.in);
System.out.print("Enter name of customer:");
personInput = input.nextLine();
A.setName(personInput);
System.out.print("Enter address of customer:");
personInput = input.nextLine();
A.setAddress(personInput);
System.out.print("Enter phone number of customer:");
personInput = input.nextLine();
A.settNumber(personInput);
System.out.print("Enter customer number:");
customerInput = input.nextLine();
B.setcNumber(customerInput);
System.out.print("Enter yes/no -- does the customer want to receive mail?:");
customerInput = input.nextLine();
B.setmList(false);
if (customerInput.equals("yes"))
B.setmList(true);
else if (customerInput.equals("no"))
B.setmList(false);
System.out.println("");
System.out.println("Cutomer: ");
System.out.println(A.toString());
System.out.println(B.toString());
}
private static class Person
{
private String name;
private String address;
private String tNumber;
public Person(String name, String address, String tNumber)
{
this.name = name;
this.address = address;
this.tNumber = tNumber;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public String getAddress()
{
return address;
}
public void setAddress(String address)
{
this.address = address;
}
public String gettNumber()
{
return tNumber;
}
public void settNumber(String tNumber)
{
this.tNumber = tNumber;
}
@Override
public String toString() {
return "Name: " + name + "\n"
+ "Address: " + address + "\n"
+ "Phone Number: " + tNumber + "\n";
}
}
private static class Customer extends Person
{
private String cNumber;
private boolean mList;
public Customer(String cNumber, boolean mList, String name, String address, String tNumber)
{
super(name, address, tNumber);
this.cNumber = cNumber;
this.mList = mList;
}
public String getcNumber()
{
return cNumber;
}
public void setcNumber(String cNumber)
{
this.cNumber = cNumber;
}
public boolean ismList()
{
return mList;
}
public void setmList(boolean mList)
{
this.mList = mList;
}
@Override
public String toString() {
return "Customer Number: " + cNumber + "\n"
+ "Receive Mail?: " + mList;
}
'返回super.toString調用()+ 「客戶編號:」 不是的System.out.println + cNumber + 「\ n」 +「接收郵件?」+ mList;' –
@ElliottFrisch沒有工作現在空間已經消失,但名稱,電話號碼和地址現在不顯示 –