I have 2 classes, the first class (person) has a string format and in the second one (Staff) i want to add some more variables to that string, how do i add to the string format?
Class Person, this is the first class with the most information
public String toString() { String str = String.format("\nName: " + firstName + " " + lastName + "\nAddress: " + address1 + "\n " + address2 + "\n " + city + ", " + state + " " + zipCode + "\nPhone: " + phoneNumber + "\nEmail " + email); return str; }
Class Staff had more to it
public String String() { String str = String.format("\nID " + idNumber + "\nSalary " + salary + "\nDepartment " + department); return str; }
Heres the class that gives information and runs it
Person dave = new Person("Dave", "Hill", "Buttercup Ln", "", "Little Rock", "Arkansas", 67575, 555555, "dave@yahoo.com"); Staff hank = new Staff("Hank", "Green", "57 Baker St", "", "Denver", "Colorado", 72120, 634839288, "hank@email.com", 2727, 10000.0, "work"); System.out.println(john); System.out.println(hank);
When it runs it prints out:
Name: John Fox
Address: Lane
null
Little Rock, Arkansas 63638
Phone: 667733883
Email john@email.com
Name: Hank Green
Address: 57 Baker St
null
Denver, Colorado 72120
Phone: 634839288
Email hank@email.com
It prints exactly how i want but I want the second part to include the id number, salary, and department.