HospitalEmployee Inheritance help please.
import java.text.NumberFormat;
public class HospitalEmployee
{
private String empName;
private int empNumber;
private double hoursWorked;
private double payRate;
private static int hospitalEmployeeCount = 0;
//-----------------------------------------------------------------
// Sets up this hospital employee with default information.
//-----------------------------------------------------------------
public HospitalEmployee()
{
empName = "Chris Smith";
empNumber = 9999;
hoursWorked = 0;
payRate =0;
hospitalEmployeeCount++;
}
//overloaded constructor.
public HospitalEmployee(String eName, int eNumber, double hours, double pay)
{
empName = eName;
empNumber = eNumber;
hoursWorked = hours;
payRate = pay;
hospitalEmployeeCount++;
}
//-----------------------------------------------------------------
// Sets the name for this employee.
//-----------------------------------------------------------------
public void setEmpName (String eName)
{
empName = eName;
}
//-----------------------------------------------------------------
// Sets the employee number for this employee.
//-----------------------------------------------------------------
public void setEmpNumber (int eNumber)
{
empNumber = eNumber;
}
//-----------------------------------------------------------------
// Sets the hours worked for this employee.
//-----------------------------------------------------------------
public void setHoursWorked (double hours)
{
hoursWorked = hours;
}
//-----------------------------------------------------------------
// Sets the pay rate for this employee.
//-----------------------------------------------------------------
public void setPayRate (double rate)
{
payRate = rate;
}
//-----------------------------------------------------------------
// Returns this employee's name.
//-----------------------------------------------------------------
public String getEmpName()
{
return empName;
}
//-----------------------------------------------------------------
// Returns this employee's number.
//-----------------------------------------------------------------
public int getEmpNumber()
{
return empNumber;
}
//-----------------------------------------------------------------
// Returns hours worked.
//-----------------------------------------------------------------
public double getHoursWorked()
{
return hoursWorked;
}
//-----------------------------------------------------------------
// Returns employee payRate
//-----------------------------------------------------------------
public double getpayRate()
{
return payRate;
}
//-----------------------------------------------------------------
// Returns this employee's gross pay.
//-----------------------------------------------------------------
public double calculateGrossPay()
{
return (hoursWorked * payRate);
}
//-----------------------------------------------------------------
// This adds or subtracts hours from the hoursWorked instance var.
//-----------------------------------------------------------------
public void changeHoursWorked(double hours)
{
hoursWorked = hoursWorked + hours;
}
//-----------------------------------------------------------------
// Changes the instance variable payRate by the amount
//-----------------------------------------------------------------
public void changePayRate(double amount)
{
payRate = payRate + amount;
}
//---------------------------------------------------------------
// Calculates a bonus based on a rating
// Returns 500 for excellent employees
// Returns 300 for satisfactory employees
// Returns 0 for all other ratings
//
// good example to overload.
//---------------------------------------------------------------
public double calculateBonus(String rating)
{
double bonus = 0.0;
rating = rating.toLowerCase();
if (rating.equals("excellent") )
{
bonus = 500;
} else if (rating.equals("satisfactory") )
{
bonus = 300;
} //everyone else is 0
return bonus;
}
//overloaded calculateBonus
//bonus is calculated as a percent of gross pay
//percent = 10% passed in a 10
public double calculateBonus(double percent)
{
double bonus = calculateGrossPay() * percent / 100.0;
return bonus;
}
//-----------------------------------------------------------------
// Returns a description of this employee as a string.
//-----------------------------------------------------------------
public String toString()
{
NumberFormat fmt = NumberFormat.getCurrencyInstance();
return ("empName: " + empName + "\t empNumber: " + empNumber + "\thoursWorked: " +
hoursWorked + "\tpayRate: " + fmt.format(payRate) );
}
//static method that returns number of HospitalEmployee objects created
public static int getHospitalEmployeeCount( )
{
return hospitalEmployeeCount;
}
}
import java.util.Random;
public class Doctor extends HospitalEmployee{
private String special;
public Doctor(String eName, int eNumber, double hours,
double pay, String Special){
super(eName,eNumber,hours,pay);
this.special = Special;
}
public String getSpecial() {
return special;
}
public void setSpecial(String special) {
this.special = special;
}
public double calculateBonus(String shift){
double bonus = 0.0;
shift = shift.toLowerCase();
if (shift.equals("night shift") )
{
bonus = super.calculateBonus(10);
} else if (shift.equals("evening shift") )
{
bonus = super.calculateBonus(5);
}
return bonus;
}
public String createLogin(){
Random r = new Random();
int n = r.nextInt(9);
String s =
this.getEmpName().substring(0, 1)+
Integer.toString(n)+Integer.toString(this.getEmpNumber());
return s;
}
public String toString(){
return super.toString();
}
}
public class Hospital {
public static void main(String[] args) {
// TODO Auto-generated method
stub
HospitalEmployee luke = new
HospitalEmployee("Luke Skywalker", 5432, 40, 20.50);
System.out.println("Status of luke:
"+luke.toString());
System.out.println("Bonus of Luke:
$"+luke.calculateBonus("satisfactory"));
Doctor darth = new Doctor("Darth
Vader", 9876, 17, 150.00, "Plastic Surgery");
System.out.println("Status of
Darth: "+darth.toString());
System.out.println("Bonus of Darth:
$"+darth.calculateBonus("evening shift"));
System.out.println("Login of darth:
"+darth.createLogin());
System.out.println("Number of
employees: "+HospitalEmployee.getHospitalEmployeeCount());
}
}
HospitalEmployee Inheritance help please. import java.text.NumberFormat; public class HospitalEmployee { private String empName; private...
departmentstore: package departmentstorepkg; import java.util.ArrayList; public class DepartmentStore { private static final int DEFAULT_SIZE = 10; private StaffMember [] myEmployees; private int myNumberEmployees; private String myFileName; private StaffMember[] employee; public DepartmentStore (String filename){ myFileName = filename; myEmployees = employee; } public String toString(){ return this.getClass().toString() + ": " + myFileName; } public void addEmployee(Employee emp){ } /** * prints out all the employees in the array list held in this class */ public void print(){ for(int i =...
Previous class code: 1) Employee.java ------------------------------------------------------------------------------- /** * */ package main.webapp; /** * @author sargade * */ public class Employee { private int empId; private String empName; private Vehicle vehicle; public Double calculatePay() { return null; } /** * @return the empId */ public int getEmpId() { return empId; } /** * @param empId * the empId to set */ public void setEmpId(int empId) { this.empId = empId; } /** * @return the empName */ public String getEmpName() { return...
public class Person t publie alass EmployeeRecord ( private String firstName private String last Nanei private Person employee private int employeeID publie EnmployeeRecord (Person e, int ID) publie Person (String EName, String 1Name) thia.employee e employeeID ID setName (EName, 1Name) : publie void setName (String Name, String 1Name) publie void setInfo (Person e, int ID) this.firstName- fName this.lastName 1Name this.employee e employeeID ID: publio String getFiritName) return firstName public Person getEmployee) t return employeei public String getLastName public int getIDO...
By editing the code below to include composition, enums, toString; must do the following: Prompt the user to enter their birth date and hire date (see Fig. 8.7, 8.8 and 8.9 examples) in addition to the previous user input Create a new class that validates the dates that are input (can copy date class from the book) Incorporate composition into your class with these dates Use enums to identify the employee status as fulltime (40 or more hours worked for...
Given attached you will find a file from Programming Challenge 5 of chapter 6 with required you to write a Payroll class that calculates an employee’s payroll. Write exception classes for the following error conditions: An empty string is given for the employee’s name. An invalid value is given to the employee’s ID number. If you implemented this field as a string, then an empty string could be invalid. If you implemented this field as a numeric variable, then a...
C++ Lab 9B Inheritance Class Production Worker Create a project C2010Lab9b; add a source file Lab9b.cpp to the project. Copy and paste the code is listed below: Next, write a class named ProductionWorker that is derived from the Employee class. The ProductionWorker class should have member variables to hold the following information: Shift (an integer) Hourly pay rate (a double) // Specification file for the ProductionWorker Class #ifndef PRODUCTION_WORKER_H #define PRODUCTION_WORKER_H #include "Employee.h" #include <string> using namespace std; class ProductionWorker...
Please answer the following question with Java Modify the Employee and ProductionWorker classes provided below so they throw exceptions when the following errors occur. - The Employee class should throw an exception named InvalidEmployeeNumber when it receives an employee number that is less than 0 or greater than 9999. - The ProductionWorker class should throw an exception named InvalidShift when it receives an invalid shift. - The ProductionWorker class should thrown anexception named InvalidPayRate when it receives a negative number...
4. Command pattern //class Stock public class Stock { private String name; private double price; public Product(String name, double price) { this.name = name; this.price = price; } public void buy(int quantity){ System.out.println(“BOUGHT: “ + quantity + “x “ + this); } public void sell(int quantity){ System.out.println(“SOLD: “ + quantity + “x “ + this); } public String toString() { return “Product [name=” + name + “, price=” + price + “]”; } } a. Create two command classes that...
import java.util.Scanner; public class StudentClient { public static void main(String[] args) { Student s1 = new Student(); Student s2 = new Student("Smith", "123-45-6789", 3.2); Student s3 = new Student("Jones", "987-65-4321", 3.7); System.out.println("The name of student #1 is "); System.out.println("The social security number of student #1 is " + s1.toString()); System.out.println("Student #2 is " + s2); System.out.println("the name of student #3 is " + s3.getName()); System.out.println("The social security number...
I was wondering if I could get some help with a Java Program that I am currently working on for homework. When I run the program in Eclipse nothing shows up in the console can you help me out and tell me if I am missing something in my code or what's going on? My Code: public class Payroll { public static void main(String[] args) { } // TODO Auto-generated method stub private int[] employeeId = { 5658845, 4520125, 7895122,...