Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-03-2007, 09:57 PM
Member
 
Join Date: Nov 2007
Posts: 8
badness is on a distinguished road
Beginner; Create a class to store info and constructor to initialize
Hey everyone. I love that this forum exists and we can learn from one another. At this point I am the one doing all of the learning, but I will someday be able to return the favor for other beginners.

I need a little help. My time, of late, is very limited for my studying of Java and I am saddened by this because I am interested in learning more. I have a project I need to submit for school and I thought I could enlist some help in gaining understanding of how to do it.

I have a payroll program:

import java.util.Scanner;

public class Payroll3
{
public static void main( String[] args )
{
Scanner input = new Scanner( System.in );

boolean enterMoreData = true;
while(enterMoreData)
{
System.out.print ( "Enter employee name: " );
String theName = input.nextLine();
if(theName.equalsIgnoreCase("stop"))
{
input.close();
break;
}

int hoursWorked;
do
{
System.out.println("Enter hours worked: ");
String line = input.nextLine();
hoursWorked = Integer.parseInt(line);
if(hoursWorked < 0)
System.out.println("number must be positive");
}
while(hoursWorked < 0);

int hourlyPayRate;
do
{
System.out.println("Enter hourly pay rate: ");
String line = input.nextLine();
hourlyPayRate = Integer.parseInt(line);
if(hourlyPayRate < 0)
System.out.println("number must be positive");
}
while(hourlyPayRate < 0);

// multiply hours worked * hourly pay rate
int weeklyPay = hoursWorked * hourlyPayRate;

// display employee name and weekly pay total
System.out.printf( "Employee Name: %s, Weekly pay is $%d%n",
theName, weeklyPay );
}
}
}


I got help from some of you to get this far and I learned a lot. Thanks to those who helped. Now I need to modify the program for these requirements:

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. Use a constructor to initialize the
employee information, and a method within that class to calculate the weekly pay. Once
stop is entered as the employee name, the application should terminate.


I am unsure of how to put a class in that will store this info until called upon by the constructor. I will be doing some reading this afternoon trying to find this in my text, I am not just being lazy. I would, though appreciate any help and explanations that you may offer. I really do appreciate this.

Badness
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-03-2007, 10:37 PM
Senior Member
 
Join Date: Jul 2007
Posts: 910
hardwired is on a distinguished road
Code:
import java.util.Scanner; public class PayrollRx { public static void main( String[] args ) { Scanner input = new Scanner( System.in ); boolean enterMoreData = true; while(enterMoreData) { System.out.print ( "Enter employee name: " ); String theName = input.nextLine(); if(theName.equalsIgnoreCase("stop")) { input.close(); break; } int hoursWorked; do { System.out.println("Enter hours worked: "); String line = input.nextLine(); hoursWorked = Integer.parseInt(line); if(hoursWorked < 0) System.out.println("number must be positive"); } while(hoursWorked < 0); int hourlyPayRate; do { System.out.println("Enter hourly pay rate: "); String line = input.nextLine(); hourlyPayRate = Integer.parseInt(line); if(hourlyPayRate < 0) System.out.println("number must be positive"); } while(hourlyPayRate < 0); Employee employee = new Employee(theName, hoursWorked, hourlyPayRate); System.out.printf( "Employee Name: %s, Weekly pay is $%d%n", employee.name, employee.getWeeklyPay() ); } } } class Employee { String name; int hours; int hourlyPayRate; int weeklyPay; public Employee(String name, int hours, int rate) { this.name = name; this.hours = hours; hourlyPayRate = rate; computeWeeklyPay(); } private void computeWeeklyPay() { weeklyPay = hours * hourlyPayRate; } public int getWeeklyPay() { return weeklyPay; } }
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 05-06-2008, 10:42 PM
Member
 
Join Date: May 2008
Location: Ohio
Posts: 11
Azzia is on a distinguished road
Send a message via AIM to Azzia Send a message via MSN to Azzia
Hello,

