Im am trying to write a Java program with a system class called:PayScale.
1. It needs to prompt user for "Hours worked" and "Pay rate"
2. Determine if there is overtime
3. Calculate overtime at "time and 1/2"
4. Calculate regular pay
It must then print out:
1. Total hours worked
2. Regular hours
3. Overtime hours
4. Pay rate
5. Regular pay
6. Overtime pay
7. Total pay
I must also format the pay as currency and build in an exit key.
I have been trying for hours on end and cannot seem to solve. This is what I have so for:

import java.io.*;

public class PayScale

{
public static void main(String [] args) throws IOException

	{
		
	int input, sumA, sumB, sumC, sumD, sumF, sumG, sumH;
		sumA=0;
		sumB= 40;
		sumC=sumA - 40;
		sumD=sumF=sumG=sumH=0;

System.out.print("please enter your total hours worked [0 to exit] : ");

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	input = Integer.parseInt(br.readLine());

		if(input==0) System.exit(1);

		while(input != 0)
		{
			if(input <= 40)
			{
			System.out.println(input + " hours");
			}
			if(input > 40)
			{
			                sumB++;
			System.out.println(input +" hours");
			}
			if (input > 40) 
			{
				sumC++;
			System.out.println(input +" hours");
			}
						System.out.print("Please enter your pay rate[0 to exit]:");
		input = Integer.parseInt(br.readLine());
		}

System.out.println("The total number of hours worked is " + sumA );
System.out.println("The total number of regular hours worked is " + sumB );
System.out.println("The total number of overtime hours worked is " + sumC );

> I must also format the pay as currency
Do you mean having decimal points ? If yes then you could define your pay variable as float/double according to your requirement.

> Build an exit key
What you could do is have a menu printed at the start of every calculating stage mentioning the user about the options, say 1. to enter hours worked, 2. exit. Something of this sort. Then process accordingly.

I must also format the pay as currency: Actually I am not only supposed to have the decimal using a float/double, but it should show a dollar sign.

Build and exit key: I built an exit key using the number 0, but somehow I think it is entering into the formatted equations and changing the response I'm expecting. I could be wrong. I'm very very new at this.

Build and exit key: I built an exit key using the number 0, but somehow I think it is entering into the formatted equations and changing the response I'm expecting. I could be wrong. I'm very very new at this.

Thats the reason I suggested you a menu, at every stage of input taking, you could have a different exit key, which does not fall into the range of valid inputs for that stage.

I have tried for countless days and hours to get this PayScale program to work; however, i have not been successful and am almost ready to give up. I have attached my latest attemp at class PayScale_2 and have also attached the latest error message. Any help to get this coded correctly would be greatly appreciated. We are not allowed to use javabeans or any other ide, so everything is command coded. If that is the right terminology.
Thanks for any assistance!

If you want help, then identify, specifically, what you are trying to do and why it does not work. We aren't going to scour your program for errors and give you answers. We will help you if you specify what you need help with. Start by dividing your payscale program into logical units. That is, what does it need to do? You've already done so, above:

1. It needs to prompt user for "Hours worked" and "Pay rate"
2. Determine if there is overtime
3. Calculate overtime at "time and 1/2"
4. Calculate regular pay
It must then print out:
1. Total hours worked
2. Regular hours
3. Overtime hours
4. Pay rate
5. Regular pay
6. Overtime pay
7. Total pay

Now, write test code to make sure that those things are working properly. Since your program isn't working, clearly, not all of those work properly. Tell us which one doesn't, and post the code for it. Then we can help you further.

If you want help, then identify, specifically, what you are trying to do and why it does not work. We aren't going to scour your program for errors and give you answers. We will help you if you specify what you need help with. Start by dividing your payscale program into logical units. That is, what does it need to do? You've already done so, above:

1. It needs to prompt user for "Hours worked" and "Pay rate"
2. Determine if there is overtime
3. Calculate overtime at "time and 1/2"
4. Calculate regular pay
It must then print out:
1. Total hours worked
2. Regular hours
3. Overtime hours
4. Pay rate
5. Regular pay
6. Overtime pay
7. Total pay

Now, write test code to make sure that those things are working properly. Since your program isn't working, clearly, not all of those work properly. Tell us which one doesn't, and post the code for it. Then we can help you further.

1. Print out "Enter hours worked: ".... use a scanner... store variable.... repeat for "Enter $ per hour: "
2. if(hoursWorked > 40) overHours = hoursWorked-40;
3. overPay = overHours*(payRate*.5);
4. regularPay = hoursWorked*payRate

1. Print(hoursWorked)
2. Print(hoursWorked-overHours)
3. Print(overHours)
4. Print(payRate)
5. Print(payRate)
6. Print(payRate*1.5)
7. Print(regularPay+overPay)

initialize all your variables to 0 before you start and you should be good to go... hope I could help

a few words of advice... make your variables mean something rather than sumA and sumB... you get confused easily... also you might wanna use a scanner...

import java.util.Scanner;
Scanner input = new Scanner(System.in);
int variable = input.nextInt();

that way you can avoid parsing stuff after you read it... the program is pretty strait forward you just have to ask yourself how do I do each step... then just do it and edit later if you made a mistake or need to change something. Well thats my 2 cents for what its worth. How everything goes well.

All the errors point to just one thing that the symbol/variable input is not declared.

input = Integer.parseInt(br.readLine());

In the above code of yours, have initialized input but havne't declared it anywhere, declare the variable before using it.

Note: Also paste your code in code blocks in future so that the trouble of saving/opening it can be avoided on our part, also you can copy paste the error in the post itself.

I understand now. Thank you very much.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.