Results 1 to 6 of 6
Thread: tlouvierre
- 04-30-2009, 11:03 AM #1
Member
- Join Date
- Apr 2009
- Location
- I live Stafford Texas right outside of Houston.
- Posts
- 78
- Rep Power
- 0
tlouvierre
// Payroll Program Part 2
// Author: Tiffany D. Louvierre-Ramirez
// April 30, 2009
import java.util.Scanner; // program uses class Scanner
public class Payroll Program Part 2
{
// main method begins execution of java application
public static void main( String args[] )
{
System.out.println( "Welcome to the Payroll Program Calculator " );
boolean stop = false; // This flag will control whether we exit the loop below
// Loop until user types "stop" as the employee name:
while (!stop)
{
// create scanner to obtain input from command window
Scanner input = new Scanner ( System.in );
System.out.println(); // outputs a blank line
System.out.print( "Please enter the employee name or stop to terminate program: " );
// prompt for and input employee name
String empName = input.nextLine(); // read employee name
if ( empName.equals("stop")) // Check whether user indicated to stop program
{
System.out.println( "Program Terminated" );
stop = true;
}
else
{
// User did not indicate to stop, so continue reading info for this iteration:
float hourlyRate; // hourly rate
float hoursWorked; // hours worked
float weeklyPay; // Weekly Pay for employee
System.out.print( "Enter hourly rate: " ); // prompt for hourly rate
hourlyRate = input.nextFloat(); // read hourly rate
while (hourlyRate >= 0) // prompt until a positive value is entered
{
System.out.print( "Hourly rate must be a positive value. " +
"Please enter the hourly rate again: " ); // prompt for positive value for hourly rate
hourlyRate = input.nextFloat(); // read hourly rate again
}
System.out.print( "Enter hours worked: " ); // prompt for # of hours
hoursWorked = input.nextFloat(); // read # of hours
while (hoursWorked >= 0) // prompt until a positive value is entered
{
System.out.print( "Hours worked must be a positive value. " +
"Please enter the hours worked again: " ); // prompt for positive value for hours worked
hoursWorked = input.nextFloat(); // read hours worked again
}
// Move on to calculate Weekly Pay.
weeklyPay = (float) hourlyRate * hoursWorked; // multiply the hourly rate by the hours worked
// Display output for this iteration
System.out.println(); // outputs a blank line
System.out.print( empName ); // display employee name
System.out.printf( "'s weekly pay is: $%,.2f\n", weeklyPay); // display weekly pay
System.out.println(); // outputs a blank line
}
}
// Display ending message:
System.out.println( "Good-Bye" );
System.out.println(); // outputs a blank line
} // end method main
} // end class Payroll1
E:\IT 215 Java Programming\Payroll Program Part 2.java:7: class, interface, or enum expected
{
^
- 04-30-2009, 11:24 AM #2
Don't give the classname with space.Please go thru sun site for declarations and code code conventions.
Change the classname as "PayrollProgramPart2" and compile.
- 04-30-2009, 11:33 AM #3
Senior Member
- Join Date
- Dec 2008
- Location
- Hong Kong
- Posts
- 473
- Rep Power
- 5
filename and public class name need to be same
and plz use meaningful titleLast edited by mtyoung; 04-30-2009 at 11:57 AM.
- 04-30-2009, 02:19 PM #4
The name of the class can't contain spaces. If you eant to use the above, it should be:Java Code:public class Payroll Program Part 2 {
Luck,Java Code:public class PayrollProgramPart2 {
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 05-28-2009, 05:00 AM #5
Member
- Join Date
- Apr 2009
- Location
- I live Stafford Texas right outside of Houston.
- Posts
- 78
- Rep Power
- 0
- 05-28-2009, 05:03 AM #6
Member
- Join Date
- Apr 2009
- Location
- I live Stafford Texas right outside of Houston.
- Posts
- 78
- Rep Power
- 0


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks