Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I just want a flowchart, purpuse, input and output. I appreciate it if you can h

ID: 3837092 • Letter: I

Question

I just want a flowchart, purpuse, input and output. I appreciate it if you can help

Challenge: The exception Project Problem

This assignment assumes you have completed Programming Challenge 1 of chapter 10 (Employee and ProductionWorker Classes). Modify the Employee and the productionWorker classes so they throw exceptions when the following errors occur:

• The Employee class should throw an exception named InvalidEmployeeNumber when it receives an invalid employee number.

• The ProductionWorker class should throw an exception named InvalidShift when it receives an invalid shift.

• The ProductionWorker class should throw an exception named InvalidPayRate when it receives a negative number for the hourly pay rate.

Write a test program the demonstrates how each of these exception conditions works.

Explanation / Answer

Employee.java

public class Employee
{
private String name;
private String date;
private String empnumber;



public Employee()
{
name = " ";
date = " ";
empnumber = " ";
}


public Employee(String name, String date, String empnumber) throws InvalidEmployeeNumber
{
this.name = name;
this.date = date;
setEmpnumber(empnumber);
  
}

public String getName()
{
return name;
}

public String getDate()
{
return date;
}

public String getNumber()
{
return empnumber;
}

   public void setEmpnumber(String empnumber) throws InvalidEmployeeNumber {
       if (empnumber.length() != 5)
       {
  
               throw new InvalidEmployeeNumber();
      
       }
   else if ((!Character.isDigit(empnumber.charAt(0))) ||
   (!Character.isDigit(empnumber.charAt(1))) ||
   (!Character.isDigit(empnumber.charAt(2))) ||
   (empnumber.charAt (3) != '-') ||
   (Character.toUpperCase(empnumber.charAt(4)) < 'A') ||
   (Character.toUpperCase(empnumber.charAt(4)) > 'M'))
   {
     
                       throw new InvalidEmployeeNumber();
                  
   }
   else
   {
       this.empnumber = empnumber;
   }
   }


   public String toString()
{
return "Name: " + name + " Employee Number: " + empnumber + " Hire Date: " + date;
}
}

_________________

Productionworker.java

public class Productionworker extends Employee {
   public static final int DAYSHIFT = 1;
   public static final int NIGHTSHIFT = 2;
     
   private int shift;
   private double payrate;
     
     
   public Productionworker()
   {
   super();
   shift = DAYSHIFT;
   payrate = 0.0;
   }
     
   public Productionworker(String n, String d, String e, int shift, double payrate) throws Exception
   {
   super(n,d,e);
   setShift(shift);
   setPayrate(payrate);

   }
     
   private void setPayrate(double payrate) throws InvalidPayRate {
           if(payrate<0)
               throw new InvalidPayRate();
           else
               this.payrate=payrate;
          
       }

       private void setShift(int shift) throws InvalidShift {
           if(shift ==1 || shift ==2)
               this.payrate=payrate;
           else
               throw new InvalidShift();

          
       }

       public int getShift()
   {
   return shift;
   }
     
   public double payrate()
   {
   return payrate;
   }
     
   public String toString()
   {
   String str = super.toString();
     
   if(shift == DAYSHIFT)
   {
   str += "day shift";
   }
     
   else if(shift == NIGHTSHIFT)
   {
   str += "night shift";
   }
     
   return str += " hourly payrate:" + payrate;
     
   }

}

___________________

InvalidEmployeeNumber.java

public class InvalidEmployeeNumber extends Exception {
   public InvalidEmployeeNumber()
   {
       System.out.println(":: Invalid Employee Number ::");
   }

}

____________________

InvalidPayRate.java

public class InvalidPayRate extends Exception {
   public InvalidPayRate()
   {
       System.out.println(":: Invalid pay rate ::");
   }

}

___________________

InvalidShift.java

public class InvalidShift extends Exception {
public InvalidShift()
{
   System.out.println(":: Invalid Shift ::");
}
}

____________________

package org.students;

import java.util.Scanner;

public class Test {


   public static void main(String[] args) {
       String name;
       String date;
       String empnumber;

       Productionworker pw=null;
       //Scanner object is used to get the inputs entered by the user
               Scanner sc=new Scanner(System.in);
              
               while(true)
               {
                   System.out.print("Enter Employee no :");
                   empnumber=sc.next();
                   sc.nextLine();
                   System.out.print("Enter Employee Name :");
                   name=sc.nextLine();
                   System.out.print("Enter Joining Date :");
                   date=sc.next();
                  
                  
                   System.out.print("Enter Shift :");
                   int shift=sc.nextInt();
                  
                   System.out.print("Enter Payrate:");
                   double payrate=sc.nextDouble();
                  
                  
                  
                  
                   try {
                      
                       pw=new Productionworker(name, date, empnumber, shift, payrate);
                       break;
                   }
                   catch(Exception e)
                   {
                       continue;
                   }
               }


          

               System.out.println(pw.toString());
              
              
   }

}

___________________

Output:

Enter Employee no :123A
Enter Employee Name :Williams
Enter Joining Date :12/12/2006
Enter Shift :2
Enter Payrate:45000
:: Invalid Employee Number ::
Enter Employee no :123-A
Enter Employee Name :Williams
Enter Joining Date :12/12/2006
Enter Shift :3
Enter Payrate:45000
:: Invalid Shift ::
Enter Employee no :123-A
Enter Employee Name :Williams
Enter Joining Date :12/12/2006
Enter Shift :2
Enter Payrate:-45000
:: Invalid pay rate ::
Enter Employee no :123-A
Enter Employee Name :Willaims
Enter Joining Date :12/12/2006
Enter Shift :2
Enter Payrate:45000
Name: Willaims
Employee Number: 123-A
Hire Date: 12/12/2006 hourly payrate:45000.0

___________________Thank You