Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

THIS PROGRAM WAS WRITTEN BY ONE OF THE SPECIALISTS BUT DOES NOT PRODUCE ANY OUTPUT WHEN YOU EXECUTE IT, CAN YOU WORK ON THE APPLICATION

THIS PROGRAM WAS WRITTEN BY ONE OF THE SPECIALISTS BUT DOES NOT PRODUCE ANY OUTPUT WHEN YOU EXECUTE IT, CAN YOU WORK ON THE APPLICATION AND MAKE IT WORK OR I need the output

(

1) //Appication.java////////////////

public class Appication {

public static void main(String[] args) {

Employee emp[]=new Employee[5];

Student std[]=new Student[20];

}

}

//end of Appication.java////////////////

ABSTRACTION, INHERITANCE AND COMPOSITION

Create an abstract base class Person. Person object will have the following member fields.

Name

Id

Address

Since the address a more complex entity it will be defined by Address class. Here are the field necessary to define an address.

Street

City

Zip code

Country (country will have a default value USA)

The usage of the Address class in the Person class is form of composition.

Extending the abstract Person class we will create two concrete class (non-abstract).

Employee class

Student class

Employee class will have additional fields: salary and social security number. For security reason when we perform get on SSN it will only return the last 4 digits in the following format ##-##-1234.

Student class will have additional fields: gpa and number of credits completed

To test and the above created class we will create an application class (only class with public void main(String [] args) method). The application class should create 5 instances of Employee and 20 instances of Student class. Use data structure such as List<> or [] (array) to store the instances. For

example, List employees = new ArrayLists<>();

Print (System.out.println) the name and salary of all the Employees. Similarly print the name, address, and gpa of all created students.

HINT: may what to override the to string of Address to make it easy to print. Guidelines

All class should allow initialization of objects via constructor parameter.

All member fields should have the necessary accessor and mutator (i.e. getters and setters)

====================================================================================

Create class in following order:

Address

Person

Employee

Student

Application

Explanation

Please refer to solution in this step.

Answer

//Address.java//////////////////

public class Address {

private String Street;

private String City;

private String ZipCode;

private String Country;

public Address(String street, String city, String zipCode, String country) {

super();

Street = street;

City = city;

ZipCode = zipCode;

Country = country;

}

public String getStreet() {

return Street;

}

public void setStreet(String street) {

Street = street;

}

public String getCity() {

return City;

}

public void setCity(String city) {

City = city;

}

public String getZipCode() {

return ZipCode;

}

public void setZipCode(String zipCode) {

ZipCode = zipCode;

}

public String getCountry() {

return Country;

}

public void setCountry(String country) {

Country = country;

}

public String toString() {

return "Street: "+Street+" "+"City: "+City+" "+"Country: "+Country+" "+"Zip Code: "+ZipCode;

}

}

//end of Address.java//////////

//Person.java/////////////////////

public abstract class Person {

private String Name;

private String Id;

private Address address;

public Person(String name, String id, Address address) {

super();

Name = name;

Id = id;

this.address = address;

}

public String getName() {

return Name;

}

public void setName(String name) {

Name = name;

}

public String getId() {

return Id;

}

public void setId(String id) {

Id = id;

}

public Address getAddress() {

return address;

}

public void setAddress(Address address) {

this.address = address;

}

}

//end of Person.java

//Employee.java/////////////////////

public class Employee extends Person {

private double Salary;

private String SSN;

public Employee(String name, String id, Address address,double salary,String ssn) {

super(name, id, address);

Salary=salary;

SSN=ssn;

}

public double getSalary() {

return Salary;

}

public void setSalary(double salary) {

Salary = salary;

}

public String getSSN() {

String arr[]=SSN.split("-");

return "##-##-"+arr[2];

}

public void setSSN(String sSN) {

SSN = sSN;

}

}

//end of Employee.java/////////////

//Student.java//////////////////

public class Student extends Person {

private double GPA;

private int NumberOfCredits;

public Student(String name, String id, Address address,double gpa,int credit) {

super(name, id, address);

GPA=gpa;

NumberOfCredits=credit;

}

public double getGPA() {

return GPA;

}

public void setGPA(double gPA) {

GPA = gPA;

}

public int getNumberOfCredits() {

return NumberOfCredits;

}

public void setNumberOfCredits(int numberOfCredits) {

NumberOfCredits = numberOfCredits;

}

}

//end of Student.java//////////////////

//Appication.java////////////////

public class Appication {

public static void main(String[] args) {

Employee emp[]=new Employee[5];

Student std[]=new Student[20];

}

}

//end of Appication.java////////////////

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Factory Active Database For Enterprise Computing

Authors: Schur, Stephen

1st Edition

0471558443, 9780471558446

More Books

Students also viewed these Databases questions

Question

What is an interface? What keyword is used to define one?

Answered: 1 week ago

Question

Calculate the lifetime value (LTV) of a loyal customer.

Answered: 1 week ago

Question

Use service tiering to manage the customer base and build loyalty.

Answered: 1 week ago