I need help trying to get this code to compile, could someone please read this c
ID: 3836366 • Letter: I
Question
I need help trying to get this code to compile, could someone please read this code and compile it and then write it out here in cheggs by ,java class files please? it is programming challenge 1 form chp10(starting out with java from control structures through objects 6th edition tony gaddis), please read the picture files that i have posted here and try to rewrite them into java and compile them successfully try to use as much of the original code as you can, and rewrite the code that isn't legable, Thank you so much!!
import Java. text.Decima. Format Production Worker class public class Productionworker extends Employee Constants for the day and night shifts. SHIFT 1. 2. ublic final int NIGHT shift public static final employee s pay rate. The s The private shift Rate: name double Pay with a initializes an object pay This constructor hire name am n The s number date. num The employee s hire he a ram Copa.Explanation / Answer
Hi, Please find my implementation.
Please copy my code. It is working fine.
############ Exception Classes ########
class Invalidpayrate extends Exception {
public Invalidpayrate(String message){
super(message);
}
}
class InvalidEmployeeNumber extends Exception{
public InvalidEmployeeNumber(String message) {
super(message);
}
}
class InvalidShift extends Exception{
public InvalidShift(String message) {
super(message);
}
}
########### Employee.java ##########
public class Employee
{
private String Empname;
private String Empnumber;
private String Hiredate;
public Employee()
{
Empname="";
Empnumber="";
Hiredate="";
}
public Employee (String Empname, String Empnumber,String Hiredate) throws InvalidEmployeeNumber
{
setName(Empname);
setNumber(Empnumber);
setHiredate(Hiredate);
}
public void setName(String n) throws InvalidEmployeeNumber
{
if( n == null || n.trim().equals(""))
throw new InvalidEmployeeNumber("Employee name can not be null or empty");
Empname = n;
}
public void setNumber(String num)
{
Empnumber = num;
}
public void setHireDate(String h)
{
Hiredate = h;
}
public String getName()
{
return Empname;
}
public String getNumber()
{
return Empnumber;
}
public String getHireDate()
{
return Hiredate;
}
private void setHiredate(String Hiredate) {
this.Hiredate = Hiredate;
}
}
############## ProductionWorker.java ###########
public class ProductionWorker extends Employee
{
private int shift; // The employee's shift
private double hourpayrate; // The employee's pay rate
public ProductionWorker(String Empname, String Empnumber, String Hiredate,
int shift, double hourpayrate) throws InvalidEmployeeNumber, InvalidShift, Invalidpayrate
{
super(Empname, Empnumber, Hiredate);
setShift(shift);
setHourlyPayRate(hourpayrate);
}
public int getShift()
{
return shift;
}
public double getHourlyPayRate()
{
return hourpayrate;
}
public void setShift(int s) throws InvalidShift
{
if(s < 0){
throw new InvalidShift("Shift can not negative");
}
shift = s;
}
/**
The setPayRate method sets the employee's pay rate.
@param p The employee's pay rate.
*/
public void setHourlyPayRate(double r) throws Invalidpayrate
{
if(r < 0)
throw new Invalidpayrate("Pay rate can not be negative");
hourpayrate = r;
}
}
############### WorkerDemo.java ################
import java.util.*;
public class WorkerDemo
{
public static void main(String[] args)
{
String name,id,date;
int shift;
double pay;
// Creates Scanner object
Scanner keyboard = new Scanner(System.in);
// Gets the user's name.
System.out.println("Enter employee name: ");
name = keyboard.nextLine();
// Gets the user's employee number.
System.out.println("Enter employee ID: ");
id = keyboard.nextLine();
// Gets the user's hire date.
System.out.println("Enter employee date ");
date = keyboard.nextLine();
System.out.println("1-day Shift/n2-Night shift");
System.out.println("Enter employee shift: ");
shift = keyboard.nextInt();
System.out.println("Enter hourly pay");
pay = keyboard.nextDouble();
try{
// Creates an Production worker object.
ProductionWorker pw = new ProductionWorker(name,id,date,shift,pay);
System.out.println();
System.out.println("Employee Name: " + pw.getName());
System.out.println("Employee ID: " + pw.getNumber());
System.out.println("Hire Date: " + pw.getHireDate());
System.out.println("Shift: " + pw.getShift());
System.out.println("Hourly Rate: " + pw.getHourlyPayRate());
}catch(InvalidEmployeeNumber e){
System.out.println(e.getMessage());
}catch(Invalidpayrate e){
System.out.println(e.getMessage());
}catch(InvalidShift e){
System.out.println(e.getMessage());
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.