I'm trying to create a class "WeeklyPay" that contains the methods that class "WeeklyPayT est" will use to compute the weekly pay of an employee when the user inputs employee name, hours worked, and pay rate.
I get an error when trying to compile WeeklyPay.java:
WeeklyPay.java: 78: missing return statement
}//end displayPay
^
Also if anyone sees anything else that's going to give me a problem please tell me about it. Thanks!
here is my code for WeeklyPay.java:
here is my code for WeeklyPayTest:
I get an error when trying to compile WeeklyPay.java:
WeeklyPay.java: 78: missing return statement
}//end displayPay
^
Also if anyone sees anything else that's going to give me a problem please tell me about it. Thanks!
here is my code for WeeklyPay.java:
Code:
// WeeklyPay.java // This program calculates the weekly pay when the user inputs the employee name, rate of pay and hours worked. import java.util.Scanner; public class WeeklyPay { String empName; double hours; double rate; double pay; Scanner input = new Scanner( System.in ); public void enterEmployeeName() { String empName; //employee name entered by user System.out.println(); // prints blank line System.out.println( "Please enter employee name, enter stop to quit:"); empName = input.nextLine(); //read employee name from user System.out.println(); // prints blank line }// end enterEmployeeName public String getName () { return empName; }//end getName public void enterHours() { System.out.printf( "Enter hours worked by %s : ", empName ); //prompt hours = input.nextDouble(); //read hours worked System.out.println(); // prints blank line while ( hours < 0.00 ) // loop if amount is negative { System.out.println(); // prints blank line System.out.println( "Error! Please enter positive number!" ); System.out.printf( "Enter hours worked by %s : ", empName ); //prompt hours = input.nextDouble(); //read hours worked System.out.println(); // prints blank line } // end while }// end enterHours public void enterRate() { System.out.printf( "Enter rate of pay for %s :$", empName ); //prompt rate = input.nextDouble();//read rate of pay System.out.println(); while ( rate < 0.00 ) // loop if amount is negative { System.out.println(); // prints blank line System.out.println( "Error! Please enter a positive number!" ); System.out.printf( "Enter rate of pay for %s :$", empName ); //prompt rate = input.nextDouble();//read rate of pay System.out.println(); } // end while }// end enterRate private void setPay() { pay = rate * hours; }//end setPay public String displayPay() { System.out.printf( "Employee name: %s \nWeekly pay amount: $%.2d", empName, pay); //display name and pay amount System.out.println(); input.nextLine(); }//end displayPay }// end class WeeklyPay
Code:
//WeeklyPayTest.java //Creat and manipulate a WeeklyPay object import java.util.Scanner; //program uses Scanner public class WeeklyPayTest { //main method begins program execution public static void main( String args [] ) { //create Scanner to obtain input Scanner input = new Scanner(System.in ); //create a WeeklyPay object and assign to payroll WeeklyPay payroll = new WeeklyPay(); boolean condition = true while ( condition ) { payroll.enterEmployeeName( input.nextLine()); // call method to input employee name if( ! (payroll.getName().equals("stop"))) { payroll.enterHours( input.nextDouble() ); //call method to input hours worked payroll.enterRate( input.nextDouble() ); // call method to input pay rate payroll.displayPay(); //calls method to display employee name and weekly pay amount }//end if else { condition = false; }//end else }//end while }//end main }//end class WeeklyPayTest
Comment