Hello, I need help on the homework:
- Write an interface called MyOwnInterface, which has the following
method
- AddressInterface getAddress();
- The AddressInterface is a Java interface that has the following
methods.
- int getStreetNumber();
- void setStreetNumber(int streetNumber);
- String getStreetName();
- void setStreetName(String streetName);
- String getCountry();
- void setCountry(String country);
- Write AddressImpl class that implements AddressInterface
- Make the Person class to implement MyOwnInterface.
- Initialize a Person object with proper data and display it.
This is my code:
package PersonMultipleInterfaces;
public interface *MyOwnInterface *
{
AddresInterface getAddres();
}
-------------------------------------------------------------------------------------------------------------------
package PersonMultipleInterfaces;
public interface* AddresInterface*
{
int getStreetNumber();
void setStreetNumber(int streetNumber);
String getStreetName();
void setStreetName(String streetName);
String getCountry();
void setCountry(String country);
}
-------------------------------------------------------------------------------------------------------------------
package PersonMultipleInterfaces;
public class *AddressImpl* implements AddresInterface
{
int streetNumber;
String streetName;
String country;
public AddressImpl(int streetNumber, String streetName, String country)
{
this.streetNumber = streetNumber;
this.streetName = streetName;
this.country = country;
}
public int getStreetNumber()
{
return streetNumber;
}
public void setStreetNumber(int streetNumber)
{
this.streetNumber = streetNumber;
}
public String getStreetName()
{
return streetName;
}
public void setStreetName(String streetName)
{
this.streetName = streetName;
}
public String getCountry()
{
return country;
}
public void setCountry(String country)
{
this.country = country;
}
}
-------------------------------------------------------------------------------------------------------------------------------------
package PersonMultipleInterfaces;
public class *GetPersonMultipleInterfaces*
{
public static void *main*(String[] args)
{
Person Tomek = new Person();
Tomek.getAddres().setCountry("Poland");
Tomek.getAddres().setStreetName("Kasztelanska");
Tomek.getAddres().setStreetNumber(100);
System.out.println("The county name is: " +
Tomek.getAddres().getCountry());
System.out.println("The addres id: " +
Tomek.getAddres().getStreetName());
System.out.println("The street number is: " +
Tomek.getAddres().getStreetNumber());
}
}
---------------------------------------------------------------------------------------------------------------------------------------
package PersonMultipleInterfaces;
public class *Person* implements MyOwnInterface
{
int streetNumber;
String streetName;
String country;
AddresInterface addres;
public Person()
{}
public AddresInterface getAddres()
{
* ???????????????????????????* <----------- hiere is the problem
}
}
I'm implementing the MyOwnInterface to the Person class but I don't know how
to get to the methods implemented in the AddressInterface interface. Please
someone explain it to me, i'll be very gratefull.
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---