Here is the part of the code I am having trouble with:
for (i=0; i<=numOfEmployees-1; i++)
{
System.out.println("Enter the name of an employee that worked this house:");
nameOfEmployee = scan.next();
if(numOfEmployees == 2 && numOfRooms == "6")
nameOfEmployee.updatePay(30);
if(numOfEmployees == 2 && numOfRooms == "5")
nameOfEmployee.updatePay(25);
if(numOfEmployees == 2 && numOfRooms == "4")
nameOfEmployee.updatePay(20);
if(numOfEmployees == 2 && numOfRooms == "3")
nameOfEmployee.updatePay(15);
if(numOfEmployees == 3 && numOfRooms == "6")
nameOfEmployee.updatePay(25);
if(numOfEmployees == 3 && numOfRooms == "5")
nameOfEmployee.updatePay(20);
if(numOfEmployees == 3 && numOfRooms == "4")
nameOfEmployee.updatePay(15);
if(numOfEmployees == 3 && numOfRooms == "3")
nameOfEmployee.updatePay(10);
}
And here is my method program:
public class Employee
{
String houseNumber, date, numOfRooms, name;
int pay;
public Employee(String name)
{
this.name = name;
this.pay = 0;
}
public Employee(String houseNumber, String date, String numOfRooms)
{
this.houseNumber = houseNumber;
this.date = date;
this.numOfRooms = numOfRooms;
}
public void updatePay(int housePay)
{
pay += housePay;
}
public int getPay()
{
return pay;
}
public String getName()
{
return name;
}
public String getHouse()
{
return "House Number: " + houseNumber +
"/nDate Cleaned: " + date +
"/nNumber Of Rooms: " + numOfRooms;
}
}
There error is:
Calculation.java:59: error: cannot find symbol
nameOfEmployee.updatePay(20);
^
symbol: method updatePay(int)
location: variable nameOfEmployee of type String
I get it for every single one of the updatePay. I'm guessing it's something wrong with my method program but I'm not sure what is wrong with it.
Code where user creates the employees:
//Prompting user to enter # of employees that worked on Monday
System.out.println("How many employees worked on Monday?");
int numOnMon = scan.nextInt();
Employee[] newEmployeeName = new Employee[numOnMon];
//Prompting user to enter the employees that worked on Monday
for (int i=0; i<=numOnMon-1; i++)
{
System.out.println("Please enter the name of an employee that worked on Monday:");
name = scan.next();
newEmployeeName[i] = new Employee(name);
}