# Looking for assistance

Show 40 post(s) from this thread on one page
Page 1 of 2 12 Last
• 10-21-2009, 06:10 PM
s_dawg101
Looking for assistance
Design a class that models an employee. The employee is defined by the employee name and the pay. For hourly employees, the pay will be the hourly rate. For salaried employees, the pay is the weekly salary paid. You should have a boolean field that indicates whether an employee is paid by the hour or is paid salary. There should be a method called calculateWeeklyGrossPay which takes in the number of hours worked and returns the gross pay. This method should check to see if the employee is hourly or salary and return the calculated pay with or without overtime for hourly employees or the weekly salary for salaried employees.
• 10-21-2009, 06:13 PM
literallyjer
This looks like a homework assignment. What is your question?
• 10-21-2009, 06:39 PM
s_dawg101
Code:

```//the program is designed to model a employee //Branden Sullivan import java.util.Scanner; import java.text.DecimalFormat; public class Employee  {         public static void main(String [] args)         {           //variables are declared here         int Workers, totalWorkers;                                //Accumulator        //number of workers         String Employee;                                              //employee's name         double hours;                                                //hours worked         double hourlyRate;                                            //dollars per hour         double salary;                                                //salary         double calculateWeeklyGrossPay;          //calulated the gross pay for that week                                         DecimalFormat dollar = new DecimalFormat("#,##0.00");                 Scanner keyboard = new Scanner (System.in);                 //Get the number of workers from the user         System.out.print("How many employee's pay do you want to calculate?  ");         Workers = keyboard.nextInt();                 totalWorkers = 0;                 for (int count = 1; count <= Workers; count++){                 System.out.print("What is the employee's name?  ");                 Employee = keyboard.nextString();         }                        }  }```
this is what i have so far
• 10-21-2009, 06:45 PM
toymachiner62
We still aren't sure what your question is.
• 10-21-2009, 06:47 PM
r035198x
No those fields need to go into the employee class outside any method (not in the main method).
• 10-21-2009, 06:48 PM
s_dawg101
how would i get the program to ask the user for how many workers and then ask them what the name of each worker is? how would i end the loop? how would i start it??
• 10-21-2009, 06:50 PM
r035198x
Start by getting the Employee class right. Read my response above to see where you went wrong.
You get user input from the console using the Scanner class.
• 10-21-2009, 06:54 PM
toymachiner62
Quote:

//Get the number of workers from the user
System.out.print("How many employee's pay do you want to calculate? ");
Workers = keyboard.nextInt();
Well your asking the user for the number of employees, and then your setting the variable Workers to the number of employees.

Quote:

for (int count = 1; count <= Workers; count++){
System.out.print("What is the employee's name? ");
Employee = keyboard.nextString();
}
You have your loop right, it will loop through the correct number of users, the ony thing is your loop is only going to know the last person's name because you keep over writing the variable employee.

If a user enters 2 employees, its going to go to your for loop and ask the user for a name and then set the variable employee to that name. Then your loop is going to ask what the next user's name is and then it's going to set the variable Employee to that person's name--over writing the first name.
• 10-22-2009, 02:19 AM
s_dawg101
Code:

```//the program is designed to model a employee import java.util.Scanner; import java.text.DecimalFormat; public class Employee  {         public static void main(String [] args)         {           //variables are declared here         int Workers, totalWorkers;                                //number of workers         String Employee;                                              //employee's name         double hours;                                                //hours worked         double hourlyRate;                                            //dollars per hour         double salary;                                                //salary         double calculateWeeklyGrossPay;          //calulated the gross pay for that week                                         DecimalFormat dollar = new DecimalFormat("#,##0.00");                 Scanner keyboard = new Scanner (System.in);                 //Get the number of workers from the user         System.out.print("How many employee's pay do you want to calculate?  ");         Workers = keyboard.nextInt();                 totalWorkers = 0;                 for (int count = 1; count <= Workers; count++){         }                 System.out.print("What is the employee's name?  ");         Employee = keyboard.nextString();         }  }```
this is what i have and this error comes up

Code:

```Employee.java:33: cannot find symbol symbol  : method nextString() location: class java.util.Scanner         Employee = keyboard.nextString();                           ^ 1 error```
• 10-22-2009, 02:42 AM
Fubarable
It's telling you exactly what's wrong: the Scanner class doesn't have a method "nextString()". You'd best look up the Scanner API to see what methods are available.

Also, you still haven't created a true Employee class. I have a feeling that your teacher looking for a class that doesn't have a main method, or any static methods or variables. Then you'll likely have your main method in another class, say EmployeeTest that uses objects of the Employee class.
• 10-22-2009, 03:37 AM
s_dawg101
ok i got that done. no i need help on the demo class. how would i start???
• 10-22-2009, 05:57 AM
s_dawg101
Code:

```import java.util.Scanner; import java.text.DecimalFormat; public class EmployeeDemo  {         public static void main(String [] args)         {         DecimalFormat dollar = new DecimalFormat("#,##0.00");         Scanner keyboard = new Scanner (System.in);                 //variables are declared here         int newWorkers, totalWorkers;         String newEmployee;         double hours;         double hourlyRate;         double salary;                         //Get the number of workers from the user         System.out.print("How many employee's pay do you want to calculate?  ");         newWorkers = keyboard.nextInt();                 totalWorkers = 0;                 for (int count = 1; count <= newWorkers; count++){                 System.out.print("What is the employee's name?  ");                 newEmployee = keyboard.next();         }                 }    }```
this is what i have for the demonstration class. i dont know how i would get the names to not overwrite the other ones
• 10-22-2009, 08:16 AM
r035198x
Your first post says nothing about a test class for your Employee class. Concentrate on getting the Employee class first. You haven't posted what you have for that and it's the most important part.
• 10-22-2009, 11:59 AM
Fubarable
Agrees with r-etc. You need to get perspective on this assignment. I recommend that you talk to your teacher without delay.
• 10-22-2009, 12:23 PM
r035198x

