I have an abstract class Employee, and based on that, I created the following subclasses:
FulltimeEmployee
PartTimeEmployee
Salesman
as well as one standalone class, Orders.
I use the Orders class to "describe the salesman" by sending an array of orders in the Salesman constructor:
public Salesman(String firstname, String lastname,int code, String address,
String city,int tk,int phone,String email,int deptcode,int card,
double hours,String cat,int orderno,double salary,
Orders[] order){
super( firstname, lastname, code, address, city, tk, phone, email, deptcode,
card, hours, cat );
this.orderno=orderno;
setBaseSalary( salary );
getSalary(orders);
/////////////////
}
Later, I use that array to calculate the bonus a salesman gets, depending on the amount of sales he makes.
In main, I created an array of type Employee:
Employee employees[] = new Employee[ 7 ];
employees[ 0 ] = salary1;
employees[ 1 ] = salary2;
employees[ 2 ] = salary3;
employees[ 3 ] = partt1;
employees[ 4 ] = partt2;
employees[ 5 ] = sales1;
employees[ 6 ] = sales;
where each row is a different type of employee (salary = full-time, partt = part-time, and sales = salesman).
My problem is that I want to print the orders of each salesman using the employees array.
What I’ve done so far is
for (int i=5;i<employees.length;i++){
System.out.printf("Orders of Salesman: %S %S",
employees[i].getName(),employees[i].getSurname());
System.out.printf(" Total amount(money) from orders: %,.0f ",
employees[i].earnings());
int j=0;
((Salesman)employees[i]).getOrderNo(arr) ;
//((Orders)employees[i]).getOrderNo();
System.out.printf("ordernumber: %d orderdate:%s description: %s
order amount(money): %,.0f\n ");
}
The problem comes here:
System.out.printf("ordernumber: %d orderdate:%s description: %s order amount(money): %,.0f\n ");
How do I access the orders array inside of the Salesman object on employees array?
I have tried casting, but it won’t work because Orders is not a subclass of Employee.
I need it to print, for example,
Orders of Salesman: john koun
Total amount of orders: 13000
Orders per SalesmanOrder number: 1 order date: 10/2/2010 description: machinery sale order amount: 12000
Order number: 2 order date: 20/2/2010 description: sales of parts order amount: 1000
your
Salesmanconstructor accepts anOrder[]orders but it doesn’t look like you keep a reference to it anywhere (unless you do that ingetSalaryor in the commented out portion).You will need to add something like
this.orders = orders;in your
Salesmanconstructor so you can refer to the array as a field/property of theSalesmanobject.Typically you should use the
Beanpattern whereby each field has a getter/setter method:then in your constructor add
setOrders(orders);and then in your debug/output code add: