0% found this document useful (0 votes)
4 views

Assignment8_AbstractClass_Staff (1)

Uploaded by

Devil Lucifer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Assignment8_AbstractClass_Staff (1)

Uploaded by

Devil Lucifer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

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

com.tca ==> Demo.java


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

package com.tca;

import com.tca.entities.FullTimeStaff;
import com.tca.entities.PartTimeStaff;
import com.tca.entities.Staff;

import java.util.Scanner;

public class Demo {


public static void main(String ...args) throws Exception{
Scanner sc = new Scanner(System.in);

System.out.print("Enter The Number Of Objects You Want To Create : ");


int noOfObjects = sc.nextInt();
Staff[] arrayOfStaff = new Staff[noOfObjects];

System.out.print("Enter \"1\" For Creating Full Time Staff Object OR Enter \"2\" For Creating Part Time Staff Object
: ");
int choiceOfUser = sc.nextInt();

switch (choiceOfUser){
case 1 :
for(int index = 0 ; index<noOfObjects ; index++)
{
System.out.println("=======================================================");
System.out.print("Enter The Name Of The Full Time Staff : ");
String nameOfStaff = sc.next();
System.out.print("Enter The Address Of The Full Time Staff : ");
String addressOfStaff = sc.next();
System.out.print("Enter The Department Of Working : ");
String departmentOfStaff = sc.next();
System.out.print("Enter The Salary Of The Staff : ");
int salaryOfStaff = sc.nextInt();

arrayOfStaff[index] = new FullTimeStaff(nameOfStaff,addressOfStaff,departmentOfStaff,salaryOfStaff);


}
for(int index = 0 ; index<noOfObjects ; index++){
arrayOfStaff[index].display();
}
break;
case 2:
for(int index = 0 ; index<noOfObjects ; index++)
{
System.out.println("=======================================================");
System.out.print("Enter The Name Of The Full Time Staff : ");
String nameOfStaff = sc.next();
System.out.print("Enter The Address Of The Full Time Staff : ");
String addressOfStaff = sc.next();
System.out.print("Enter The Number Of Hours Of Working : ");
int noOfHoursOfWorking = sc.nextInt();
System.out.print("Enter The Rate Per Hour Of Staff : ");
int ratePerHourOfStaff = sc.nextInt();

arrayOfStaff[index] = new
PartTimeStaff(nameOfStaff,addressOfStaff,noOfHoursOfWorking,ratePerHourOfStaff);
}
for(int index = 0 ; index<noOfObjects ; index++){
arrayOfStaff[index].display();
}
break;
default:
System.out.println("Invalid Input!!");
}
}
}

=============================================
com.tca.entities ==> Staff (ABSTRACT CLASS)
=============================================

package com.tca.entities;

abstract public class Staff {


private String staffName;
private String staffAddress;

public Staff(){}

public Staff(String staffName, String staffAddress) {


this.staffName = staffName;
this.staffAddress = staffAddress;
}

public String getStaffName() {


return staffName;
}

public void setStaffName(String staffName) {


this.staffName = staffName;
}

public String getStaffAddress() {


return staffAddress;
}

public void setStaffAddress(String staffAddress) {


this.staffAddress = staffAddress;
}

abstract public void display();


}

===================================
com.tca.entities ==> FullTimeStaff
===================================

package com.tca.entities;

public class FullTimeStaff extends Staff{


private String departmentOfStaff;
private int salaryOfTheStaff;

public FullTimeStaff(){super();}

public FullTimeStaff(String staffName, String staffAddress, String departmentOfStaff, int salaryOfTheStaff) {


super(staffName, staffAddress);
this.departmentOfStaff = departmentOfStaff;
this.salaryOfTheStaff = salaryOfTheStaff;
}

public String getDepartmentOfStaff() {


return departmentOfStaff;
}

public void setDepartmentOfStaff(String departmentOfStaff) {


this.departmentOfStaff = departmentOfStaff;
}

public int getSalaryOfTheStaff() {


return salaryOfTheStaff;
}

public void setSalaryOfTheStaff(int salaryOfTheStaff) {


this.salaryOfTheStaff = salaryOfTheStaff;
}

public void display()


{
System.out.println("=======================================================");
System.out.println("The Name Of The Staff : " + getStaffName());
System.out.println("The Address Of The Staff : " + getStaffAddress());
System.out.println("The Department Of The Staff Is : " + departmentOfStaff);
System.out.println("The Salary Of The Staff Is : " + salaryOfTheStaff);
}
}

===================================
com.tca.entities ==> PartTimeStaff
===================================

package com.tca.entities;

public class PartTimeStaff extends Staff{


private int noOfHoursOfWorkingOfStaff;
private int ratePerHourWagesOfStaff;

public PartTimeStaff(){super();}

public PartTimeStaff(String staffName, String staffAddress, int noOfHoursOfWorkingOfStaff, int


ratePerHourWagesOfStaff) {
super(staffName, staffAddress);
this.noOfHoursOfWorkingOfStaff = noOfHoursOfWorkingOfStaff;
this.ratePerHourWagesOfStaff = ratePerHourWagesOfStaff;
}

public int getRatePerHourWagesOfStaff() {


return ratePerHourWagesOfStaff;
}

public void setRatePerHourWagesOfStaff(int ratePerHourWagesOfStaff) {


this.ratePerHourWagesOfStaff = ratePerHourWagesOfStaff;
}

public int getNoOfHoursOfWorkingOfStaff() {


return noOfHoursOfWorkingOfStaff;
}
public void setNoOfHoursOfWorkingOfStaff(int noOfHoursOfWorkingOfStaff) {
this.noOfHoursOfWorkingOfStaff = noOfHoursOfWorkingOfStaff;
}

public void display()


{
System.out.println("=======================================================");
System.out.println("The Name Of The Staff : " + getStaffName());
System.out.println("The Address Of The Staff : " + getStaffAddress());
System.out.println("The Number Of Hours Of Working : " + noOfHoursOfWorkingOfStaff);
System.out.println("The Rate Per Hour Is : " + ratePerHourWagesOfStaff);
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy