I am taking an IT course and need help desperately. I have referred to several different resources and am having a hard time grasping OOP. I came across this site and thought I should give it a try. Please bear with me I am new to the site. I am not looking for anyone to give me the answers. I am looking for direction and help to gain a better understanding so that I can proceed. This assignment has already been graded and I was told that my program compile and run fine, but my employee class does not work. I also needed to add a method to the employee class to calculate the weekly pay. I do not understand how to get the employee class to work. Should they be in two separate files (Employee.java and Payroll3.java) or could I have put them in one file? I am also confused when it comes to adding methods. Can someone please help me? I would greatly appreciate any assistance.
import java.util.Scanner; // program uses class Scanner
public class Payroll3
{
// main method starts execution of program execution
public static void main( String args[ ] )
{
boolean stop = false;
while ( !stop )
{
// create Scanner to obtain input from command window
Scanner input = new Scanner( System.in );
System.out.print ( "Enter employee's first and last name or stop to exit program:" );
String empName = input.nextLine(); // read employee's name input by user
if ( empName.equals ( "stop" ) )
{
System.out.println( "Goodbye. Program Terminated." );
stop = true; }
else
{
double hourlyRate; // hourly rate
double weeklyHours; // amount of hours worked for the week
double weeklyPay; // product of hourlyRate and weeklyHours
System.out.print( "Enter employee's hourly rate: " ); // prompt
hourlyRate = input.nextDouble ();
while ( hourlyRate < 0 )
{
System.out.print( "Invalid entry. Enter a positive number: " ); // prompt
hourlyRate = input.nextDouble(); // read hourly rate input by user
}
System.out.print( "Enter number of hours employee worked: " ); // prompt
weeklyHours = input.nextDouble(); // read number of hours worked by the employee input by user
while ( weeklyHours < 0 )
{
System.out.print( "Invalid entry. Enter a positive number:" ); // prompt
weeklyHours = input.nextDouble();
}
weeklyPay = hourlyRate * weeklyHours; // multiply numbers
System.out.println( "Employee:" + empName ); // display employee's name
System.out.printf( "Weekly pay is $" + weeklyPay ); // display weekly total
System.out.println();
}
}
} // end method main
} // end class Payroll3
This is my employee class
public class Employee
{
public static void main( String args[ ] )
{
private String empName;
private double hourlyRate;
private double weeklyHours;
// constructor
public Employee( String name, double rate, double hours )
{
empName = name;
hourlyRate = rate;
weeklyHours = hours;
} // end constructor
public void setEmpName ( String name )
{
empName = name;
}
public String getEmpName()
{
return empName;
}
public void setHourlyRate ( double rate )
{
hourlyRate = rate;
}
public double getHourlyRate()
{
return hourlyRate;
}
public void setWeeklyHours ( double hours )
{
weeklyHours = hours;
}
public double getWeeklyHours()
{
return weeklyHours;
}
// method to calculate weekly pay
public double calculateWeeklyPay;
{
double weeklyPay = hourlyRate * weeklyHours;
}
}
} // end class Employee