If statements and possible Scanner error
807600Oct 19 2007 — edited Oct 20 2007I'm supposed to be creating a program that will calculate weekly pay for an employee after the user inputs the employee's name, pay rate, and hours worked that week. Keep in mind, I really don't understand much of what I'm doing yet (this is only my second assignment). If anyone can find what's wrong and help me adjust it, I would greatly appreciate it.
Here is my code:
// FinalWeek2.java
// Program that calculates weekly pay for an employee
import java.util.Scanner;
public class FinalWeek2
{
public static void main( String args[] )
{
Scanner input = new Scanner( System.in );
int number1; //adds hourly rate
int number2; //adds hours worked
int product; //product of number1 and number2
//Name Input
System.out.print( "Enter name of employee (Type 'stop' when you are done): " );
String nameOfEmployee = input.nextLine();
if ( nameofEmployee = "stop" ){
}
//Pay Input
System.out.print( "Enter pay per hour (Type 'stop' when you are done): " );
number1 = input.nextInt();
if ( number1 < 0 ){
System.out.println( "Please enter a positive number: " );
} else
if ( number1 = "stop" ){
}
//Hours Input
System.out.print( "Enter hours worked (Type 'stop' when you are done): " );
number2 = input.nextInt();
if ( number2 < 0 ){
System.out.println( "Please enter a positive number: " );
} else
if ( number2 = "stop" ){
}
product = number1 * number2;
System.out.println();
System.out.printf( "earned $ %d\n this week", product );
}
}
Here are the errors I'm getting:
C:\j2sdk1.4.2_16\bin>javac FinalWeek2.java
FinalWeek2.java:3: cannot resolve symbol
symbol : class Scanner
location: package util
import java.util.Scanner;
^
FinalWeek2.java:9: cannot resolve symbol
symbol : class Scanner
location: class FinalWeek2
Scanner input = new Scanner( System.in );
^
FinalWeek2.java:9: cannot resolve symbol
symbol : class Scanner
location: class FinalWeek2
Scanner input = new Scanner( System.in );
^
FinalWeek2.java:18: cannot resolve symbol
symbol : variable nameofEmployee
location: class FinalWeek2
if ( nameofEmployee = "stop" ){
^
FinalWeek2.java:27: incompatible types
found : int
required: boolean
if ( number1 = "stop" ){
^
FinalWeek2.java:35: incompatible types
found : int
required: boolean
if ( number2 = "stop" ){
^
FinalWeek2.java:41: cannot resolve symbol
symbol : method printf (java.lang.String,int)
location: class java.io.PrintStream
System.out.printf( "earned $ %d\n this week", product );
^
7 errors