PDA

View Full Version : Java question



bornwithnoname
10-21-2008, 02:20 AM
This compiles and runs as expected. The question is Is this the best way to accomplish this task.





import java.util.Scanner; // program uses Scanner


public class WeekTwoCheckPoint {


public static void main(String[] args) {
Scanner input = new Scanner( System.in );

float PayRate;
float HoursWorked;
float GrossPay;



System.out.println( "Please enter employee name:" ); // input employee name
String EmployeeName = input.nextLine();

System.out.println( "Please enter employee pay rate:" ); //input emplyee rate
PayRate = input.nextFloat();

System.out.println( "Please enter hours worked:" ); //input hours worked
HoursWorked = input.nextFloat();

GrossPay = HoursWorked * PayRate; // calculate gross pay

System.out.print( EmployeeName + "'s gross pay is $" ) ; // output results to console
System.out.printf ("%6.2f",GrossPay);
System.out.println(); // insert blank line
System.out.println(); // insert blank line






} // end of method

} // end of class

s_player
10-26-2008, 06:09 PM
Yes, it looks normal, but there is a one problem here - you don't check user input for errors

bornwithnoname
10-26-2008, 07:32 PM
I know that was not part of the assignment, but it is for this week.

torontolimo
10-28-2008, 05:48 PM
yes this looks normal...i will try to complile it...

be back