The application should display text that requests user input the name of employee, hourly rate, and number of hours worked for the week. The application should then print out the name of employee and the weekly pay amount. In the printout, display dollar symbol ($) to the left of weekly pay amount and format weekly pay amount to display currency.
// Public class: Payroll.java
// A calculation program that displays an employee's information and hourly rate.
import java.util.Scanner; // program uses class Scanner
public class Payroll
{
// main method begins execution of Java application
public static void main( String args[] )
{
// create Scanner to obtain input from command window
Scanner input = new Scanner( System.in );
char name; // employee's name
int number1; // hourly rate
int number2; // number of hours worked for the week
int product; // product of number1 and number2
System.out.print( "Enter employee's name: " ); // prompt user to input name
name = input.nextLine(); //read employee's name from user's input
System.out.print( "Enter hourly rate: " ); // prompt user for employee's hourly rate
number1 = input.nextInt(); // read hourly rate from user's input
System.out.print( "Enter hours worked for the week: " ); // prompt user to enter number of hours worked for the week
number2 = input.nextInt(); // read number of weeks from user's input
product = number1 * number2; // multiply numbers
System.out.printf( "The Employee" , name ); // displays employee's name
System.out.printf( "weekly pay is $%d\n" , product ); // displays weekly pay
} // end method main
} // end class Payroll
When I run it, this is what it says and I don't know enough to know what it means!
init:
deps-jar:
Compiling 1 source file to C:\Documents and Settings\Cassie\My Documents\NetBeansProjects\JavaApplication2\build\classes
C:\Documents and Settings\Cassie\My Documents\NetBeansProjects\JavaApplication2\src\javaapplication2\Main.java:6: class Payroll is public, should be declared in a file named Payroll.java
public class Payroll
C:\Documents and Settings\Cassie\My Documents\NetBeansProjects\JavaApplication2\src\javaapplication2\Main.java:21: incompatible types
found : java.lang.String
required: char
name = input.nextLine(); //read employee's name from user's input
^
2 errors
BUILD FAILED (total time: 0 seconds)
Edited by WingedPanther, 18 August 2008 - 07:32 AM.
add code tags


Sign In
Create Account

Back to top









