I'm currently writing a program that should read through a text file, create an array of different types of employees (each have their own subclass), then print out the information in a different format. I think I've got most of it working, but whenever I try to actually create the objects (at least I think that's what it is?), I'm getting a "Constructor is undefined" error. This is happening on all 7 of these objects. I will simply post one here (along with its subclass) so that you guys aren't overloaded with information, and hopefully I can figure out the rest from that.
Thanks for any help you can provide!
Driver class where I'm reading and creating objects (did not include the rest of the code following this)
Error occurs at the "Emp[0]" line
import java.io.File;
import java.util.Scanner;
public class PayrollSystemTest2 {
/**
* #param args
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
Scanner input;
input = new Scanner(new File("EmployeePayrollInfo.txt"));
Employee[] Emp = new Employee[20];
while(input.hasNext())
{
String ID = input.nextLine();
if (ID.charAt(0) == 'S')
{
String first = input.nextLine();
String last = input.nextLine();
String ssn = input.nextLine();
Date DayOfBirth = new Date(input.nextInt(),input.nextInt(),input.nextInt());
double salary = input.nextDouble();
Emp[0] = new SalariedEmployee(first, last, ssn, DayOfBirth, ID);
}
SalariedEmployee subclass
public class SalariedEmployee extends Employee
{
private double weeklySalary;
// four-argument constructor
public SalariedEmployee( String first, String last, String ssn, Date DayOfBirth, String ID,
double salary )
{
super( first, last, ssn, DayOfBirth, ID); // pass to Employee constructor
setWeeklySalary( salary ); // validate and store salary
} // end four-argument SalariedEmployee constructor
// set salary
public void setWeeklySalary( double salary )
{
double baseSalary;
if ( salary >= 0.0 )
baseSalary = salary;
else
throw new IllegalArgumentException(
"Weekly salary must be >= 0.0" );
} // end method setWeeklySalary
// return salary
public double getWeeklySalary()
{
return weeklySalary;
} // end method getWeeklySalary
// calculate earnings; override abstract method earnings in Employee
#Override
public double earnings()
{
return getWeeklySalary();
} // end method earnings
// return String representation of SalariedEmployee object
#Override
public String toString()
{
return String.format( "salaried employee: %s\n%s: $%,.2f",
super.toString(), "weekly salary", getWeeklySalary() );
} // end method toString
} // end class SalariedEmployee
Again, thanks for any help you can provide.
Well yes - look at your constructor, including the clearly-inaccurate comment:
// four-argument constructor
public SalariedEmployee(String first, String last, String ssn, Date DayOfBirth,
String ID, double salary)
Note how there are 6 parameters. Now here's how you're trying to call it:
Emp[0] = new SalariedEmployee(first, last, ssn, DayOfBirth, ID);
You're passing in 5 arguments. What happened to the salary?
As side notes:
Java variables are conventionally camelCased - so dayOfBirth and id rather than DayOfBirth and ID
Using double for financial values such as a salary is a bad idea. Use BigDecimal or keep an integer number of cents. (That's assuming you even need it down to the cent...)
Related
I have the class "1". In that class I defined the variables "name" "phone number" and "ID". I defined all the sets and gets methods and the constructor for those variables.
In the class "2" I want to fill from the consol those variables. That will be the fist "option" of my CRUD, so everytime the user selects opcion=1, the system has to let add separately each of those variables. I know I have to use Array List but I haven't been able to do it successfully. This is an example of the code. CAPITAL LETTERS code is where I'm stuck. Thanks.
------First Class---------
package VV;
public class 1
{
private String name;
private String phone_number;
private String id;
public 1(String name, String phone_number, String id)
{this.name=name;
this.phone_number=phone_number;
this.id=id;
}
public String getName()
{ return name;
}
public void setName(String name)
{ this.name = name;
}
public String getPhone_number()
{ return phone_number;
}
public void setPhone_number(String phone_number)
{ this.phone_number = phone_number;
}
public String getId()
{ return id;
}
public void setId(String id)
{ this.id = id;
}
----------Second class------------
package VV;
public class 2
{
public 2()
{"Insert the name of the student:"
A METHOD TO INSERT THE NAME OF THE STUDENT
"Insert the phone number of the student:"
A METHOD TO INSERT THE PHONE NUMBER OF THE STUDENT
"Insert the ID of the student:"
A METHOD TO INSERT THE ID OF THE STUDENT
..And so on, each time user selects the opcion "add new student"
(I didn't put the while-case here with all its options to simply)
}
}
I actually don't know why you need that second class's constructor to take input from user and fill the fields of first class.
What I understood from the whole discussion is, you need to set the variables of the class by taking user input, and you need a dynamic way to take that input and set the values.
First way:
Well, this is a bit dynamic. You can use reflection to access all the variables of a class, and you can set their values dynamically.
First of all, create a default constructor in the first class. Then In the main class/whereever you want to take the input from user, create an object of first class and initialize it with default constructor. Then use reflection to work with individual fields, taking input from users and setting the values in the fields. This way doesn't require to know what fields are there to take input from user explicitly. Remember, you can use this method only if there's no problem to expose the names of the variables to the end user. I used only String input as you have only strings in the first class as variables. You need that field.setAccessible(true) if the variables are private. So, let's see the code in the main class/where you'll call the function to take user input:
Field[] arrayOfFields = Student.class.getDeclaredFields();
Scanner sc = new Scanner(System.in);
Student student = new Student();
for (Field field : arrayOfFields) {
try {
field.setAccessible(true);
System.out.println("Please enter the Student " + field.getName());
field.set(student, sc.nextLine());
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
That sets the fields accordingly.
Second Way:
If you know the variables you need to initialize the objects, just use scanner to scan them one by one from the user console input and initialize the object:
Scanner sc = new Scanner(System.in);
String id,name,phone_number;
System.out.println("Please enter the Student ID:");
id = sc.nextLine();
System.out.println("Please enter the Student Name:");
name = sc.nextLine();
System.out.println("Please enter the Student Phone Number:");
phone_number = sc.nextLine();
Student student = new Student(id, name, phone_number);
Simple as that.
I'm asked to compute a Java program with TestStaff that accepts name,
staff id and working perday as inputs from the user and displays the name, staff ID and salary of the staff. But at the end of the output, I got null null 0.0 . I'm a beginner at this object and class section and I'm really lost. Can anyone help? Here are my codes:
This is the given code:
class Staff {
private String name, staffID;
private double salary;
private int workingDay;
public void setStaffInfo(String nm, String id, int wDay){
name=nm;
staffID=id;
workingDay=wDay;
}
public void calculateSalary(){
salary = workingDay * 35.0;
}
public double getSalary(){
return salary;
}
public String getName(){
return name;
}
public String getStaffID(){
return staffID;
}
}
import java.util.Scanner;
Here are the codes for TestStaff:
class TestStaff {
static Scanner console = new Scanner(System.in);
public static void main(String arg[]){
Staff staff1= new Staff();
System.out.print("Enter your name: ");
String nm=console.nextLine();
System.out.print("Enter your Staff ID: ");
String id=console.nextLine();
System.out.print("Enter your working days: ");
int wDay=console.nextInt();
System.out.println(staff1.getName() + "\t" + staff1.getStaffID()+ "\t\t" + staff1.getSalary());
}
}
You need to use the Staff class set method to initialize its members.
i.e: staff1.setStaffInfo(nm, id, wDay);
What you've done is simply creating 3 new variables and assigning them values, but your Staff objects' members were not set.
Also you might want to call calculateSalary() before getSalary() because the former initializes the salary variable.
You are missing to call method staff1.setStaffInfo(nm, id, wDay);
I would suggest to have parameterized constructor with all the instance variables of class Staff, create instance for Staff using that constructor. That way you won't get null values.
Suggestion:
Create constructor in Staff class as:
Staff(){}
Staff(String name, String staffID, double salary , int workingDay){
this.name = name;
this.staffID=staffID;
this.salary=salary;
this.workingDay = workingDay;
}
And in TestStaff class, you can add these lines:
Staff staff2 = new Staff(nm,id, 2400, wDay);
System.out.println(staff2.getName() + "\t" + staff2.getStaffID() + "\t\t" + staff2.getSalary());
In the main method you have created the Staff object and stored all the input in some variable but haven't set the input in object. Thats why when you print staff1.getSalary() it returns you the default value of double i.e: 0.0. first set the value staff1.setInfo(...) And then print the values.
But at the end of the output, I got null, null, 0.0.
You are not passing any arguments to the setStaffInfo(String nm, String id, int wDay) anywhere in your code so that is why it is showing null, null,0.0
Solution
Pass the following variables to the setStaffInfo(String nm, String id, int wDay) method of the class Staff
String nm=console.nextLine();
String id=console.nextLine();
int wDay=console.nextInt();
Like this:
staff1. setStaffInfo(nm,id,wDay)
And an advice
Run your calculateSalary() in getSalary() method like this:
public double getSalary(){
calculateSalary(); //this will autimatically calculate salary
return salary;
}
Then, you will just have to call getSalary() in the main method and it will automatically call calculateSalary() or you can also put that one line of calculateSalary()in getSalary() also.
You create a new object from your Class Staff but you have to assign data member to the class and can done from 2 different ways :
1- Your method staff1.setStaffInfo(nm, id, wDay);
staff1.setStaffInfo(nm, id, wDay);
2- Constructor
Staff staff1= new Staff(id, nm, wDay);
Add the constructor below in Staff class this constructor will make you able to create a new object with specifying id, nm and wDay
Staff (String staffID ,String name , int workingDay) {
this.staffID = staffID;
this.name = name ;
this.workingDay = workingDay ;
}
I need to have a class with two constructors, one with and one without arguments. The one without is supposed to call the other with Randomized arguments, so not default ones.
Here is some sample code:
public Human(int ageIn, String nameIn){
this.name = nameIn;
this.age = ageIn;
}
public Human(){
String[] names = {"Peter", "Olof", "Alva", "Sanna", "Carl", "Illona"};
double random = Math.random();
int nameIndex = (int)(names.length*random+0.5);
String name = names[nameIndex];
random = Math.random();
int age = (int)(100*random+0.5);
this(age, name);
}
The thing that makes this hard is that this() has to be in the beginning of a constructor, but I have to define and figure out name and age before I can call the first constructor with them.
Is there any way around this?
You can make static methods which make these random values. Then on line 1 of your constructor you can call:
public Human(){
this(getRandomAge(), getRandomName());
}
Alternatively you could create a factory method to create a 'random' Human:
public class MyProgram {
public static void main(String[] args) {
Human someRandomStranger = Human.createRandomHuman();
//...
}
}
public class Human {
public Human(int ageIn, String nameIn){
this.name = nameIn;
this.age = ageIn;
}
// ...
public static Human createRandomHuman(){
String[] names = {"Peter", "Olof", "Alva", "Sanna", "Carl", "Illona"};
double random = Math.random();
int nameIndex = (int)(names.length*random+0.5);
String name = names[nameIndex];
random = Math.random();
int age = (int)(100*random+0.5);
return new Human(age, name);
}
}
This would keep your constructors clear from stuff that shouldn't be there in the first place.
A default constructor that randomly assigns values to it's fields might be accidentially called in your code and create unwanted results.
A properly named factory method on the other hand would help prevent such mistakes and clearly communicate your intention.
How about something like this?
public class Human {
public Human() {
this(null, -1);
}
public Human(String name, int age) {
if(name == null) {
name = //your random name generation code
}
if(age == -1) {
age = //your random age generation code
}
this.name = name;
this.age = age;
}
}
Don't mix concerns. A Human should not care about choosing a random name based on a predefined set of names nor compute a random age !
I would rather delete the no-arg constructor (except if you have one defined value for a name and for an age, but it seems that it's not your case) and extract this logic outside of Human, typically in a HumanFactory.
My task is to "design a class called employee that includes three instance variables, first name (string), last name (string), and monthly salary (double). Provide a constructor that initializes the threee instance variables. Provide set and get methods for each instance variable. [...] to get full credit, your programs should have no compilation errors and give correct outputs; they should also be well commented and appropriately formated."
Now, for all intents and purposes, this site helped me finish the shell of that homework yesterday, where I created the class, got the main to stop being annoying, initialized a constructor with 3 variables, and had set and get methods for them.
However, I also feel like I need to have some kind of actual instance variables that should be set'ed, get'ed, adn printf'ed out or something. Right now, the Command Prompt just self terminates on the first button press, because there's nothing for the program to actually DO.
In that way, I'm messing with my program as it will be displayed below. I can't quite get it to work, and would appreciate some insight into at least what I am doing wrong with the code below:
import java.util.Scanner;
public class Employee
{
public String FirstName, LastName; // String instance variables
public double Salary; //double floating-point instance variable
// main method begins program execution
public static void main( String[] args )
{
// create Scanner to enable user input in Dos
Scanner input = new Scanner(System.in );
}
// should introduce and initialize the constructor Employee
public Employee( String fName, String lName, double empSalary )
{
FirstName = fName;
LastName = lName;
Salary = empSalary;
}
// set First Name
public void setFirstName( String Steven ) // set the First Name
{
FirstName = Steven;
}
public void setLastName( String Dorsey ) // set the Last Name
{
LastName = Dorsey;
}
public void setSalary( double empSalary ) // set the Employee Salary
{
Salary = empSalary;
}
public String displayMessage()
{
// This statement calls Employee and should
// get the First Name from Input
System.out.printf( "Please enter the First Name\n");
getFirstName( string fName );
{
return FirstName;
}
System.out.printf( "Please enter the Last Name\n");
getLastName( string lName ) ); // get the Last Name
{
return LastName;
}
System.out.printf( "Salary: $%.2f\n");
getSalary( double empSalary )
{
return Salary;
}
}
} // End class
Now, here are my errors. provided this time by Textpad:
* Employee.java:54: error: ')' expected
getFirstName( string fName );
^
* Employee.java:54: error: illegal start of expression
getFirstName( string fName );
^
* Employee.java:60: error: ')' expected
getLastName( string lName ) ); // get the Last Name
^
* Employee.java:60: error: illegal start of expression
getLastName( string lName ) ); // get the Last Name
^
* Employee.java:60: error: ';' expected
getLastName( string lName ) ); // get the Last Name
^
* Employee.java:66: error: '.class' expected
getSalary( double empSalary )
^
* Employee.java:66: error: ';' expected
getSalary( double empSalary )
You don't have semicolons after your function names.
So, the following:
getLastName( string lName ) ); // get the Last Name
{
return LastName;
}
should instead be
getLastName( string lName ) ) // get the Last Name
{
return LastName;
}
Hope it helps, I didn't read through the rest of the code.
Your code shows that you probably have some misconceptions about how Java and programming languages in general work:
e.g. in the snippet:
public void setFirstName( String Steven ) // set the First Name
{
FirstName = Steven;
}
the naming of the String parameter Steven is very peculiar. Most programmers would name the parameter firstName or pFirstname because it holds a String variable. In some cases the content of that variable might be "Steven". Please note how I wrote the parameter names in bold while the variable content is put in quotes. The concepts variable and parameter are important to grasp before you'r code will function right. You might want to check your code along these lines for all the other concepts that you were asked to do in your assignment. Learning is about understanding the difference between a misconception and the right concept. Please don't get frustrated that your question got negative points. People on stackoverflow are expecting the people who ask questions to do the basic analysis of the problem themselves and then ask for help when they get stuck at a point where all the analysis didn't help.
try this:
public class Employee {
public String FirstName, LastName; // String instance variables
public double Salary; //double floating-point instance variable
//should introduce and initialize the constructor Employee
public Employee( String fName, String lName, double empSalary ) {
FirstName = fName;
LastName = lName;
Salary = empSalary;
}
public void setFirstName( String Steven ) // set the First Name
{
FirstName = Steven;
}
public void setLastName( String Dorsey ) // set the Last Name
{
LastName = Dorsey;
}
public void setSalary( double empSalary ) // set the Employee Salary
{
Salary = empSalary;
}
public String getFirstName()
{
return FirstName;
}
public String getLastName()
{
return LastName;
}
public double getSalary(){
return Salary;
}
public void displayEmployee(){
System.out.println("FirstName : "+FirstName);
System.out.println("LastName : "+LastName);
System.out.println("Salary : "+Salary);
}
//main method begins program execution
public static void main( String[] args )
{
// create Scanner to enable user input in Dos
Scanner input = new Scanner(System.in );
System.out.println("Enter employee details :");
Employee emp=new Employee(input.next(), input.next(), input.nextDouble());
emp.displayEmployee();
}
}// End of class
First of all, here are the instructions:
http://ideone.com/eRHwUo
Yes, this is homework! With that being said (and because I simply love the language), when you do post answers, please try to use pseudo code so that I just don't copy and paste into my program. Thank you!
As far as the code goes, I've done everything needed in for the section where the user enters all of the input. However, I need help with 'transferring' the data from the classes to the 'ArrayList' that we're supposed to use. I figure that once I get that down, I'll be able to just sort through the array to find the ID number for selection "B", and if the user enters "C" I'll just cycle through the array displaying everything in it.
Anyway, onto the code (this is main):
/*
* Name:
* Date:
* Assignment 2
*/
import java.util.Scanner;
public class homework
{
public static void main(String[] args)
{
char userSelection;
String convertString;
String userStrings;
Scanner kbd = new Scanner(System.in);
do
{
System.out.println("Here are your choices:");
System.out.println("A. Enter employee data" +
"\nB. Search for employee data" +
"\nC. List all data" +
"\nD. Exit");
convertString = kbd.next();
userSelection = convertString.charAt(0);
switch(userSelection)
{
case 'A':
GetUserInfo();
break;
case 'B':
// Stuff;
break;
case 'C':
// Display all data;
break;
case 'D':
System.out.println("Goodbye!");
break;
default:
System.out.println("Error, that is not a valid entry. Please try again.");
}
} while (userSelection > 'D');
}
// Write functions here
public static void GetUserInfo()
{
String firstName;
String lastName;
String empID;
double hourlyRate;
int hoursWorked;
double withPercent;
Scanner kbd = new Scanner(System.in);
System.out.println("What is your first name?");
firstName = kbd.next();
System.out.println("What is your last name?");
lastName = kbd.next();
System.out.println("What is your employee ID?");
empID = kbd.next();
Employee user = new Employee(empID);
user.setFirstName(firstName);
user.setLastName(lastName);
System.out.println("What is your hourly rate?");
hourlyRate = kbd.nextDouble();
System.out.println("How many hours did you work?");
hoursWorked = kbd.nextInt();
System.out.println("What is your withholding percentage?");
withPercent = kbd.nextDouble();
Pay user1 = new Pay();
user1.setHourlyRate(hourlyRate);
user1.setHoursWorked(hoursWorked);
user1.setWithPercent(withPercent);
}
}
This is the Employee class:
public class Employee
{
// Members of the class
String firstName;
String lastName;
String employeeID;
// remember about the pay object
// EmployeeID constructor
public Employee(String empID)
{
this.employeeID = empID;
}
// Below are the various getters and setters of the Employee class
public String getFirstName()
{
return firstName;
}
public void setFirstName(String firstName)
{
this.firstName = firstName;
}
public String getLastName()
{
return lastName;
}
public void setLastName(String lastName)
{
this.lastName = lastName;
}
public String getEmployeeID()
{
return employeeID;
}
}
And this is the Pay class:
public class Pay
{
// Members of the class
double hourlyRate;
int hoursWorked;
double withPercent;
// Various getters and setters of the Pay class
public double getHourlyRate()
{
return hourlyRate;
}
public void setHourlyRate(double hourlyRate)
{
this.hourlyRate = hourlyRate;
}
public int getHoursWorked()
{
return hoursWorked;
}
public void setHoursWorked(int hoursWorked)
{
this.hoursWorked = hoursWorked;
}
public double getWithPercent()
{
return withPercent;
}
public void setWithPercent(double withPercent)
{
this.withPercent = withPercent;
}
// Calculates the raw payment
public double CalcPayRate(double hourlyRate, int hoursWorked)
{
return hourlyRate * hoursWorked;
}
// If the employee has worked overtime, calculates the new payment
public double CalcOvertimePay(double hourlyRate, int hoursWorked)
{
double rawPay = 0;
rawPay = hourlyRate * hoursWorked;
if (hoursWorked > 40)
{
rawPay *= 1.5;
}
return rawPay;
}
// Calculates final amount that the employee will be paid
public double CalcTotalPay(double hourlyRate, int hoursWorked, double withPercent)
{
double rawPay = 0;
double subTotalPay = 0;
double finalPay = 0;
rawPay = hourlyRate * hoursWorked;
subTotalPay = rawPay * withPercent;
finalPay = rawPay - subTotalPay;
return finalPay;
}
}
So, thoughts please?
Also, final comments:
(1) I don't understand what 'Pay Object' is supposed to do under the Employee class?
(2) How do I use the input data to create a 'Pay Object' and then create an employee object?
Those are the two parts from the instructions I'm a little unclear about, and as such if you could shade some light on that, it'd be helpful!
(3) If there's anything that seems off about my syntax, please let me know about it so I can change it accordingly. I'm still new to this language, so any help would be great.
Edit: I have updated my code with comments:
public class homework
{
public static void main(String[] args)
{
// ArrayList<Employee> employeeList = new ArrayList<Employee>();
do
{
// Stuff commented out for readability
case 'A':
PromptForInput();
// Employee emp = PromptForInput();
// employeeList.add(emp);
break;
} while (userSelection > 'D');
}
// public static Employee PromptInput()
public static void PromptForInput()
{
Employee user = new Employee(empID);
// Isn't this supposed to be returned as well?
Pay user1 = new Pay();
user1.setHourlyRate(hourlyRate);
user1.setHoursWorked(hoursWorked);
user1.setWithPercent(withPercent);
//return user;
}
}
Is that how it's supposed to look?
I still do not understand the 'pay object' part of the assignment..
Start by taking a look at Collections.
If I was doing this...
I would return the Employee from the getUserInfo method and add it to the ArrayList within the calling method. This keeps the getUserInfo method focused on a single responsibility.
I would also allow the getUserInfo to return null if the values entered by the user did not pass validation, but this might be beyond the scope of the requirements.
For example...
List<Employee> employees = // create ArrayList...
//...
Employee emp = getUserInfo();
if (emp != null) {
employees.add(emp);
}
You should also setting a Pay object to the Employee when you create it, this will associate the Pay object to the Employee so you can find it later
As to your Pay object. The CalcPayRate, CalcOvertimePay and CalcTotalPay don't required parameters, as all the information required for these methods should be available from the properties of the object...
For example...
public double getRawPay() {
return getHoursWorked() & getHourlyRate();
}
I would also encourage you to take a look at Code Conventions for the Java Programming Language
Updated #1
Associating the Pay object with the Employee is no different from how you assiciated things like the employee's names
Basically, you need to supply a instance field/property to hold the reference and some means to set and get the reference, for example...
public class Employee
{
//...
Pay pay;
// EmployeeID constructor
public Employee(String empID)
{
this.employeeID = empID;
}
// EmployeeID constructor
public Employee(String empID, Pay pay)
{
this(empID);
this.pay = pay;
}
public void setPay(Pay pay) {
this.pay = pay;
}
public Pay getPay() {
return pay
}
//...
}
I've supplied a second constructor, you don't really need it, but it's a demonstration of how it might be achieved.
Then you would simply pass the reference of Pay to Employee...
Employee emp = new Employee(...);
//...
Pay pay = new Pay();
//...
emp.setPay(pay);
Update #2
Another approach would be to create an instance of Pay when Employee is created...
public class Employee
{
//...
Pay pay = new Pay();
// EmployeeID constructor
public Employee(String empID)
{
this.employeeID = empID;
}
This would suggest we no longer need setPay, but that's up to you.
When you need to get or set values for Pay, you simple ask the instance of Employee for it
Employee emp = ...;
emp.getPay().setHourlyRate(hourlyRate);
//...
double hourlyRate = emp.getPay().getHourlyRate();
Updated #3
Basically, you need to associate an instance of Pay with an instance of Employee. If it makes it easier, name it something else...
Based on the example from Update #1
public static Employee PromptForInput()
{
String firstName;
String lastName;
String empID;
double hourlyRate;
int hoursWorked;
double withPercent;
//...
Employee user = new Employee(empID);
user.setFirstName(firstName);
user.setLastName(lastName);
//...
Pay payObj = new Pay();
payObj .setHourlyRate(hourlyRate);
payObj .setHoursWorked(hoursWorked);
payObj .setWithPercent(withPercent);
// Don't forget to give an instance of Pay to the instance
// of Employee
user.setPay(payObj);
return user;
}
Think of Employee as a container, it contains the name and ID of the employee as well as their pay details. When you start with a new instance of Employee, it is just an empty container, you need to fill it...
When you need to, you simply request and instance of Pay from the Employee via the getPay
Update #4
Based on you new code, I would only make one small suggestion...
In your display all data choice, you could use the following loop to display the Employee AND the Employee's pay rate, for example...
for (int i = 0; i < employeeList.size(); i++)
{
Employee emp = employeeList.get(i);
System.out.println(emp);
System.out.println(emp.getPay().CalcPayRate());
}
Looking at the instructions, I think your just supposed to create an ArrayList with a generic type of Employee. The GetUserInfo() should return the Employee object it just created, and this Employee object should be stored into the ArrayList - right after the function call - with its .add() function.
Edit:
My attempt at your bottom three questions.
1) The Pay Object should be referenced with a variable in the Employee Object. You can use create another setter method in the Employee Object to do this.
2) I believe you already did this by the following code:
user1.setHourlyRate(hourlyRate);
user1.setHoursWorked(hoursWorked);
user1.setWithPercent(withPercent);
3) The syntax looks fine to me.
A. Enter Employee Data
You are utilizing a class (noun) to perform actions. Actions generally translate to method calls. Even your usage of 'get' (by convention classes should not start with get) suggests introducing a method. So, change GetUserInfo to
private static Employee promptForEmployeeInfo()
//or more simply
private static Employee getEmployee()
Then you can return an employee object after all the necessary information is gathered, including the pay information. Then you will need to provide the pay information to the employee object. In the most basic form, this will be accomplished by instantiating a Pay object and passing it into the constructor of Employee (for immutable objects which is more advanced techniques than you require) or via a setter method.
Inside your main method, the List will be instantiated before your do/while loop. Every time the user enters 'A' you call employeeList.add('insert Employee method call here').
(1) I don't understand what 'Pay Object' is supposed to do under the Employee class
In object oriented programming (OOP), encapsulating data and actions on that data into a descriptive, appropriately named class is part of OOP convention.