Question: Java question public class Person { private String name; private int birthYear; private boolean veteran; public Person() { name = ; birthYear = 0; veteran
Java question
public class Person { private String name;
private int birthYear; private boolean veteran;
public Person() {
name = ""; birthYear = 0; veteran = false;
}
public Person(String name, int year, boolean vet) {
this.name = name; birthYear = year; veteran = vet;
}
public void setName(String newName) {
name = newName;
public void setBirthYear(int newYear)
{ }
}
birthYear = newYear;
public void setVet(boolean newVet)
{ }
veteran = newVet; public String getName()
{ }
return name; public int getYear()
{ }
return birthYear; public boolean getVet()
{ }
return veteran;
public String toString() {
String temp = "Name " + name +
" Birth year " + birthYear +
return temp;
" veteran status " + veteran;
}
public class Student extends Person{ private String major;
public Student() {
major = "";
public Student(String name, int year, boolean vet, String major)
super(name, year, vet); this.major = major;
}
public void setMajor(String newMajor) {
major = newMajor; public String getMajor() {
return major; public String toString()
String temp = super.toString() + " major " + major; return temp;
}
}
} {
}
} { }
public class TestInheritance3 {
public static void main(String[] args) { Student s1 = new Student(); s1.setName("John Smith"); s1.setBirthYear(1990); s1.setMajor("Cps"); System.out.println(s1.toString());
Student s2 = new Student("Mary Thomas", 1999, false, "Biology"); System.out.println(s2.toString());
Instructor it= new Instructor("Mary Thomas", 1999,
false, 90000); System.out.println(it.toString());
} }
'll AT&T Wi-Fi 23:53 9b-Chapter 1 1 part 2.pdf 5 of 57 Inheritance lab (15 minutes) .A Staff is a Person and inherits all the instance variables of Person. A Staff has one more instance variables, status which can have the values: "exempt and "non-exempt" Write the Staff class. - Include 2 constructors (no-args and constructor which values all instance variables) -Include the new instance variables, getters, setters and a toString method which prints all the information about a Staff member. Change the Testinheritance class to create two Staff objects (each using a different constructor). Value all the fields of each Staff Object. For the object created using the Default constructor, use the setters to value the fields. Print the information about both Staff objects. Partially filled Array of Objects Remember that when an Array is created, it is automatically filled with the default value for the type stored in the Array. An array of ints or doubles is filled with zero WI An arrav of boolean is filled with false a Open With Print
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
