I'm trying to create a class "WeeklyPay" that contains the methods that class "WeeklyPayTest" 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: - // 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
here is my code for WeeklyPayTest: - //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
8 1830
I'm trying to create a class "WeeklyPay" that contains the methods that class "WeeklyPayTest" 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: - 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
-
You declare the return type of that method as a String; nowhere in that little
method do you return a String; that's why the compiler is whining at you.
kind regards,
Jos
I'm trying to create a class "WeeklyPay" that contains the methods that class "WeeklyPayTest" 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: - // 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
here is my code for WeeklyPayTest: - //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
Your displayPay method signature says that it returns a String but it does not do that. The compiler therefore has to complain.
In your employeeName() method your create a local String empName; that one
will be set and your member variable with the same name will still remain null.
kind regards,
Jos
Thanks!
Now my problem is that when I run WeeklyPayTest it won't calculate my hours and rate. It keeps returning $0.00 no matter what amounts I enter:
C:\Documents and Settings\Sam>java WeeklyPayTest Please enter employee name, enter stop to quit: Sam
Enter hours worked by Sam : 45
Enter rate of pay for Sam :$45
Employee name: Sam
Weekly pay amount: $0.00
Please enter employee name, enter stop to quit: stop
C:\Documents and Settings\Sam>
What do I need to do to get it to work like I need it to? - // 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 employeeName()
-
{
-
-
System.out.println(); // prints blank line
-
System.out.printf( "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 hours()
-
{
-
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 hours
-
-
public void rate()
-
{
-
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 rate
-
-
public void setPay()
-
{
-
pay = rate * hours; //calculate pay by multiplying hours and rate
-
-
}//end setPay
-
-
public double getPay()
-
{
-
return pay;
-
-
}// end getPay
-
-
-
public void displayPay()
-
{
-
System.out.printf( "Employee name: %s \nWeekly pay amount: $%.2f", empName, getPay() ); //display name and pay amount
-
System.out.println();
-
input.nextLine();
-
-
}//end displayPay
-
-
}// end class WeeklyPay
- //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.employeeName(); // call method to input employee name
-
-
if( ! (payroll.getName().equals("stop")))
-
{
-
payroll.hours(); //call method to input hours worked
-
payroll.rate(); // 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
I never see your setPay() method being called anywhere in your code. That
method calculates the amount of money to be paid. Or maybe I'm just blind ;-)
kind regards,
Jos
sweet! I overlooked that. Now it works perfectly! Thanks for helping this java newbie out. I appreciate it.
sweet! I overlooked that. Now it works perfectly! Thanks for helping this java newbie out. I appreciate it.
Thanks; no problem; we're nice folks here actually as long as one shows that
s/he's been trying to solve some problem(s) him/herself first.If one gets stuck
then we'll help you out. OTOH if one is just too lazy to put some effort in at first,
we (read: I) are/am too lazy too to do any homework for others at all ;-)
You showed that you've put in a lot of work in it yourself so we'll help you out.
Have fun studying the Java programming language.
kind regards,
Jos
Sign in to post your reply or Sign up for a free account.
Similar topics
by: shank |
last post by:
1) I'm getting this error: Syntax error (missing operator) in query
expression on the below statement. Can I get some advice.
2) I searched ASPFAQ and came up blank. Where can find the "rules"...
|
by: Sonoman |
last post by:
Hi all:
I am getting a "missing storage class or idetifier" error and I do not
understand what it means, therefore and I cannot figure it out. I am just
starting a new project and I cannot get...
|
by: Junior |
last post by:
I keep receiving this "The type or namespace name 'CASsEventHandler' could
not be found (are you missing a using directive or an assembly reference?)"
message in two particular lines, and I've...
|
by: soup_or_power |
last post by:
I'm passing the return from window.open as a function argument and
getting the error "missing ] after element list" when tested with
FireFox. Here is the relevant code. Many thanks for your help....
|
by: Jigar.Patel |
last post by:
I have simple remoting server exposing following simple method. When I try to
add webreference to this server in another project by serveraddresss?wsdl,
it gives me following error:
Custom tool...
|
by: Jigar.Patel |
last post by:
I have simple remoting server exposing following simple method. When I try to
add webreference to this server in another project,
it gives me following error:
Custom tool error: Unable to import...
|
by: Fred Chateau |
last post by:
Still working on my XML DataSet...
Having moved on past difficult and complex problems, resolved with the
assistance of everyone here, I find myself facing yet another problem. My
XML document...
|
by: honguin |
last post by:
Hi,
With the following code, I have created a web request to a url which I
am making a HTML POST with the html page request.htm, even though it
makes a HTML POST, the StreamReader produces a XML...
|
by: im2cre8iv |
last post by:
Here is my code where I am receiving the error:
#include <fstream>
#include "BinaryTree.h"
using namespace std;
Node* BinaryTree::MakeTree(ifstream& infile)
{
char name;
infile>>name;
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |