Jump to content

I can't figure out the 2 errors

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
Cassie836

Cassie836

    Newbie

  • Members
  • Pip
  • 5 posts
Create a non-GUI based java application that calculates weekly pay for an employee.?
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


#2
Blmaster

Blmaster

    Learning Programmer

  • Members
  • PipPipPip
  • 50 posts
I did find an error... the char has to be String because you are inputting a lot of characters so change char name to String name!

Edit:
Actually there are some other things i found and i edited it to work. here it is:

// 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 );


String name; // employee's name

double number1; // hourly rate

int number2; // number of hours worked for the week

double 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.nextDouble(); // 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 $" + product ); // displays weekly pay


} // end method main


} // end class Payroll


#3
Cassie836

Cassie836

    Newbie

  • Members
  • Pip
  • 5 posts
I understand, thank you! This is only my second week of the class, I'm trying to read 3 different books and use tutorials to figure it all out! I appreciate the help!!