Alright, I'm sure the problem I'm having is an oversight on my part but I'm not seeing my mistake.
WorkerDemoWilson.java:13: error: cannot find symbol ProductionWorkerWilson pw1 = new prodWorker("Bob Jones", "321-D", "09-20-1980", ^ symbol: class prodWorker location: class WorkerDemoWilson WorkerDemoWilson.java:17: error: cannot find symbol ProductionWorkerWilson pw2 = new prodWorker("James Dean", "333", "09-20-1980", ^ symbol: class prodWorker location: class WorkerDemoWilson WorkerDemoWilson.java:21: error: cannot find symbol ProductionWorkerWilson pw3 = new prodWorker("Aaron Fletcher", "123-D", "09-20-1980", ^ symbol: class prodWorker location: class WorkerDemoWilson WorkerDemoWilson.java:25: error: cannot find symbol ProductionWorkerWilson pw4 = new prodWorker("Ed Robertson", "666-D", "09-20-1980", ^ symbol: class prodWorker location: class WorkerDemoWilson WorkerDemoWilson.java:79: error: cannot find symbol ProductionWorkerWilson pw = new prodWorker(employeeName, employeeNumber, hireDate, shift, payRate); ^ symbol: class prodWorker location: class WorkerDemoWilson WorkerDemoWilson.java:79: error: cannot find symbol ProductionWorkerWilson pw = new prodWorker(employeeName, employeeNumber, hireDate, shift, payRate); ^ symbol: variable employeeName location: class WorkerDemoWilson WorkerDemoWilson.java:79: error: cannot find symbol ProductionWorkerWilson pw = new prodWorker(employeeName, employeeNumber, hireDate, shift, payRate); ^ symbol: variable employeeNumber location: class WorkerDemoWilson WorkerDemoWilson.java:79: error: cannot find symbol ProductionWorkerWilson pw = new prodWorker(employeeName, employeeNumber, hireDate, shift, payRate); ^ symbol: variable hireDate location: class WorkerDemoWilson WorkerDemoWilson.java:79: error: cannot find symbol ProductionWorkerWilson pw = new prodWorker(employeeName, employeeNumber, hireDate, shift, payRate); ^ symbol: variable shift location: class WorkerDemoWilson WorkerDemoWilson.java:79: error: cannot find symbol ProductionWorkerWilson pw = new prodWorker(employeeName, employeeNumber, hireDate, shift, payRate); ^ symbol: variable payRate location: class WorkerDemoWilson WorkerDemoWilson.java:81: error: return outside method return pw; // Returning the production worker ^ 11 errors
public class WorkerDemoWilson { public static void main(String[] args) { // A normal functioning production worker ProductionWorkerWilson pw1 = new prodWorker("Bob Jones", "321-D", "09-20-1980", 1, 12.25); // A production worker with an invalid employee number. ProductionWorkerWilson pw2 = new prodWorker("James Dean", "333", "09-20-1980", 1, 12.25); // A production worker with an invalid shift. ProductionWorkerWilson pw3 = new prodWorker("Aaron Fletcher", "123-D", "09-20-1980", 3, 12.25); // A production worker with an invalid pay rate. ProductionWorkerWilson pw4 = new prodWorker("Ed Robertson", "666-D", "09-20-1980", 1, -500.00); // Heres our production worker currently. System.out.println(pw1); System.out.println(); System.out.println(pw2); System.out.println(); System.out.println(pw3); System.out.println(); System.out.println(pw4); System.out.println(); } // prodWorker method that creates instances. public static ProductionWorkerWilson prodWorker(String name, String num, String date, int shi, double rate) { try { if(num.length() < 5 || num.length() > 5) { throw new InvalidEmployeeNumber(); // Throws exception for invalid employee numbers } } catch(InvalidEmployeeNumber e) { System.out.println(e.getMessage() + num); } try { if(shi != 1 && shi != 2) { throw new InvalidShift(); // Throws the exception for an invalid shift number } } catch(InvalidShift e) { System.out.println(e.getMessage() + shi); } try { if(rate < 0) { throw new InvalidPayRate(); // Throws the exception for an invalid shift number } } catch(InvalidPayRate e) { System.out.println(e.getMessage() + rate); } } // Creating the production worker ProductionWorkerWilson pw = new prodWorker(employeeName, employeeNumber, hireDate, shift, payRate); { return pw; // Returning the production worker } }
public class ProductionWorkerWilson extends EmployeeWilson { public static final int day_shift = 1; // The day shift (1) public static final int night_shift = 2; // The night shift (2) private int shift; private double payRate; // The hourly pay rate. /** Constructor */ public ProductionWorkerWilson() { super(); shift = day_shift; payRate = 0.0; } /** Overloaded constructor */ public ProductionWorkerWilson(String n, String num, String date, int shi, double rate) { super(n, num, date); shift = shi; payRate = rate; } /** Accessor method that gets the shift number. */ public int getShift() { return shift; } /** Accessor method that gets the hourly pay rate. */ public double getPayRate() { return payRate; } /** Mutator method that sets the shift number. */ public void setShift(int shi) throws InvalidShift { // Making sure the shift is either 1 or 2 if(shi < 1 || shi > 2) { throw new InvalidShift(); // Throws the invalid shift exception. } else { shift = shi; // If it passes the check, it sets the shift accordingly } } /** Mutator method that sets the pay rate. */ public void setPayRate(double rate) throws InvalidPayRate { // Checking to see if the payrate is invalid if(rate < 0) { throw new InvalidPayRate(); // Throws the invalid pay rate exception } else { payRate = rate; // If it passes the check, it sets the payrate accordingly } } // The toString method public String toString() { String string = super.toString(); string += "\nShift: "; if(shift == day_shift) { string += "1 (Day)"; } else if(shift == night_shift) { string += "2 (Night)"; } else { string += "Invalid Shift Number"; } return string += ("\nPay Rate: $" + payRate); }
public class EmployeeWilson { public String employeeName; // The employee's name. public String employeeNumber; // The employee's number, formated as XXX-L. public String hireDate; // The date in which the employee was hired. /** Constructor */ public EmployeeWilson() { employeeName = ""; employeeNumber = ""; hireDate = ""; } /** Overloaded constructor */ public EmployeeWilson(String n, String num, String date) { //Sets the values of the employeename, employeenumber, and hireDate employeeName = n; employeeNumber = num; hireDate = date; } /** Accessor method that gets the employee's name */ public String getEmployeeName() { return employeeName; } /** Accessor method that gets the employee's numbers */ public String getEmployeeNumber() { return employeeNumber; } /** Accessor method that gets the employee's hire date */ public String getHireDate() { return hireDate; } /** Mutator method that sets the employee's name with the new name. */ public void setEmployeeName(String n) { employeeName = n; } /** Mutator method that sets the employee's number with the new number. */ public void setEmployeeNumber(String num) throws InvalidEmployeeNumber { if(isValidEmpNum(num)) { employeeNumber = num; } else { employeeNumber = ""; throw new InvalidEmployeeNumber(); // Throws the invalid employee number exception } } /** Mutator method that sets the employee's hire date with the new hire date. */ public void setHireDate(String newHDate) { hireDate = newHDate; } // isValidEmpNum method checks to see if the employee number is formatted correctly private boolean isValidEmpNum(String num) { // Default boolean status to true boolean status = true; //Making sure the number is correct. if(num.length() != 5) { status = false; } return status; } // The toString method public String toString() { String string = "Name: " + employeeName + "\nEmployee Number: "; if(employeeNumber == "") { string += "Invalid Employee Number"; } else { string += employeeNumber; } return string += ("\nHire Date: " + hireDate); }
The idea is that I'm trying to create 4 separate objects that I can then call to print. One will work fine, but the other 3 will not work and throw an exception which has been handled in some exception classes. Demonstrating the exception code.