Reputation:
I'm building a small Java app to calculate monthly expenses for a department:
Currently working on MainClass. I have 2 question/areas I'd like some input. 1) getting these errors from these lines.
Manager managerA = new Manager(tester1, dev1);
Manager managerB = new Manager(managerA);
Multiple markers at this line - The constructor Manager(QATester, Developer) is undefined - Manager cannot be resolved to a type
2) I'm new to threading and was considering running this app on a thread, maybe adding a UI, suggestions/examples?
Thanks.
package main;
import expenseApp.Developer;
import expenseApp.Manager;
import expenseApp.QATester;
public class MainClass {
public static void main(String[] args)
{
QATester tester1 = new QATester();
Developer dev1 = new Developer();
Manager managerA = new Manager(tester1, dev1);
Manager managerB = new Manager(managerA);
}
}
package expenseApp;
import java.util.ArrayList;
public class Manager extends Employee
{
private ArrayList<Manager> managerList;
private ArrayList<Employee> employeeList;
public void add(Employee employee)
{
if(employee instanceof Manager)
{
managerList.add((Manager) employee);
}
else
{
employeeList.add(employee);
}
}
@Override
public int getExpenses()
{
return 300;
}
public int getTotalExpenses()
{
int totalExpenses = 0;
for(Manager manager : managerList)
{
totalExpenses += manager.getTotalExpenses();
}
for(Employee employee : employeeList)
{
totalExpenses += employee.getExpenses();
}
return totalExpenses;
}
Upvotes: 1
Views: 46
Reputation: 554
Question 1: Your calling code can't find the Manager
class for some reason. While it's strange because the error occurs on the constructor line instead of the import
line (which is usually the case), I'd suggest fixing you constructors first (see my next section) before looking into that cannot be resolved into a type
error, as it might be a subsequent fault.
Furthermore, your Manager
class does not have any constructor defined, which implicitly defines the default (empty) constructor:
public Manager() {
}
You need to provide all the constructors you need. From your code I'm guessing you want something like this:
public Manager(List<Manager> managers, List<Employee> employees) {
this.managers = new ArrayList<>(managers);
this.employees = new ArrayList<>(employees);
}
Question 2: "Running on a thread" - your application is already running on a thread, the main
thread. What do you want to do that makes you think you need threading? While adding a UI might be a valid response, there is the possibility of building a UI without explicit threading on your side. My suggestion would be to keep it as simple as necessary, from what I see, you don't need multithreading right now, and I'd not introduce a whole lot of synchronization issues unless it's necessary.
Upvotes: 1