/** Modify the Payroll Program so that it uses a class to store and retrieve the employee's
name, the hourly rate, and the number of hours worked. */
/** Program should continue to check the hourly rate and number of hours worked are positive
numbers; if either the hourly rate or the number of hours worked is not a positive value,
then prompt the user to enter a positive value. */
// Use a constructor to initialize the employee information.
// Use a method within the class to calculate the weekly pay.
// Once 'stop' is entered as the employee name, the application should terminate.
import java.util.Scanner; // program uses class Scanner
public class Payroll3
{
// main method begins execution of Java application
public static void main( String args[] )
{
boolean stop = false; // Loop will run as long as 'stop' is not input by user
do
{
// create Scanner to obtain input from Command Prompt window.
Scanner input = new Scanner( System.in );
String nameOfEmployee; // employee's name
double hrlyPay; // first number used to multiply
double hrsWrkd; // second number used to multiply
double product; //product of hrlyPay and hrsWrkd
String Employee;
System.out.print( "\nPlease enter Employee's full name:\n " ); // prompt
nameOfEmployee = input.nextLine(); // read line of text entered by user
if ( nameOfEmployee.toLowerCase().equals( "stop" ) )
{
System.out.print( "You have entered Stop! The program will now terminate.\n" );
System.out.print( "GoodBye!\n" );
stop = true;
}
else
{
System.out.print( "\nPlease enter Employee's full name:\n " ); // prompt
nameOfEmployee = input.nextLine(); // read line of text entered by user
}
System.out.print( "\nEnter your hourly wage:\n$ " ); // prompt
hrlyPay = input.nextDouble(); // read hourly pay input from user
while( hrlyPay < 0 )
{
System.out.print( "\nInvalid entry! Enter positive numbers only.\n" ); // entry error message displayed
System.out.print( "Please enter a valid hourly wage:\n$ " ); // prompt
hrlyPay = input.nextDouble(); // loop until valid hourly wage is input by user
} // end while
System.out.print( "\nEnter hours worked for the week:\n " ); // prompt
hrsWrkd = input.nextDouble(); // read hours worked input from user
while( hrsWrkd < 0 )
{
System.out.print( "\nInvalid entry! Enter positive numbers only.\n" ); // entry error message displayed
System.out.print( "Please enter valid hours worked for the week:\n " ); // prompt
hrsWrkd = input.nextDouble(); // read hours worked input from user
} // end while
Employee employee = new Employee( nameOfEmployee, hrlyPay, hrsWrkd );
System.out.printf( "\n%s\n", nameOfEmployee ); // display employee name
System.out.printf( "Your weekly pay is: $%.2f\n\n", Employee.getName(), Employee.calcWklyPay() ); // Get inputs from Employee class - multiply and display weekly pay.
} while( stop == false );
} // end main
} // end class Payroll3
The two compile errors I receive are:
Payroll3.java:65: cannot find symbol symbol : method getName() location: class java.lang.String System.out.printf( "Your weekly pay is: $%.2f\n\n", Employee.getName(), Employee.calcWklyPay() ); // Get inputs from Employee class - multiply and display weekly pay. ^ Payroll3.java:65: cannot find symbol symbol : method calcWklyPay() location: class java.lang.String System.out.printf( "Your weekly pay is: $%.2f\n\n", Employee.getName(), Employee.calcWklyPay() ); // Get inputs from Employee class - multiply and display weekly pay.
Same line of code...I thought I had the methods for getName() and calcWklyPay() declared in my Class Employee
// Class Employee
public class Employee
{
// private variable containers
private String nameOfEmployee;
private double hrlyPay;
private double hrsWrkd;
// 3 constuctor arguments for creating employee object
public Employee( String Name, double Wage, double Hours )
{
this.nameOfEmployee = Name;
this.hrlyPay = Wage;
this.hrsWrkd = Hours;
}
// Methods for retrieving user input information
public String getName()
{
return this.nameOfEmployee; // read user input; Employee Name
}
public double getWage()
{
return this.hrlyPay; // read user input; Employee Wage
}
public double getHours()
{
return this.hrsWrkd; // read user input; Hours Worked
}
public double calcWklyPay()
{
return this.hrlyPay * hrsWrkd; // calculate and display total weekly pay
}
} // end Class Employee
I have been working on this (after work) for days and I can't seem to figure out what I am missing/overlooking.

New Topic/Question
Reply



MultiQuote




|