I know this is an old post and sorry to bring it back to life but I have the same exact assignment. I read through your code, hardwired, and it seems I have made mine work in a different way. I understand a little able what you have done above but not enough to be able to implement it into my code. Without adding the code, can you explain a little bit or point me in the correct direction as to where I can understand better on where the constructors would appear and/or how to create a class to store the information?

Code:
import java.util.Scanner; public class Main { double rate; double hours; String Empname; // main method begins execution of Java application public static void main(String args[]) { boolean stop = false; // controls if loop below is executed while (!stop) { // create Scanner to obtain input from command window Scanner input = new Scanner(System.in); System.out.print("Enter employee's name or stop to quit: "); // prompt for name String EmpName = input.nextLine(); // read employee's name entered if (EmpName.equals("stop")) { System.out.println("This program has ended successfully."); stop = true; } else { double PayRate; // First number multiplied double HoursWorked; // Second number multiplied double total; // Total of PayRate * HoursWorked System.out.print("Enter the pay rate per hour of the employee: "); // prompt for rate PayRate = input.nextDouble(); // read payrate of employee while (PayRate <= 0) // Validate for positive number { System.out.println(); System.out.println("Pay rate must be a positve number. "); System.out.print("Please enter pay rate per hour again: "); PayRate = input.nextDouble(); System.out.println(); } System.out.print("Enter the employee's hours worked this pay week: "); // prompt for Hours HoursWorked = input.nextDouble(); while (HoursWorked <= 0) // validate for positive number { System.out.println(); System.out .println("Hours worked must be a positive number. "); System.out.print("Please enter hours worked this pay week again: "); HoursWorked = input.nextDouble(); //read hourly rate of pay System.out.println(); } total = (double) PayRate * HoursWorked; // Multiply PayRate by HoursWorked System.out.println(); System.out.println("Employee: " + EmpName); //display name System.out.println("Number of hours worked this pay week: " + HoursWorked); //display hours worked System.out.printf("Employee's Pay: $%,.2f\n", total); //display pay rate System.out.println(); System.out.println(); } // end else } //end while } // end main } // end class

Last edited by Azzia : 05-06-2008 at 10:45 PM.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 05-07-2008, 06:19 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 1,136
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Are you looking complete explanation for the complete code? Best things is asked question by steps, where you stuck with. Then you can found the best solution for it.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Want to make your IDE the best?Vote Now
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 05-07-2008, 06:35 PM
Member
 
Join Date: May 2008
Location: Ohio
Posts: 11
Azzia is on a distinguished road
Send a message via AIM to Azzia Send a message via MSN to Azzia
Code:
Employee employee = new Employee(theName, hoursWorked, hourlyPayRate); System.out.printf( "Employee Name: %s, Weekly pay is $%d%n", employee.name, employee.getWeeklyPay() ); } } } class Employee { String name; int hours; int hourlyPayRate; int weeklyPay; public Employee(String name, int hours, int rate) { this.name = name; this.hours = hours; hourlyPayRate = rate; computeWeeklyPay(); } private void computeWeeklyPay() { weeklyPay = hours * hourlyPayRate; } public int getWeeklyPay() { return weeklyPay; } }
This is the part I am unsure about. I have created the class but when I try and implement the constructor in my above code it will not work. The error is about variables but the variables I have used are declared in my code which again makes no sense to me.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 05-07-2008, 08:03 PM
Senior Member
 
Join Date: Jul 2007
Posts: 910
hardwired is on a distinguished road
Looking at your Main class you declare three variables of (the primitive data) type double.
Code:
double PayRate; // First number multiplied double HoursWorked; // Second number multiplied double total; // Total of PayRate * HoursWorked ... PayRate = input.nextDouble(); ... HoursWorked = input.nextDouble(); ... total = (double) PayRate * HoursWorked; // Create an instance of Employee with this data: Employee employee = new Employee(PayRate, HoursWorked, total);
For this to work your Employee class must have a constructor that accepts three double arguments, viz,
Code:
class Employee { ... public Employee(double arg1, double arg2, double arg3) { ... } ... }
If java cannot find such a constructor in the Employee class it will give a compile error saying it cannot find a constructor with this signature.
So you would want to design your Employee (or whatever name you choose to give it) class to match your Main class data that you are collecting, computing and want to save (in the Employee class).
Code:
class Employee { double payRate; double hours; double total; Employee(double payRate, double hours, double total) { this.payRate = payRate; this.hours = hours; this.total = toal; } ... }
The argument types must match up. Java is very prissy about type matching. It all seems silly in the beginning but it's a way to make everything clear and easy to read and understand.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 05-07-2008, 08:29 PM
Member
 
