Reddy001
12-10-2007, 03:13 AM
Khalid,
This is the code I've written so far. This is a payroll program, that ask for input information of employee...name, hourly rate, hours for the week. Once this is input, the program will sum the weekly rate. However, I had to modify the program so that the employee name is equal to stop using a while loop. Here's the program that I've written so far;
//create Scanner to obtain input from command window
Scanner input = new Scanner(System.in);
String name;//employee name
int number1;//first number to multiply
int number2;//second number to multiply
int sum;//product of number1 and number2
while ("Enter Name\n" !="stop")
//employee weekly pay();
System.out.println("Enter Name\n");//prompt employee name
name = input.nextLine();//read employee name
System.out.println("Enter Hourly rate");//prompt hourly rate
number1 = input.nextInt();//read hourly rate
System.out.println("Hours for the Week:");//prompt hours worked for the week
number2 = input.nextInt();//read hours worked
sum = number1 * number2;//multiply numbers
System.out.printf("Sum is %d\n", sum);//display sum
}//end method main
}//end class multiplication
This is the code I've written so far. This is a payroll program, that ask for input information of employee...name, hourly rate, hours for the week. Once this is input, the program will sum the weekly rate. However, I had to modify the program so that the employee name is equal to stop using a while loop. Here's the program that I've written so far;
//create Scanner to obtain input from command window
Scanner input = new Scanner(System.in);
String name;//employee name
int number1;//first number to multiply
int number2;//second number to multiply
int sum;//product of number1 and number2
while ("Enter Name\n" !="stop")
//employee weekly pay();
System.out.println("Enter Name\n");//prompt employee name
name = input.nextLine();//read employee name
System.out.println("Enter Hourly rate");//prompt hourly rate
number1 = input.nextInt();//read hourly rate
System.out.println("Hours for the Week:");//prompt hours worked for the week
number2 = input.nextInt();//read hours worked
sum = number1 * number2;//multiply numbers
System.out.printf("Sum is %d\n", sum);//display sum
}//end method main
}//end class multiplication