**I'm to the point I think where I can ask a user to input a string value,
answer is Hourly.
if hourly the user enters hours, then the program prints out value in currency format

answer is Salary
user enters which salary level
Level 1 is for recent college grads
Level 2 is for executives

level one and level 2 have different salary levels and pay is calulated on a bi-weekly pay schedule**

import java.io.*;

public class Payroll
{

   public static void main( String args[] )throws IOException
{
    System.out.println("Are you an Hourly or Salary worked?");
    BufferedReader br;
        br = new BufferedReader( new InputStreamReader( System.in ) );//gathers data from user 
    String line = br.readLine();

    if(line.equals("Hourly"))
    {
        System.out.println("Enter Hours Worked");
        System.out.println("Enter Pay Rate");
    }
 [COLOR="Red"]       //a. If hourly then ask for the following
//i. Hours worked
//ii. Pay Rate
//1. If the hours worked is greater than 40 hours then you must calculate total 
//pay for the first 40 hours at the pay rate given and then calculate hours 
//above 40 at time and a half[/COLOR]

//        
    else if(line.equals("Salary"))
    {
    System.out.println("Enter a Salary level 1 or 2");
    } //Level 1 is for recent college grads
        //Level 2 is for executives
    else
    {
        System.out.println("     ");
        }
    }

}

//iii. The bottom line is just set to constant variables with the yearly 
//salary for either level and calculate the pay based on bi-weekly pay schedule.

//4. Be able to print/show the results for the date taken in after all data has been entered.

//5. Please put this into a loop that will allow more than one entry. 

//FORMAT THE RESULT AS A CURRENCY (w/ a $ sign in front of it)

Dani AI

Generated

A few concrete, practical fixes to finish this assignment and avoid common pitfalls raised in the thread (thanks to for asking for clarity and to for pointing at parsing).

Normalize and validate the text answer first (use trim() and equalsIgnoreCase() rather than ==). Parse numeric input inside a try/catch to handle bad input. Prefer BigDecimal or integer cents for money to avoid floating‑point rounding; if you want a quicker route, double plus formatted output is fine for a learning exercise.

Example patterns to use:

double hours = Double.parseDouble(hoursInput.trim());
double rate  = Double.parseDouble(rateInput.trim());
// overtime
double pay;
if (hours <= 40) pay = hours * rate;
else pay = 40 * rate + (hours - 40) * rate * 1.5;

For accurate money math and bi-weekly salary use BigDecimal and round explicitly:

BigDecimal annual = new BigDecimal("52000.00");
BigDecimal biweekly = annual.divide(new BigDecimal("26"), 2, RoundingMode.HALF_UP);

Format all monetary output with NumberFormat.getCurrencyInstance(Locale.US) so results show a leading $ and two decimals:

NumberFormat cf = NumberFormat.getCurrencyInstance(Locale.US);
System.out.println("Paid: " + cf.format(payAmount));

Make the program loop with a simple sentinel (ask “process another? y/n”) or wrap processing in a do { ... } while (answer.equalsIgnoreCase("y"));. Key cautions: always trim() inputs, catch NumberFormatException, and keep salary constants as named final values (e.g., LEVEL1_ANNUAL) so the bi-weekly division is clear and easy to change. This approach addresses the parsing and formatting questions raised while improving on the simple Integer.parseInt suggestion from .

Recommended Answers

All 5 Replies

Wait? What is your actual question, if I may ask.
This looks like an assignment I had one day :p

My question is I'm wondering what kind of control state I should use.
I know there is an IF statement in there, but I question how I would do that and when a condition is found true CONVERT USER INPUT so that I there program can calculate there entries to currency$
also
When a user enters selections I'm not sure how to convert those selections to FORMAT CURRENCY so that the strings they enter can be converted to output currency

Thanks for you feedback

Personally I have no idea what are you talking about. If you want to change a String to int then use:
String s="2";
int i=Integer.parseInt(s);

The rest of your post don't make any sense

I have read with more attention your post and I think that when you get the salary you can print it with a '$' at the beginning. I don't know if this is what you want because it sounds to easy:
String salary="20.00";
System.out.println("$"+salary);

I hope this makes it clearer
What this program is suppose to do is.

Prompt a user to enter HOURLY or SALARY worker
If HOURLY Worker, the User will enter hours worked & pay rate

If hours worked are > 40 calculate total pay for the first 40 hours at the entered pay rate given and then calculate hours above 40 at time and a half

THE DISPLAY WILL BE
HOURLY Worker
Worked: X number of hours
Paid: X amount of $ (format as US curreny)


If Salary Worker, the user will enter hours worked & Salary Level 1 or Level 2
Level 1 has one salary level
Level 2 has another salalry level
//Pay is calculated on a bi-weekly schedule for salary workers

THE DISPLAY WILL BE
Salary Worker
Worked: X number of hours
Paid: X amount of $ (format as US curreny)
//Pay is calculated on a bi-weekly schedule for salary workers

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.