Create a java program to create a school system that keeps track of employees, s
ID: 3588619 • Letter: C
Question
Create a java program to create a school system that keeps track of employees, students and visitors, the address for all employees and students must be created, the system must calculate and display the gross weekly amount earned. Then create a abstract super class called Individuals so that employees, students and visitors can derive the common attributes.
Students and visitors cannot be inherited by any other entity.
An interface must be use to declare the following methods printDetails() and printDetails (Individuals per). Also in the interface the contacts details for the school must be in it
(name, telephone number and email address)
Use another interface to declare a method called calGrossSalary(). this should be implemented by employees entity.
Not all students pursue the same number of subjects so a regular array to implement this functionality.
Lastly create a driver to test the logistics of the program
Explanation / Answer
interface Salary //Salary interface to be implemented by Employee class
{
public void calGrossSalary(int hoursWorked,double ratePerHour);
}
interface Details //Interface to be implemented by all concrete classes
{
//static variables
public static String schoolName = "ABC School";
public static String telephone = "0474756-656";
public static String email = "abcschool@mail.com";
public void printDetails();
}
abstract class Individual //abstract base class
{
private String address;
private String name;
public Individual(String name,String address) //argument constructor
{
this.name = name;
this.address = address;
}
//get methods
public String getName()
{
return name;
}
public String getAddress()
{
return address;
}
}
class Employee extends Individual implements Salary,Details
{
public Employee(String name,String address)
{
super(name,address); //call to base class constructor
}
public void calGrossSalary(int hoursWorked,double ratePerHour) //implement method of Salary interface
{
System.out.println(" Gross Salary : $"+ (hoursWorked*ratePerHour));
}
public void printDetails() //implement method of interface Details
{
System.out.println(" School Name : "+schoolName + " telephone : "+telephone +" email : "+email);
System.out.println(" Employee name : "+getName() +" Address : "+getAddress());
}
}
final class Student extends Individual implements Details
{
public Student(String name,String address)
{
super(name,address);
}
public void printDetails()
{
System.out.println(" School Name : "+schoolName + " telephone : "+telephone +" email : "+email);
System.out.println(" Student name : "+getName() +" Address : "+getAddress());
}
}
final class Visitor extends Individual implements Details
{
public Visitor(String name,String address)
{
super(name,address);
}
public void printDetails()
{
System.out.println(" School Name : "+schoolName + " telephone : "+telephone +" email : "+email);
System.out.println(" Visitor name : "+getName() +" Address : "+getAddress());
}
}
class Test
{
public static void main (String[] args)
{
Student s = new Student("Jim Carry","345,down Street ,NJ");
s.printDetails();
Employee e = new Employee("John Mathew","4656,Hillside NY");
e.calGrossSalary(39,7.8);
e.printDetails();
Visitor v = new Visitor("Jessica Rich","7756 BridgeTown,NY");
v.printDetails();
}
}
output:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.