Hey all i am having some problems with trying to figure out what all i need in order to do the following:
-3 private instance variables: 1 for Name (use the Name class), 1 for Address (Use the Address class), a string for SSN.
- A constructor which initializes the SSN, Name and Address
- getName function (returns Name of Employee)
- getAddress function (returns Address of Employee)
- getSSN fuction (returns SSN as string)
- Print Name, Address and SSN.
This is my code so far:
Employee.java
class Employee
{
private Name Nam;
private Address Addr;
private String strSSN;
public Employee(String theName, String theAddress, String SSN)
{
Nam = new Name(theName);
Addr = new Address(theAddress);
strSSN = SSN;
}
public String getName()
{
Nam = new Name(FName, MName, LName);
return Nam;
}
public String strAddress()
{
Addr = new Address(Street, City, State, Zip);
return Addr;
}
public String getSSN()
{
return strSSN;
}
public String toString()
{
return "Name: " + getName() + "\n" +
"Address: " + getAddress() + "\n" +
"SSN: " + strSSN + "\n";
}
}
Name.java
class Name
{
private String strFirst;
private String strMiddle;
private String strLast;
public Name(String FName, String MName, String LName)
{
strFirst = FName;
strMiddle = MName;
strLast = LName;
}
public String getFName()
{
return strFirst;
}
public String getMName()
{
return strMiddle;
}
public String getLName()
{
return strLast;
}
public String toString()
{
return "First Name: " + strFirst + "\n" +
"Middle Name: " + strMiddle + "\n" +
"Last Name: " + strLast + "\n";
}
}
Address.java
class Address
{
private String strStreet;
private String strCity;
private String strState;
private String strZip;
public Address(String Street, String City, String State, String Zip)
{
strStreet = Street;
strCity = City;
strState = State;
strZip = strZip;
}
public String getStreet()
{
return strStreet;
}
public String getCity()
{
return strCity;
}
public String getState()
{
return strState;
}
public String getZip()
{
return strZip;
}
public String toString()
{
return "Street: " + strStreet + "\n" +
"City: " + strCity + "\n" +
"State: " + strState + "\n" +
"Zip: " + strZip + "\n";
}
}
Both the Name and Address .java compiles just fine without errors.
How can i get the Employee.java to get the Name from the Name.java and the Address from the Address.java?? Am i doing it correctly with the "Nam = new Name(theName);"?
Thanks for your time!
David