1 Replies - 310 Views - Last Post: 24 April 2010 - 07:32 AM Rate Topic: -----

#1 andoiscool  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 29-October 09

Trouble with methods

Posted 24 April 2010 - 07:22 AM

I'm having sooo much trouble getting this method to work. I know I'm doing something wrong but not sure what.
Thank you for any help!


/** This Program uses the J option pane to calculate wages and overtime */
import javax.swing.JOptionPane;
import java.text.NumberFormat;

public class wageCalculator  {   
   
   
   
   	// global variables for storing user input and output
   double hoursWorked, hourlyWage;            // inputs from user
   double wages, overtimePay, federalTaxes, takeHomePay;    // calculated outputs to be displayed
   int TAX_RATE = 0.15;
     
      JOptionPane.showMessageDialog(null, "Wage Calculator by AW computes weekly wages\nIt includes overtime pay");
    
    public static void main( String args[] )   {
    	do {
        getInput(); 
        
        
        
  } while calculatePay();
  
  output();
   
   } // end method main
   

     public static void getInput(){
       	  
          String input;   // text input which must be converted to numeric form
          input = JOptionPane.showInputDialog(null,"Enter Hours worked this week:" );
          hoursWorked = Double.parseDouble(input);	
           
          input = JOptionPane.showInputDialog(null,"Enter hourly rate: ");
          hourlyRate = Double.parseDouble(input);      	
     } // end getInput


       
     

     public static void calculatePay(){
       // determine total wages
      if ( hoursWorked <= 40 ) {   
           // no overtime
           	wages = hoursWorked * hourlyRate;
           	overtimePay = 0;
           	federalTax = wages * TAX_RATE; //Taxed at 15%
           	takehomePay = wages - federalTax; //After taxes
      } else   {     
          // overtime involved    
          	wages = 40 * hourlyRate; // for 1st 40 hours
          	overtimeHours = hoursWorked - 40;
          	overtimePay = overtimeHours * ( 1.5 * hourlyRate);   // @ 1.5 regular rate
          	wages +=   overtimePay;     // add overtimePay to wages
          	federalTax = wages * TAX_RATE; //Taxed at 15%
          	takehomePay = wages - federalTax; //After taxes 	  
      }      	
     } // end calculatePay



     
      
      public static void output(){
       // display wages using formatting        
       NumberFormat money = NumberFormat.getCurrencyInstance() ;
       
       String output =  "Hours worked: " + hoursWorked +
       	                "  Hourly Rate: " + money.format (hourlyRate) +
       	                "\nTotal Wages: " + money.format(wages) + 
       	                "\nOvertime Pay: " +   money.format(overtimePay) + 
       	                "\nFederal Tax: " +   money.format(federalTax) +
       	                "\nTake Home Pay: " +   money.format(takehomePay) ;    	  
      
       JOptionPane.showMessageDialog(null,  output); //Displays final totals
      }  
  

} // end class WageCalculator




Is This A Good Question/Topic? 0
  • +

Replies To: Trouble with methods

#2 mostyfriedman  Icon User is offline

  • The Algorithmi
  • member icon

Reputation: 727
  • View blog
  • Posts: 4,473
  • Joined: 24-October 08

Re: Trouble with methods

Posted 24 April 2010 - 07:32 AM

which method exactly?, and what is the method supposed to be doing?, and what is it doing now?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1