Results 1 to 17 of 17
Thread: Java Homework Help!
- 02-07-2013, 06:43 PM #1
Member
- Join Date
- Feb 2013
- Posts
- 26
- Rep Power
- 0
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:
It does not compile and I think It has to do with the Scanner classes. Please advise.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: "); } }
Thanks
-Austin
- 02-07-2013, 06:46 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,604
- Blog Entries
- 7
- Rep Power
- 17
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,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 02-07-2013, 07:13 PM #3
Member
- Join Date
- Feb 2013
- Posts
- 26
- Rep Power
- 0
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
- 02-07-2013, 07:14 PM #4
Senior Member
- Join Date
- Feb 2009
- Posts
- 303
- Rep Power
- 5
Re: Java Homework Help!
Your constructor is called "EmployeePay" while the class is called "employeePay". These need to match whatever the File is called.
- 02-07-2013, 07:28 PM #5
Member
- Join Date
- Feb 2013
- Posts
- 26
- Rep Power
- 0
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,
-AustinLast edited by ajb5876; 02-07-2013 at 07:33 PM.
- 02-07-2013, 07:32 PM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,604
- Blog Entries
- 7
- Rep Power
- 17
Re: Java Homework Help!
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 02-07-2013, 07:47 PM #7
Senior Member
- Join Date
- Feb 2009
- Posts
- 303
- Rep Power
- 5
Re: Java Homework Help!
>.< I didn't even see that void there...
- 02-07-2013, 08:01 PM #8
Member
- Join Date
- Feb 2013
- Posts
- 26
- Rep Power
- 0
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: "); } }
- 02-07-2013, 08:12 PM #9
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,604
- Blog Entries
- 7
- Rep Power
- 17
Re: Java Homework Help!
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 02-08-2013, 03:45 AM #10
Member
- Join Date
- Feb 2013
- Posts
- 26
- Rep Power
- 0
- 02-10-2013, 06:53 PM #11
Member
- Join Date
- Feb 2013
- Posts
- 26
- Rep Power
- 0
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?
- 02-11-2013, 05:03 AM #12
Member
- Join Date
- Feb 2013
- Posts
- 26
- Rep Power
- 0
Re: Java Homework Help!
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?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: "); } }
-Austin
- 02-11-2013, 04:06 PM #13
Member
- Join Date
- Feb 2013
- Posts
- 26
- Rep Power
- 0
Re: Java Homework Help!
Bump. Any Thoughts?
- 02-11-2013, 04:10 PM #14
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,604
- Blog Entries
- 7
- Rep Power
- 17
- 02-11-2013, 04:14 PM #15
Senior Member
- Join Date
- Oct 2010
- Posts
- 317
- Rep Power
- 3
Re: Java Homework Help!
Hi ajb5876.
Under what condition does the value of numManager change?
Regards.
- 02-11-2013, 04:21 PM #16
Member
- Join Date
- Feb 2013
- Posts
- 26
- Rep Power
- 0
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.
- 02-13-2013, 11:08 AM #17
Member
- Join Date
- Nov 2012
- Location
- Johannesburg, South Africa
- Posts
- 40
- Rep Power
- 0
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
-
Need HW help on java homework
By sourlemons in forum New To JavaReplies: 3Last Post: 10-16-2010, 05:44 AM -
Need help with my java homework.
By nightrise420 in forum New To JavaReplies: 6Last Post: 09-24-2010, 07:23 PM -
java homework help
By jenniferrlie in forum New To JavaReplies: 5Last Post: 09-22-2009, 08:12 PM -
Java homework please
By Indulgence in forum New To JavaReplies: 1Last Post: 11-03-2008, 02:48 AM -
LF: Homework help with Java
By excurssion in forum New To JavaReplies: 2Last Post: 10-17-2008, 06:00 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks