Results 1 to 17 of 17
  1. #1
    ajb5876 is offline Member
    Join Date
    Feb 2013
    Posts
    26
    Rep Power
    0

    Default Java Homework Help!

    This is an assignment for my IST 240 – (Java Classes, Objects and Methods)

    Assignment:

    This assignment gives you an opportunity to learn how to define, create and use Java classes and methods. A
    company pays its employees as managers (who receive a fixed weekly salary), hourly workers (who receive a fixed
    hourly wage for up to the first 40 hours they work and time and a half (i.e. 1.5 times their hourly wage) for overtime
    hours worked, commission workers (who receive $350 plus 7.5% of their gross weekly sales), and pieceworkers
    (who receive a fixed amount of money per item for each of the items they produce – each pieceworker in this
    company works on only one type of item).

    Define a Java class named EmployeePayment that includes functionality to compute the weekly pay for each employee. You do not know the number of employees in advance. Each type of employee has its own pay code: Managers have paycode 1, hourly workers have paycode 2, commission workers have paycode 3 and pieceworkers have paycode 4.

    Define a main method that creates an instance of the EmployeePayment class, and calls the setManagerPay
    method to set the managers weekly salary to $625.00. The main method should then prompt the user for the
    paycode –“Enter paycode (-1 to end): “, validate the input and perform the associated processing for that paycode.Your program should allow the user to process employees until a paycode of -1 has been entered. Use a switch structure to compute each employee’s pay, based on the employee’s paycode. Within the switch, prompt the user (i.e. the payroll clerk) to enter the appropriate facts your program needs to calculate each employee’s pay based on that employee’s paycode, invoke the respective method (defined below) to perform the calculations and return the weekly pay for each type of employee, and print the returned weekly pay for each employee.

    Define a setManagerPay method that accepts and stores the fixed weekly salary value for managers.

    A private instance variable weeklyManagerPay should be defined in the EmployeePayment class to support these accessor and mutator methods.

    Define a calcManagerPay method that has no parameters and returns the fixed weekly salary.

    Define a calcHourlyWorkerPay method that accepts the hourly salary and total hours worked as input parameters and returns the weekly pay based on the hourly worker pay code description.

    Define a calcCommWorkerPay method that accepts the gross weekly sales as an input parameter and returns the weekly pay based on the commission worker pay code description.

    Define a calcPieceWorkerPay method that accepts the number of pieces and wage per piece as input parameters and returns the weekly pay based on the piece worker pay code description.

    Once all workers have been processed, the total number of each type of employee processed should be printed. Define and manage the following private instance variables (numManager, numHourlyWorker, numCommWorker, and numPieceWorker) within the EmployeePayment class. What are the ways in which these variables can be updated?


    Here is my code:
    Java Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    package employeepay;
    import java.io.InputStream;
    import java.util.Scanner;
    /**
     *
     * @author Austin Benner
     */
    public class employeepay {
        
       private static double weeklyManagerPay;
       private static double numHourlyWorker;
       private static double numCommWorker;
       private static double numPieceWorker;
       public static int numManager=0;
       private static double hourlySalary = 0;
       private static double totalHours = 0;
       private static double weeklySale = 0;
       private static double numPieces = 0;
       private static double wagePerPiece = 0;
    
        private static double Scanner(InputStream in) {
            throw new UnsupportedOperationException("Not yet implemented");
        }
       
       
     public void EmployeePay(){}
       
        public static void setManagerPay()
       
       {
           weeklyManagerPay= 625;
       }
        
       public static double calcManagerPay()
               
       {
           setManagerPay();
           return weeklyManagerPay;
       }
       
       public static double calcHourlyWorkerPay (double hw, double thw)
       
       {
           return numHourlyWorker= hw * thw;
       }
       
       
    
       public static double calcCommWorkerPay (double cw)
       
       {
           return numCommWorker = 350 * (cw * .075);
           
       }
       
       
       
        public static double calcPieceWorkerPay (double pw, double np)
                
        {
            return numPieceWorker = pw * np;
        }
       
       
       
       public void setManagerPay (int mp)
       {
           numManager = mp;
       }
       
        public int getManagerPay ()
       {
           return numManager;
       }
        
     
        
        public static void main( String args[] ) 
        {
                
           	int[] numberArr = new int[4]; // Creates and array to read inputs into
    	
            Scanner sc = new Scanner (System.in); // Creates a new instance of the Scanner() method
    	System.out.println("Enter four integers...");
    	
    	int number_1 = sc.nextInt(); // Reads in the four integer inputs from user
    	int number_2 = sc.nextInt();
    	int number_3 = sc.nextInt();
    	int number_4 = sc.nextInt();
    	
    	numberArr[0] = number_1;
    	numberArr[1] = number_2;
    	numberArr[2] = number_3;
    	numberArr[3] = number_4;
    
            while(numManager != -1) 
            {
                System.out.println ("Enter paycode (-1 to end): ");
                numManager = new Scanner (System.in);
                switch(numManager)
                {
                    case 1: 
                        
                 System.out.println("Manager Selected. ");
                 System.out.println("Weekly Manager Pay: " + calcManagerPay());
                 break;
                        
                    case 2:
                        
                 System.out.println ("Hourly Worker Selected. ");
                 System.out.println("Enter the Hourly Salary. ");
                 hourlySalary = Scanner (System.in);
                 System.out.println("Enter the Total Hours Worked. ");
                 totalHours = Scanner (System.in); 
                 System.out.println("Hourly worker pay is " + calcHourlyWorkerPay(hourlySalary, totalHours));
                        
                        break;
                        
                    case 3:
                        System.out.println (" Commision worker selected. ");
                        System.out.println(" Enter gross weekly sales. ");
                        weeklySale = Scanner (System.in);
                        System.out.println("Commision's Worker Pay is. " + calcCommWorkerPay(weeklySale));
                    break;
                        
                    case 4:
                        
                        System.out.println (" Piece worker selected. ");
                        System.out.println(" Enter the number of Pieces. ");
                        numPieces = Scanner (System.in);
                        System.out.println("Enter the wage Per Piece. " );
                        wagePerPiece = Scanner (System.in);
                        System.out.println("Piece Worker's pay. " + calcPieceWorkerPay (numPieces, wagePerPiece));
                        
                     break;
                }
                
            }
           System.out.println("Total number of Managers paid: ");
           System.out.println("Total number of hourly workers paid: ");
           System.out.println("TOtal number of commision workers paid: ");
           System.out.println("Total number of piece workers paid: ");
        } 
        
    }
    It does not compile and I think It has to do with the Scanner classes. Please advise.

    Thanks
    -Austin

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,526
    Blog Entries
    7
    Rep Power
    20

    Default Re: Java Homework Help!

    What does your compiler say? "I refuse to compile this", "not now, I have a head ache" or what?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    ajb5876 is offline Member
    Join Date
    Feb 2013
    Posts
    26
    Rep Power
    0

    Default Re: Java Homework Help!

    run:
    java.lang.NoClassDefFoundError: employeepay/EmployeePay (wrong name: employeepay/employeepay)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java :791)
    at java.security.SecureClassLoader.defineClass(Secure ClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader .java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader. java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:4 23)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 56)
    at sun.launcher.LauncherHelper.checkAndLoadMain(Launc herHelper.java:482)
    Exception in thread "main" Java Result: 1
    BUILD SUCCESSFUL (total time: 2 seconds)

    That is what it gives me at the bottom Output

  4. #4
    StormyWaters is offline Senior Member
    Join Date
    Feb 2009
    Posts
    305
    Rep Power
    6

    Default Re: Java Homework Help!

    Your constructor is called "EmployeePay" while the class is called "employeePay". These need to match whatever the File is called.

  5. #5
    ajb5876 is offline Member
    Join Date
    Feb 2013
    Posts
    26
    Rep Power
    0

    Default Re: Java Homework Help!

    I actually figured that out right before your post :-P should have looked at the error code first before psoting it up. So now that that is fixed it is still throwing me an error.

    run:
    Enter paycode (-1 to end):
    Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - incompatible types
    required: int
    found: java.util.Scanner
    at employeepay.EmployeePay.main(EmployeePay.java:95)
    Java Result: 1
    BUILD SUCCESSFUL (total time: 1 second)

    As you can see it does some how read Enter paycode (-1 to end): but then fails immediately after that. Any thoughts? I think line 104 is the problem.

    Thanks,
    -Austin
    Last edited by ajb5876; 02-07-2013 at 07:33 PM.

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,526
    Blog Entries
    7
    Rep Power
    20

    Default Re: Java Homework Help!

    Quote Originally Posted by StormyWaters View Post
    Your constructor is called "EmployeePay" while the class is called "employeePay". These need to match whatever the File is called.
    There is no constructor 'EmployeePay'; just an empty (void) method ... but I agree, the OP should check the capitalization of the class name and the file name.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    StormyWaters is offline Senior Member
    Join Date
    Feb 2009
    Posts
    305
    Rep Power
    6

    Default Re: Java Homework Help!

    >.< I didn't even see that void there...

  8. #8
    ajb5876 is offline Member
    Join Date
    Feb 2013
    Posts
    26
    Rep Power
    0

    Default Re: Java Homework Help!

    Here is new updated code.
    fixed a few things in it as well. Still not compiling correctly.

    Java Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    package employeepay;
    import java.io.InputStream;
    import java.util.Scanner;
    
    /**
     *
     * @author Austin J Benner
     */
    public class EmployeePay {
        
       private static double weeklyManagerPay;
       private static double numHourlyWorker;
       private static double numCommWorker;
       private static double numPieceWorker;
       public static int numManager=0;
       private static double hourlySalary = 0;
       private static double totalHours = 0;
       private static double weeklySale = 0;
       private static double numPieces = 0;
       private static double wagePerPiece = 0;
    
        private static double Scanner(InputStream in) {
            throw new UnsupportedOperationException("Not yet implemented");
        }
       
       
     public void EmployeePay(){}
       
        public static void setManagerPay()
       
       {
           weeklyManagerPay= 625;
       }
        
       public static double calcManagerPay()
               
       {
           setManagerPay();
           return weeklyManagerPay;
       }
       
       public static double calcHourlyWorkerPay (double hw, double thw)
       
       {
           return numHourlyWorker= hw * thw;
       }
       
       
    
       public static double calcCommWorkerPay (double cw)
       
       {
           return numCommWorker = 350 * (cw * .075);
           
       }
       
       
       
        public static double calcPieceWorkerPay (double pw, double np)
                
        {
            return numPieceWorker = pw * np;
        }
       
       
       
       public void setManagerPay (int mp)
       {
           numManager = mp;
       }
       
        public int getManagerPay ()
       {
           return numManager;
       }
        
     
        
        public static void main( String args[] ) 
        {
            
           	int[] numberArr = new int[4]; // Creates and array to read inputs into
    	
            Scanner sc = new Scanner (System.in); // Creates a new instance of the Scanner() method
    
    
            while(numManager != -1) 
            {
                System.out.println ("Enter paycode (-1 to end): ");
                numManager = new Scanner (System.in);
                switch(numManager)
                {
                    case 1: 
                        
                 System.out.println("Manager Selected. ");
                 System.out.println("Weekly Manager Pay: " + calcManagerPay());
                 break;
                        
                    case 2:
                        
                 System.out.println ("Hourly Worker Selected. ");
                 System.out.println("Enter the Hourly Salary. ");
                 hourlySalary = Scanner (System.in);
                 System.out.println("Enter the Total Hours Worked. ");
                 totalHours = Scanner (System.in); 
                 System.out.println("Hourly worker pay is " + calcHourlyWorkerPay(hourlySalary, totalHours));
                        
                        break;
                        
                    case 3:
                        System.out.println (" Commision worker selected. ");
                        System.out.println(" Enter gross weekly sales. ");
                        weeklySale = Scanner (System.in);
                        System.out.println("Commision's Worker Pay is. " + calcCommWorkerPay(weeklySale));
                    break;
                        
                    case 4:
                        
                        System.out.println (" Piece worker selected. ");
                        System.out.println(" Enter the number of Pieces. ");
                        numPieces = Scanner (System.in);
                        System.out.println("Enter the wage Per Piece. " );
                        wagePerPiece = Scanner (System.in);
                        System.out.println("Piece Worker's pay. " + calcPieceWorkerPay (numPieces, wagePerPiece));
                        
                     break;
                }
                
            }
           System.out.println("Total number of Managers paid: ");
           System.out.println("Total number of hourly workers paid: ");
           System.out.println("TOtal number of commision workers paid: ");
           System.out.println("Total number of piece workers paid: ");
        } 
        
    }

  9. #9
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,526
    Blog Entries
    7
    Rep Power
    20

    Default Re: Java Homework Help!

    Quote Originally Posted by ajb5876 View Post
    I actually figured that out right before your post :-P should have looked at the error code first before psoting it up. So now that that is fixed it is still throwing me an error.

    run:
    Enter paycode (-1 to end):
    Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - incompatible types
    required: int
    found: java.util.Scanner
    at employeepay.EmployeePay.main(EmployeePay.java:95)
    Java Result: 1
    BUILD SUCCESSFUL (total time: 1 second)

    As you can see it does some how read Enter paycode (-1 to end): but then fails immediately after that. Any thoughts? I think line 104 is the problem.

    Thanks,
    -Austin
    numManager is an int but you're trying to assign a Scanner to it; the compiler complained about it but you still attempted to run it; this is what the JVM throws at you.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  10. #10
    ajb5876 is offline Member
    Join Date
    Feb 2013
    Posts
    26
    Rep Power
    0

    Default Re: Java Homework Help!

    Quote Originally Posted by JosAH View Post
    numManager is an int but you're trying to assign a Scanner to it; the compiler complained about it but you still attempted to run it; this is what the JVM throws at you.

    kind regards,

    Jos
    So how do I go about doing that? (I am new to Java)

    Thanks
    -Austin

  11. #11
    ajb5876 is offline Member
    Join Date
    Feb 2013
    Posts
    26
    Rep Power
    0

    Default Re: Java Homework Help!

    I think I need to create some sort of variable that uses as my condition to my loop. Perhaps a boolean but im not sure about how to go about this. Then when -1 is entered, it should switch the boolean so the looping stops. Correct?

  12. #12
    ajb5876 is offline Member
    Join Date
    Feb 2013
    Posts
    26
    Rep Power
    0

    Default Re: Java Homework Help!

    Java Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    package employeepay;
    import java.io.InputStream;
    import java.util.Scanner;
    
    /**
     
     * @author Austin J Benner
     */
    public class EmployeePay {
        
       private static double weeklyManagerPay;
       private static double numHourlyWorker;
       private static double numCommWorker;
       private static double numPieceWorker;
       private static int numManager =0;
       private static double hourlySalary = 0;
       private static double totalHours = 0;
       private static double weeklySale = 0;
       private static double numPieces = 0;
       private static double wagePerPiece = 0;
       
    
        private static double Scanner(InputStream in) {
           throw new UnsupportedOperationException("paycode");
        }
       
       
     public void EmployeePay(){}
       
        public static void setManagerPay()
       
       {
           weeklyManagerPay= 625;
       }
        
       public static double calcManagerPay()
               
       {
           setManagerPay();
           return weeklyManagerPay;
       }
       
       public static double calcHourlyWorkerPay (double hw, double thw)
       
       {
           return numHourlyWorker= hw * thw;
       }
       
       
    
       public static double calcCommWorkerPay (double cw)
       
       {
           return numCommWorker = 350 * (cw * .075);
           
       }
       
       
       
        public static double calcPieceWorkerPay (double pw, double np)
                
        {
            return numPieceWorker = pw * np;
        }
       
       
       
       public void setManagerPay (int mp)
       {
           numManager = mp;
       }
       
        public int getManagerPay ()
       {
           return numManager;
       }
        
     
        
        public static void main( String args[] ) 
        {
            int paycode;
             Scanner sc = new Scanner (System.in); // Creates a new instance of the Scanner() method
    
    
            while(numManager != -1) 
            {
                System.out.println ("Enter paycode (-1 to end): ");
               paycode = sc.nextInt();
                switch(paycode)
                {
                    case 1: 
                        
                 System.out.println("Manager Selected. ");
                 System.out.println("Weekly Manager Pay: " + calcManagerPay());
                 break;
                        
                    case 2:
                        
                 System.out.println ("Hourly Worker Selected. ");
                 System.out.println("Enter the Hourly Salary. ");
                 hourlySalary = sc.nextDouble();
                 System.out.println("Enter the Total Hours Worked. ");
                 totalHours = sc.nextDouble();
                 System.out.println("Hourly worker pay is " + calcHourlyWorkerPay(hourlySalary, totalHours));
                        
                        break;
                        
                    case 3:
                        System.out.println (" Commision worker selected. ");
                        System.out.println(" Enter gross weekly sales. ");
                        weeklySale = sc.nextDouble();
                        System.out.println("Commision's Worker Pay is. " + calcCommWorkerPay(weeklySale));
                    break;
                        
                    case 4:
                        
                        System.out.println (" Piece worker selected. ");
                        System.out.println(" Enter the number of Pieces. ");
                        numPieces = sc.nextDouble();
                        System.out.println("Enter the wage Per Piece. " );
                        wagePerPiece = sc.nextDouble();
                        System.out.println("Piece Worker's pay. " + calcPieceWorkerPay (numPieces, wagePerPiece));
                        
                     break;
                }
                
            }
           System.out.println("Total number of Managers paid: ");
           System.out.println("Total number of hourly workers paid: ");
           System.out.println("TOtal number of commision workers paid: ");
           System.out.println("Total number of piece workers paid: ");
        } 
        
    }
    After a bunch of research I have figured most of it out, but for some reason the loop will not end when the user presses -1. Does anybody have any ideas?


    -Austin

  13. #13
    ajb5876 is offline Member
    Join Date
    Feb 2013
    Posts
    26
    Rep Power
    0

    Default Re: Java Homework Help!

    Bump. Any Thoughts?

  14. #14
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,526
    Blog Entries
    7
    Rep Power
    20

    Default Re: Java Homework Help!

    Quote Originally Posted by ajb5876 View Post
    After a bunch of research I have figured most of it out, but for some reason the loop will not end when the user presses -1. Does anybody have any ideas?
    You're not changing it anywhere in that loop so that variable stays the same forever.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  15. #15
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    335
    Rep Power
    4

    Default Re: Java Homework Help!

    Hi ajb5876.

    Under what condition does the value of numManager change?

    Regards.

  16. #16
    ajb5876 is offline Member
    Join Date
    Feb 2013
    Posts
    26
    Rep Power
    0

    Default Re: Java Homework Help!

    Someone correct me if Im wrong but t doesnt.... I cannot change numManager to paycode allowing it to exit and i think that's where the problem is.

  17. #17
    Kagiso is offline Member
    Join Date
    Nov 2012
    Location
    Johannesburg, South Africa
    Posts
    92
    Rep Power
    0

    Default Re: Java Homework Help!

    Buddy I think you should fisrt start by reducing your code in lines that are not necessary.... like the method in line 33(you're not using it),
    I've looked at calcManagerPay() and setManagerPay() why don't you use a single method that returns 625...
    Did you really need to create another instance of Scanner in a while loop
    Line 104.. wasn't it supposed to be numManager = sc.nextInt() because we are expecting an int
    line 91 to 99 what if you write it like this way .... numberArr[0] = sc.nextInt()..

    I think a shorter code is much easier to read

    To the Java gurus.... "please correct me if i'm wrong"
    Last edited by Kagiso; 02-13-2013 at 11:10 AM.

Similar Threads

  1. Need HW help on java homework
    By sourlemons in forum New To Java
    Replies: 3
    Last Post: 10-16-2010, 05:44 AM
  2. Need help with my java homework.
    By nightrise420 in forum New To Java
    Replies: 6
    Last Post: 09-24-2010, 07:23 PM
  3. java homework help
    By jenniferrlie in forum New To Java
    Replies: 5
    Last Post: 09-22-2009, 08:12 PM
  4. Java homework please
    By Indulgence in forum New To Java
    Replies: 1
    Last Post: 11-03-2008, 02:48 AM
  5. LF: Homework help with Java
    By excurssion in forum New To Java
    Replies: 2
    Last Post: 10-17-2008, 06:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •