Im lost....

• August 31st, 2010, 03:35 AM
brale76578
Im lost....
I have to write a program that keeps track of hours and pay for a single plumber.

1. Allow the user to enter the plumber's name, ID and pay rate.
2. Allow the user to enter the hours worked for each of 5 days. Store the data in an array.
3. Produce a report that lists the plumbers name, ID and pay rate, the average number of hours worked, the total hours worked and plumbers total pay. ( Take into account overtime which is paid at 1.5 times the pay rate for each hour worked over 40.)

My teacher expects us to know Java from high school and I was never taught it and I need your help to try and figure this out.

// houseKeeping()
int pay;
int date[] = new int[5];
int totalhours = 0;
int payRate = 10;
int otpay;
int id;
int othours;
String PlumbersName;

System.out.print("Enter Plumbers Name: ");

System.out.print("Enter Plumbers ID: ");

System.out.print("Enter Plumbers Pay Rate: ");

for(counter = 0; counter < 5; counter++)
{

date[counter] = 0;
}

for(counter = 4; counter >=0; counter--)
System.out.println("Hours Worked:" + counter + date[counter]);

System.out.println();

// workreport()
pay = totalhours * payRate;
otpay = othours * payrate * (payrate + (payrate + 1/2));

I cant get any of this to work....
• August 31st, 2010, 08:09 AM
j2me64
Re: Im lost....
i wrote an example for you. the code is not perfect, but runs without errors as long the input is correct. i hope, you got the idea, so you can enhance your own code.

Code :

```import java.io.*;   public class ImLost { public static void main(String[] args) { double totalPay; int hoursWorked[] = new int[5]; int totalHours = 0; int payRate = 10; double otPay; int id = 0; int otHours; String PlumbersName = "";   BufferedReader in = new BufferedReader(new InputStreamReader(System.in));   // read the plumbers name, id and pay rate try { System.out.print("Enter Plumbers name: "); PlumbersName = in.readLine();   System.out.print("Enter Plumbers id: "); id = Integer.parseInt(in.readLine());   System.out.print("Enter Plumbers Pay Rate: "); payRate = Integer.parseInt(in.readLine()); } catch (IOException e) { System.out.println(e.getMessage()); }   // loop 5 times for reading the hours worked for (int counter = 0; counter < hoursWorked.length; counter++) {   // initialize the array at element counter with 0 hoursWorked[counter] = 0; System.out.print("Hours worked day " + (counter + 1) + ": "); try { hoursWorked[counter] = Integer.parseInt(in.readLine()); } catch (IOException e) { System.out.println(e.getMessage()); } }   for (int counter = 0; counter < hoursWorked.length; counter++) { System.out .println("Hours Worked " + counter + hoursWorked[counter]); totalHours += hoursWorked[counter]; }   // workreport(), print plumbers parameters System.out.println("Pay report for " + PlumbersName); System.out.println("ID: " + id); System.out.println("Pay rate: " + payRate); // calculations System.out.println("Total of hours worked: " + totalHours); System.out.println("Average of hours worked: " + (totalHours / 5.0));   if (totalHours > 40) { otHours = totalHours - 40; otPay = otHours * (payRate * 1.5); totalPay = otPay + (40 * payRate); System.out.println("Total pay: " + totalPay); } else { System.out.println("Total pay: " + totalHours * payRate); } } }```