Question: Language: JAVA change the country to default USA, code that I have is listed below. create an application class with public void main string method.
Language: JAVA
change the country to default USA, code that I have is listed below. create an application class with public void main string method. it should create 5 instances. of employee and 5 of student class. use data structure such as list<>or[] to store the instances. Print (system.out.println) the name and salary of all employees. similar print the name, address and gpa of all created students
Person class
public abstract class Person {
protected String name;
protected int id;
protected Address address;
public Person(String name, int id, Address address) {
this.name = name;
this.id = id;
this.address = address;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
@Override
public String toString() {
return "name=" + name + ", id=" + id + ", address=" + address ;
}
}
Employee Class
public class Employee extends Person {
private String ssn;
private double salary;
public Employee(String name, int id, Address address) {
super(name, id, address);
}
public String getSsn() {
String retVal=null;
if (ssn.length() > 4)
{
retVal = ssn.substring(ssn.length() - 4);
}
else
{
retVal = ssn;
}
return "###-##-" + retVal;
}
public void setSsn(String ssn) {
this.ssn = ssn;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
@Override
public String toString() {
return super.toString() + "ssn=" + ssn + ", salary=" + salary ;
}
}
Student class
public class Student extends Person {
private double gpa;
public Student(String name, int id, Address address) {
super(name, id, address);
}
public double getGpa() {
return gpa;
}
public void setGpa(double gpa) {
this.gpa = gpa;
}
@Override
public String toString() {
return super.toString() + "gpa=" + gpa + "]";
}
}
Address class
public class Address {
protected String street;
protected String city;
protected int zipCode;
protected String country;
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public int getZipCode() {
return zipCode;
}
public void setZipCode(int zipCode) {
this.zipCode = zipCode;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
@Override
public String toString() {
return "street=" + street + ", city=" + city + ", zipCode=" + zipCode + ", country=" + country ;
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