Join Date: May 2008
Location: Ohio
Posts: 11
Azzia is on a distinguished road
Send a message via AIM to Azzia Send a message via MSN to Azzia
Oh wow. Well that explains a lot that the text book doesnt cover. When explaining floats and doubles, the text just says when to use them and why. Looking though it now, it never mentions that classes won't be compatible if their type isn't the same.

I am still having an issue though. I declared the string "empName" but when I use the constructor it is still giving me an error. Here is a copy of how I implemented your code into mine to see how it worked. (I also tried several different approaches by changing some things but each seem to bite the dust.)


Code:
Employee employee = new Employee ( empName, hoursWorked, payRate); System.out.printf( "Employee Name: %s, Weekly pay is $%d%n", employee.empName, employee.getWeeklyPay() ); // total = (double) PayRate * HoursWorked; // Multiply PayRate by HoursWorked // System.out.println(); // System.out.println("Employee: " + empName); //display name // System.out.println("Number of hours worked this pay week: " + HoursWorked); //display hours worked // System.out.printf("Employee's Pay: $%,.2f\n", total); //display pay rate // System.out.println(); // System.out.println(); } // end else } //end while } // end main } // end class

Last edited by Azzia : 05-07-2008 at 08:36 PM.
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 05-07-2008, 08:43 PM
Senior Member
 
Join Date: Jul 2007
Posts: 910
hardwired is on a distinguished road
Code:
String Empname; double PayRate; double HoursWorked; double total; ... // Create an instance of Employee with this data: Employee employee = new Employee(Empname, hoursWorked, payRate);
Java will look for a constructor in Employee that matches this type signature:
Code:
class Employee { ... public Employee(String arg1, double arg2, double arg3) { ... } ... }
Your Employee class can look like this:
Code:
class Employee { String name; double payRate; double hours; double total; Employee(String name, double payRate, double hours) { this.name = name this.payRate = payRate; this.hours = hours; } ... }
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 05-07-2008, 08:45 PM
Member
 
Join Date: May 2008
Location: Ohio
Posts: 11
Azzia is on a distinguished road
Send a message via AIM to Azzia Send a message via MSN to Azzia
This seems to be my issue right now. (I have changed things around and added new things but seems I am just making it worse)

Code:
Employee employee = new employee ( empName, hoursWorked, payRate);
It is a symbol error. I am going to research a little more to see if I can find the issue. Here is the rest of the code.

