请帮助我,如何使代码打印出地址的完整详细信息作为输出而不是空输出
Pls help me, how can I make the code printout the full details of the address as an output instead of empty output
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package addressname;
/**
*
* @author MY PC
*/
public class AddressName {
public static void main(String[] arg){
}
private String name;
private String streetAddress;
private String city;
private String state;
private String zipCode;
/**
* Create an address with all empty fields.
*
*/
public AddressName ()
{
name = "";
streetAddress = "";
city = "";
state = "";
zipCode = "";
}
/**
* Create an address.
*/
public AddressName (String nm, String streetAddr, String city,
String state, String zip)
{
name = nm;
streetAddress = streetAddr;
this.city = city;
this.state = state;
zipCode = zip;
}
/**
* @return the theName
*/
public String getName() {
return name;
}
/**
* @param theName the theName to set
*/
public void setName(String theName) {
this.name = theName;
}
/**
* @return the streetAddress
*/
public String getStreetAddress() {
return streetAddress;
}
/**
* @param streetAddress the streetAddress to set
*/
public void setStreetAddress(String streetAddress) {
this.streetAddress = streetAddress;
}
/**
* @return the city
*/
public String getCity() {
return city;
}
/**
* @param city the city to set
*/
public void setCity(String city) {
this.city = city;
}
/**
* @return the state
*/
public String getState() {
return state;
}
/**
* @param state the state to set
*/
public void setState(String state) {
this.state = state;
}
/**
* @return the zipCode
*/
public String getZipCode() {
return zipCode;
}
/**
* @param zipCode the zipCode to set
*/
public void setZipCode(String zipCode) {
this.zipCode = zipCode;
}
/**
* True if the names and addresses are equal
*/
public boolean equals (Object right)
{
AddressName r = (AddressName)right;
return name.equals(r.name)
&& streetAddress.equals(r.streetAddress)
&& city.equals(r.city)
&& state.equals(r.state)
&& zipCode.equals(r.zipCode);
}
public int hashCode ()
{
return name.hashCode() + 3 * streetAddress.hashCode()
+ 5 * city.hashCode()
+ 7 * state.hashCode()
+ 11 * zipCode.hashCode();
}
public String toString()
{
return name + ": " + streetAddress + ": "
+ city + ", " + state + " " + zipCode;
}
public Object clone()
{
return new AddressName(name, streetAddress, city,
state, zipCode);
}
}
输出
完成成功
像这样修改主要方法的主体:
public static void main(String[] arg) {
Address address = new Address("The Game", "Seventh street", "Generic Town", "State", "1234");
System.out.println(address.toString());
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package addressname;
/**
*
* @author MY PC
*/
public class AddressName {
public static void main(String[] arg){
}
private String name;
private String streetAddress;
private String city;
private String state;
private String zipCode;
/**
* Create an address with all empty fields.
*
*/
public AddressName ()
{
name = "";
streetAddress = "";
city = "";
state = "";
zipCode = "";
}
/**
* Create an address.
*/
public AddressName (String nm, String streetAddr, String city,
String state, String zip)
{
name = nm;
streetAddress = streetAddr;
this.city = city;
this.state = state;
zipCode = zip;
}
/**
* @return the theName
*/
public String getName() {
return name;
}
/**
* @param theName the theName to set
*/
public void setName(String theName) {
this.name = theName;
}
/**
* @return the streetAddress
*/
public String getStreetAddress() {
return streetAddress;
}
/**
* @param streetAddress the streetAddress to set
*/
public void setStreetAddress(String streetAddress) {
this.streetAddress = streetAddress;
}
/**
* @return the city
*/
public String getCity() {
return city;
}
/**
* @param city the city to set
*/
public void setCity(String city) {
this.city = city;
}
/**
* @return the state
*/
public String getState() {
return state;
}
/**
* @param state the state to set
*/
public void setState(String state) {
this.state = state;
}
/**
* @return the zipCode
*/
public String getZipCode() {
return zipCode;
}
/**
* @param zipCode the zipCode to set
*/
public void setZipCode(String zipCode) {
this.zipCode = zipCode;
}
/**
* True if the names and addresses are equal
*/
public boolean equals (Object right)
{
AddressName r = (AddressName)right;
return name.equals(r.name)
&& streetAddress.equals(r.streetAddress)
&& city.equals(r.city)
&& state.equals(r.state)
&& zipCode.equals(r.zipCode);
}
public int hashCode ()
{
return name.hashCode() + 3 * streetAddress.hashCode()
+ 5 * city.hashCode()
+ 7 * state.hashCode()
+ 11 * zipCode.hashCode();
}
public String toString()
{
return name + ": " + streetAddress + ": "
+ city + ", " + state + " " + zipCode;
}
public Object clone()
{
return new AddressName(name, streetAddress, city,
state, zipCode);
}
}
输出 完成成功
像这样修改主要方法的主体:
public static void main(String[] arg) {
Address address = new Address("The Game", "Seventh street", "Generic Town", "State", "1234");
System.out.println(address.toString());
}