r035198x (<---oppressed
• 10-23-2009, 05:54 PM
s_dawg101
Code:

```//the program is designed to model a employee import java.util.Scanner; import java.text.DecimalFormat; public class Employee  {         //variables are declared here         int Workers, totalWorkers;                          //number of workers         String Employee;                    //employee's name         double hours;                                                //hours worked         double hourlyRate;                                            //dollars per hour         double salary;                                                //salary         double calculateWeeklyGrossPay;          //calulated the gross pay for that week                                 public Employee(){                }                 public void setEmployee(String newEmployee){                 Employee = newEmployee;         }         public void setWorkers(int newWorkers){                 Workers = newWorkers;         }         public void sethours(double newhours){                 hours = newhours;         }         public void sethourlyRate(double newhourlyRate){                 hourlyRate = newhourlyRate;         }         public void setsalary(double newsalary){                 salary = newsalary;         }         //calculates the gross pay for the week         public double calculateWeeklyGrossPay(){                 calculateWeeklyGrossPay = hours * hourlyRate;                 return calculateWeeklyGrossPay;         }         public String getEmployee(){                 return Employee;         }         public int getWorkers(){                 return Workers;         }         public double gethours(){                 return hours;         }         public double hourlyRate(){                 return hourlyRate;         }         public double getsalary(){                 return salary;         }          }```
this is what i have for the employee class
Code:

``` import java.util.Scanner; import java.text.DecimalFormat; public class EmployeeDemo  {         public static void main(String [] args)         {         DecimalFormat dollar = new DecimalFormat("#,##0.00");         Scanner keyboard = new Scanner (System.in);                 //variables are declared here         int newWorkers, totalWorkers;         String newEmployee;         double hours;         double hourlyRate;         double salary;                         //Get the number of workers from the user         System.out.print("How many employee's pay do you want to calculate?  ");         newWorkers = keyboard.nextInt();                 totalWorkers = 0;                 for (int count = 1; count <= newWorkers; count++){                 System.out.print("What is the employee's name?  ");                 newEmployee = keyboard.next();                        }         System.out.print("Is the employee payed on a hourly rate or salary?  ");                 }  }```
and this is what i have for the demo class so far. i need help on the loop. is there a way not only to loop just the employee's names but other things at the same time???
• 10-23-2009, 05:58 PM
s_dawg101
i would like to have the program ask for how many employees there are?? and then ask the first employee's name and store that. then ask whether they are payed on an hourly rate or salary, then ask how many hours they worked and calculate the pay with or without overtime. then i would like that whole process to repeat. is there a way to do that???
• 10-23-2009, 06:19 PM
r035198x
Your Employee class cannot possibly compile like that. It is the important part of this assignment. You can't try to use it in the other class before you get it right.
You need to get rid of that setEmployee method and instead include a constructor that takes the values required to create an Employee.
• 10-23-2009, 06:24 PM
s_dawg101
the employee class does compile. i just need help on the demo class. i almost have it done.
Code:

```import java.util.Scanner; import java.text.DecimalFormat; public class EmployeeDemo  {         public static void main(String [] args)         {         DecimalFormat dollar = new DecimalFormat("#,##0.00");         Scanner keyboard = new Scanner (System.in);                 //variables are declared here         int newWorkers, totalWorkers;         String newEmployee;         double hours;         double hourlyRate;         double salary;         String choice;                         //Get the number of workers from the user         System.out.print("How many employee's pay do you want to calculate?  ");         newWorkers = keyboard.nextInt();                 totalWorkers = 0;                 for (int count = 1; count <= newWorkers; count++){                 System.out.print("What is the employee's name?  ");                 newEmployee = keyboard.next();                 System.out.print("Is the employee payed on a hourly rate or salary?  ");                 choice = keyboard.next();                 if(choice == "hourly rate" || choice == "Hourly Rate"){                         System.out.print("How many hours did the employee work?  ");                         hours = keyboard.nextDouble();                 }                 else{                         System.out.print("How much is this persons salary?  ");                         salary = keyboard.nextDouble();                 }                         }                         }  }```
this is what i have so far and it seems to work well. i just get one error message.
Code:

```How many employee's pay do you want to calculate?  4 What is the employee's name?  Greg Is the employee payed on a hourly rate or salary?  hourly rate How much is this persons salary?  Exception in thread "main" java.util.InputMismatchException         at java.util.Scanner.throwFor(Scanner.java:840)         at java.util.Scanner.next(Scanner.java:1461)         at java.util.Scanner.nextDouble(Scanner.java:2387)         at EmployeeDemo.main(EmployeeDemo.java:38)  ----jGRASP wedge2: exit code for process is 1.  ----jGRASP: operation complete.```
this is what i get when i type in hourly rate
• 10-23-2009, 06:33 PM
r035198x
Ok it does compile because your variable called Employee is a String which is meaningless.
You need that constructor that I talked about above for creating the employees. An employee is not a String. It is an object of type Employee created using something like
Employee employee = new Employee("The name of the employee", 4000, ....