Your Ad Here Your Ad Here
Results 1 to 4 of 4

Thread: Java question

  1. #1
    bornwithnoname's Avatar Bit Master BT Rep: +1
    Join Date
    Sep 2006
    Location
    USA
    Posts
    368
    This compiles and runs as expected. The question is Is this the best way to accomplish this task.


    Code:
    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

    I'll be more enthusiastic about encouraging thinking outside the box when there's evidence of any thinking going on inside it. (Terry Prattchet)

  2. Internet, Programming and Graphics   -   #2
    Yes, it looks normal, but there is a one problem here - you don't check user input for errors

  3. Internet, Programming and Graphics   -   #3
    bornwithnoname's Avatar Bit Master BT Rep: +1
    Join Date
    Sep 2006
    Location
    USA
    Posts
    368
    I know that was not part of the assignment, but it is for this week.

    I'll be more enthusiastic about encouraging thinking outside the box when there's evidence of any thinking going on inside it. (Terry Prattchet)

  4. Internet, Programming and Graphics   -   #4
    yes this looks normal...i will try to complile it...

    be back

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •