• Create a non-GUI based Java application that calculates weekly pay for an employee. The application should display text that requests the user input the name of the employee, the hourly rate, and the number of hours worked for that week. The application should then print out the name of the employee and the weekly pay amount. In the printout, display the dollar symbol ($) to the left of the weekly pay amount and format the weekly pay amount to display currency.

So what's ur exact problem? Displaying the result, or reading from commandline or what?

I am trying to use JCreator and I do not know exactly what I am supposed to do. I am not going to lie. I am so confussed in this class. I am a dummie to Java. This is my last class for my diploma and I am failing. I am not sure how to complete the code or exactly what code I am supposed to use. I have been searching the web trying to get a better understanding, but it is doing no good. I wish I had someone to help me understand. I have created the workspace for the assignment in JCreator, but I do not know where to go after that.

Before you start thinking in terms of code, maybe try understanding the steps involved in english. Write out some dot points on a piece of paper to get a better idea of what is going on. I'll give you step one:

Display text: "Please enter employee's name." Get input and store it somewhere.

Don't worry about how you are going to do this at this stage, just work out what needs to be done. This is an important stage of the problem solving process called design and it is a stage that requires practice, but I can't stress how important design is in the real world with complex problems to solve.

So give that a go, repost what you think the steps are and let us know what you can / can't code.

Ok, this is what I have for this program but am getting 3 error messaes first is line 15 it states illegal start of type, the second error is line 84 it states identifier expected and the third line is 88 it states class or interface expected anyone know how to fix this please let me know.

import java.util.Scanner; // program uses Scanner


public class Payroll3
{
private String nameOfEmployee;


public Payroll3( String name )
{
nameOfEmployee = name;
} // end constructor


boolean exit = false; // this flag will stop the program


// loop until user exits from program
while ( !exit )
{
// create Scanner to obtain input from command window
Scanner input = new Scanner( System.in );


float HoursWorked; // input number of hours worked
float PayRate; // input hourly pay rate
float multiply; // multiply NumberHours with PayRate


// clean input buffer
String cleanInputBuffer = "";


// input the employee's name
System.out.print( "Enter the employee's name or exit to quit:" );
String nameOfEmployee = input.nextLine(); // display employee's name


if(nameOfEmployee.equals("exit"))
{
System.out.println( "End of Program.");
exit = true;
} // end if statement


else
{
// user did not exit, so continue prompt
System.out.print( "Enter number of hours worked:" ); // prompt for input
HoursWorked = input.nextFloat(); // display number of hours worked
while ( HoursWorked <= 0 ) // prompt the user to input a positive number
{
System.out.print( "Number of hours worked must be a positive value." + "Please enter the number of hours worked again:" );
// prompt for a positive number
HoursWorked = input.nextFloat();
} // end while


//set hours worked
public void setHoursWorked( float hours )
{
HoursWorked = HoursWorked;
}
public float getHoursWorked() // method get hours worked
{
return HoursWorked;
}
System.out.print( "Enter hourly pay rate: " ); // prompt for input
PayRate = input.nextFloat(); // display hourly rate
while ( PayRate <= 0 ) // prompt the user to input a positive number
{
System.out.print( "Pay Rate must be a positive value." + "Enter hourly pay rate: " ); // prompt for a positive number
PayRate = input.nextFloat(); // display hourly rate
} // end while
public void setPayRate( float PayRate ) // method set pay rate
{
PayRate = PayRate;
}
public float getPayRate() // method get pay rate
{
return PayRate;
}
public float calculateWeeklyPay()
{
return multiply = HoursWorked * PayRate; //calculate weekly pay
}


System.out.print( "Total weekly pay is $%.2f\n", multiply); // display weekly pay
cleanInputBuffer = input.nextLine();
} // end else statement


System.out.println(); // inserts a blank line


} // end while


} // end main


} // end class Payroll3
and
import java.util.Scanner;


public class TestPayroll3
{ // start Payroll3


public static void main( String args[])
{
Scanner input = new Scanner( System.in );



TestPayroll3 myEmployee = new TestPayroll3();



System.out.printf("Enter the employee's name or exit to quit:");



System.out.print( "Enter hourly pay rate: " );
myEmployee.setpayrate(input.nextDouble());



System.out.print( "Please enter the number of hours worked again:" );
myEmployee.sethoursworked(input.nextDouble());



System.out.printf("Employee earned " + myEmployee.calculateweeklypay() );



} // end main
} // end Payroll3

Edited 3 Years Ago by happygeek: fixed formatting

This question has already been answered. Start a new discussion instead.