Code:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package payrollprogram; /** * * @author MKAY */ import java.util.Scanner; public class Main { String empName; double payRate; double hoursWorked; // main method begins execution of Java application public void main(String args[]) { boolean stop = false; // controls if loop below is executed while (!stop) { // create Scanner to obtain input from command window Scanner input = new Scanner(System.in); System.out.print("Enter employee's name or stop to quit: "); // prompt for name String EmpName = input.nextLine(); // read employee's name entered if (EmpName.equals("stop")) { System.out.println("This program has ended successfully."); stop = true; input.close(); break; } else { double PayRate; // First number multiplied double HoursWorked; // Second number multiplied double total; // Total of PayRate * HoursWorked System.out.print("Enter the pay rate per hour of the employee: "); // prompt for rate PayRate = input.nextDouble(); // read payrate of employee while (PayRate <= 0) // Validate for positive number { System.out.println(); System.out.println("Pay rate must be a positve number. "); System.out.print("Please enter pay rate per hour again: "); PayRate = input.nextDouble(); System.out.println(); } System.out.print("Enter the employee's hours worked this pay week: "); // prompt for Hours HoursWorked = input.nextDouble(); while (HoursWorked <= 0) // validate for positive number { System.out.println(); System.out .println("Hours worked must be a positive number. "); System.out.print("Please enter hours worked this pay week again: "); HoursWorked = input.nextDouble(); //read hourly rate of pay System.out.println(); } Employee employee = new employee ( empName, hoursWorked, payRate); System.out.printf( "Employee Name: %s, Weekly pay is $%d%n", employee.empName, employee.getWeeklyPay() ); // total = (double) PayRate * HoursWorked; // Multiply PayRate by HoursWorked // System.out.println(); // System.out.println("Employee: " + EmpName); //display name // System.out.println("Number of hours worked this pay week: " + HoursWorked); //display hours worked // System.out.printf("Employee's Pay: $%,.2f\n", total); //display pay rate // System.out.println(); // System.out.println(); } // end else } //end while } // end main } // end class class Employee { String empName; double hoursWorked; double payRate; double total; public void Employee (String name, double hours, double rate){ this.empName = name; this.hoursWorked = hours; this.payRate = rate; computeWeeklyPay(); } private void computeWeeklyPay() { total = (double) hoursWorked * (double) payRate; } public double getWeeklyPay(){ return total; } }
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 05-07-2008, 09:11 PM
Senior Member
 
Join Date: Jul 2007
Posts: 910
hardwired is on a distinguished road
Typo:
Code:
// Change this Employee employee = new employee ( empName, hoursWorked, payRate); // to this Employee employee = new Employee ( empName, hoursWorked, payRate);
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 05-07-2008, 09:15 PM
Member
 
Join Date: May 2008
Location: Ohio
Posts: 11
Azzia is on a distinguished road
Send a message via AIM to Azzia Send a message via MSN to Azzia
Code:
public void Employee (String name, double hours, double rate){ this.empName = name; this.hoursWorked = hours; this.payRate = rate; computeWeeklyPay();
Got it. Not sure what I was thinking. Thanks a lot for your help! I am sure ill be needing you again soon!
Bookmark Post in Technorati
Reply With Quote
  #12 (permalink)  
Old 05-08-2008, 12:30 AM
Member
 
Join Date: May 2008
Location: Ohio
Posts: 11
Azzia is on a distinguished road
Send a message via AIM to Azzia Send a message via MSN to Azzia
Alright, well I thought I had it all good and corrected but then it was giving me an error of <no main class found>. So, I went back through and edited it some mroe and got it to where there were no errors BUT the program wouldnt run, it just told me build successful and thats it. So, I played around again with it and now I am back to square one. Here is my whole source code. I am at my end with this.

Code:
import java.util.Scanner; public class Main { // main method begins execution of Java application public static void Main(String empName, double hoursWorked, double payRate, double total) { boolean stop = false; // controls if loop below is executed while (!stop) { // create Scanner to obtain input from command window Scanner input = new Scanner(System.in); System.out.print("Enter employee's name or stop to quit: "); // prompt for name String EmpName = input.nextLine(); // read employee's name entered if (EmpName.equals("stop")) { System.out.println("This program has ended successfully."); stop = true; input.close(); break; } else { double PayRate; // First number multiplied double HoursWorked; // Second number multiplied //double total; // Total of PayRate * HoursWorked System.out.print("Enter the pay rate per hour of the employee: "); // prompt for rate PayRate = input.nextDouble(); // read payrate of employee while (PayRate <= 0) // Validate for positive number { System.out.println(); System.out.println("Pay rate must be a positve number. "); System.out.print("Please enter pay rate per hour again: "); PayRate = input.nextDouble(); System.out.println(); } System.out.print("Enter the employee's hours worked this pay week: "); // prompt for Hours HoursWorked = input.nextDouble(); while (HoursWorked <= 0) // validate for positive number { System.out.println(); System.out .println("Hours worked must be a positive number. "); System.out.print("Please enter hours worked this pay week again: "); HoursWorked = input.nextDouble(); //read hourly rate of pay System.out.println(); } //Employee employee = new Employee(); Employee employee = new Employee(empName, hoursWorked, payRate, total); System.out.printf( "Employee Name: %s, Weekly pay is $%d%n", employee.empName, employee.getWeeklyPay() ); // total = (double) PayRate * HoursWorked; // Multiply PayRate by HoursWorked System.out.println(); // System.out.println("Employee: " + EmpName); //display name // System.out.println("Number of hours worked this pay week: " + HoursWorked); //display hours worked // System.out.printf("Employee's Pay: $%,.2f\n", total); //display pay rate System.out.println(); System.out.println(); } // end else } //end while } // end main } // end class class Employee { public String empName; double hoursWorked; double payRate; double total; public Employee(String name, double hours, double rate) { this.empName = name; this.hoursWorked = hours; this.payRate = rate; computeWeeklyPay(); } private void computeWeeklyPay() { total = (double) hoursWorked * (double) payRate; } public double getWeeklyPay(){ return total; } }
Bookmark Post in Technorati
Reply With Quote
  #13 (permalink)  
Old 05-08-2008, 06:58 AM
Senior Member
 
Join Date: Jul 2007
Posts: 910
hardwired is on a distinguished road
Code:
// change this public static void Main(String empName, double hoursWorked, double payRate, double total) // to this public static void main() ... // To get your class to work with these two statements Employee employee = new Employee(); Employee employee = new Employee(empName, hoursWorked, payRate, total); // you would have to add more constructors: class Employee { public String empName; double hoursWorked; double payRate; double total; public Employee() { this(null, 0.0, 0.0); } public Employee(String name, double hours, double rate) { this(name, hours, rate, 0.0); computeWeeklyPay(); } public Employee(String name, double hours, double rate, double total) { this.empName = name; this.hoursWorked = hours; this.payRate = rate; this.total = total; } ...
or you could change the constructor in the Main class to
Code:
Employee employee = new Employee(empName, hoursWorked, payRate);
and call computeWeeklyPay() in the Employee constructor to calculate total as you had it.

Last edited by hardwired : 05-08-2008 at 07:13 AM. Reason: more to say after a second look
Bookmark Post in Technorati
Reply With Quote
  #14 (permalink)  
Old 05-08-2008, 08:24 PM
Member
 
Join Date: May 2008
Location: Ohio
Posts: 11
Azzia is on a distinguished road
Send a message via AIM to Azzia Send a message via MSN to Azzia
I apologize for this all in advance. I am at the point where I have messed with it so much that its all a big mumbo jumbo in my head. I am going to read up a little more on contructors cause that seems to be my issue. I can't seem to get away from this error and its irritating.

Code:
symbol : constructor Employee(java.lang.String,double,double[],double) location: class payrollprogram.Employee Employee employee = new Employee(empName, hoursWorked, payRate, total); 1 error BUILD FAILED (total time: 0 seconds)
I will let you know what I figure out.
Bookmark Post in Technorati
Reply With Quote
  #15 (permalink)  
Old 05-08-2008, 09:22 PM
Member
 
Join Date: May 2008
Location: Ohio
Posts: 11
Azzia is on a distinguished road
Send a message via AIM to Azzia Send a message via MSN to Azzia
Well, I am laughing now.
My compiler is messed up and I have to completely make a whole new package cause the error just wouldn't budge.

Well, the program compiles and runs...

Code:
/* import java.util.Scanner; public class Main { double rate; double hours; String Empname; // main method begins execution of Java application public static void main( String [] args) { boolean stop = false; // controls if loop below is executed while (!stop) { // create Scanner to obtain input from command window Scanner input = new Scanner(System.in); System.out.print("Enter employee's name or stop to quit: "); // prompt for name String EmpName = input.nextLine(); // read employee's name entered if (EmpName.equals("stop")) { System.out.println("This program has ended successfully."); stop = true; input.close(); break; } else { double PayRate; // First number multiplied double HoursWorked; // Second number multiplied double total; // Total of PayRate * HoursWorked System.out.print("Enter the pay rate per hour of the employee: "); // prompt for rate PayRate = input.nextDouble(); // read payrate of employee while (PayRate <= 0) // Validate for positive number { System.out.println(); System.out.println("Pay rate must be a positve number. "); System.out.print("Please enter pay rate per hour again: "); PayRate = input.nextDouble(); System.out.println(); } System.out.print("Enter the employee's hours worked this pay week: "); // prompt for Hours HoursWorked = input.nextDouble(); while (HoursWorked <= 0) // validate for positive number { System.out.println(); System.out .println("Hours worked must be a positive number. "); System.out.print("Please enter hours worked this pay week again: "); HoursWorked = input.nextDouble(); //read hourly rate of pay System.out.println(); } Employee employee = new Employee (); System.out.printf( "Employee Name: %s, Weekly pay is $%,.2f", employee.empName, employee.getWeeklyPay() ); // total = (double) PayRate * HoursWorked; // Multiply PayRate by HoursWorked System.out.println(); // System.out.println("Employee: " + EmpName); //display name // System.out.println("Number of hours worked this pay week: " + HoursWorked); //display hours worked // System.out.printf("Employee's Pay: $%,.2f", total); //display pay rate System.out.println(); System.out.println(); } // end else } //end while } // end main } // end class class Employee { String empName; double hoursWorked; double payRate; double total; public void Employee (String name, double hours, double rate) { this.empName = name; this.hoursWorked = hours; payRate = rate; computeWeeklyPay(); } private void computeWeeklyPay() { total = hoursWorked * payRate; } public double getWeeklyPay() { return total; } }

but now... dun dun dun...

"Employee Name: null, Weekly pay is $0.00


Enter employee's name or stop to quit: "

Last edited by Azzia : 05-08-2008 at 09:27 PM.
Bookmark Post in Technorati
Reply With Quote
  #16 (permalink)  
Old 05-08-2008, 10:03 PM
Senior Member
 
Join Date: Jul 2007
Posts: 910
hardwired is on a distinguished road
Code:
C:\jexp>javac employeetest2.java employeetest2.java:57: cannot find symbol symbol : constructor Employee2() location: class Employee2 Employee2 employee = new Employee2(); ^ 1 error
There is no explicit constructor declared in the Employee2 class so the jvm calls the default class constructor which the jvm gives to any class without a constructor.
Code:
// This is a method with a void return type, ie, the method // does not return anything to the caller. public void Employee2(String name, double hours, double rate) // This is a constructor: a special method that does not have a // return type int its declaration and whose name is the same as // its enclosing class. public Employee2(String name, double hours, double rate)
For more on constructors see Providing Constructors for Your Classes.
Works okay now:
Code:
import java.util.Scanner; public class EmployeeTest2 { public static void main( String[] args) { boolean stop = false; while (!stop) { Scanner input = new Scanner(System.in); System.out.print("Enter employee's name or stop to quit: "); String EmpName = input.nextLine(); if (EmpName.equals("stop")) { System.out.println("This program has ended successfully."); stop = true; input.close(); break; } else { double PayRate; double HoursWorked; double total; System.out.print("Enter the pay rate per hour of " + "the employee: "); PayRate = input.nextDouble(); while (PayRate <= 0) { System.out.println(); System.out.println("Pay rate must be a positve number. "); System.out.print("Please enter pay rate per hour again: "); PayRate = input.nextDouble(); System.out.println(); } System.out.print("Enter the employee's hours " + "worked this pay week: "); HoursWorked = input.nextDouble(); while (HoursWorked <= 0) { System.out.println(); System.out.println("Hours worked must be a " + "positive number. "); System.out.print("Please enter hours worked " + "this pay week again: "); HoursWorked = input.nextDouble(); System.out.println(); } Employee2 employee = new Employee2(EmpName, PayRate, HoursWorked); System.out.printf( "Employee Name: %s, Weekly pay is $%,.2f%n", employee.empName, employee.getWeeklyPay() ); } } } } class Employee2 { String empName; double hoursWorked; double payRate; double total; public Employee2(String name, double hours, double rate) { this.empName = name; this.hoursWorked = hours; payRate = rate; computeWeeklyPay(); } private void computeWe