Reputation: 21
I am new in this forum. I am stuck on a part of my code. One method of my code give me this information :
getFullAddress() should return the address as a formatted String, one item per line: e.g.:
23 High Street
Newcastle
NE1 1NE
The thing is that i am stuck, i tried everything but nothing works.
Here is my code :
/**
* 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;
}
}
Thank you in advance for your help
Upvotes: 1
Views: 228
Reputation: 5747
You aren't returning anything in getFullAddress()
. Change getFullAddress
method to this:
public String getFullAddress() {
final String separator = System.getProperty("line.separator"); //final indicates the variable will not change
return getStreet() + separator + getTown() + separator + getPostcode();
}
I suggest you use System.getProperty("line.separator");
over \n
, because \n
will not correctly work on every operating system. Getting the line separator using System.getProperty()
returns the correct newline character for every OS.
Upvotes: 1
Reputation: 311863
Just concat the string with newline characters between them:
public String getFullAddress() {
return String.format("%s%n%s%n", getStreet(), getTown(), getPostcode());
}
Upvotes: 0