我是這個論壇的新手。我卡在我的代碼的一部分。我的代碼 一種方法給我這樣的信息:返回多個字符串格式
getFullAddress()應返回的地址作爲格式的字符串,每行一個項目: 如:
23 High Street
Newcastle
NE1 1NE
的事情是,我堅持,我試過一切,但沒有任何工作。
這裏是我的代碼:
/**
* Write a description of class Address here.
*
* @author Bento Xavier
* @version 10/17/2015
*/
public class Address
{
private String postcode;
private String street;
private String town;
public Address(String street, String town, String postcode)
{
this.street = street;
this.town = town;
this.postcode = postcode;
}
public String getFullAddress()
{
String fullAddress = "";
fullAddress = ;
}
public String getPostcode()
{
return postcode;
}
public String getStreet()
{
return street;
}
public String getTown()
{
return town;
}
public void printAddress()
{
System.out.println(street + " \n" + town + " \n" + postcode);
}
public void setFullAddress(String street, String town, String postcode)
{
this.street = street;
this.town = town;
this.postcode = postcode;
}
public void setPostcode(String postcode)
{
this.postcode = postcode;
}
public void setStreet(String street)
{
this.street = street;
}
public void setTown(String town)
{
this.town = town;
}
}
預先感謝您的幫助
格式肯定似乎會更加清晰,或者至少* *行分隔符設置爲一箇中間值。 –
我不想太複雜的代碼,因爲這是一個初學者的問題。但是你保存行分隔符是正確的,不需要三次。編輯。 – nbokmans