You have to use this
method to pass your own instance as an argument. If I understood correctly, you need to use the etemp
array in the other class, the one having the pay
method. If that is right, you don't have to create more objects.
etemp[15] = new Employee(134, "Nicole", 45.0);
queue.put(etemp[15]);
if(queue!=null){
//Attempt 1 : Editing pay of a single employee
System.out.println("not empty!");
double x = etemp[15].getSalary();
double calc = (x*0.10)+x;
etemp[15].setPay(calc);
System.out.println("Raise: "+etemp[15].getData());
//Attempt 2 : Using a method to edit pay of ALL employee
queue.pay(this,10); //Adding our own instance
} else {
System.out.println("empty");
}
METHOD IN OTHER CLASS:
public void pay(MainClass m, int p){
// Here you can use m as the instance, it will have the etemp. Normally, atributes are private, so you have to implement some kind of getters to reach to that array
int id = 0;
String k = "";
double pay = m.getOriginalPay(id); // For example
Employee e = new Employee(id, k, pay);
CircQueue q = new CircQueue(20);
if(rear!=null){
Node temp=front;
do{
for (int i= 0; i<currNodes; i++)
{
System.out.println(temp.obj.getData());
q.put(e);
q.listAll();
double x = e.getSalary();
double calc = (x*0.10)+x;
System.out.println("Raise: "+calc);
temp = temp.next;
}
}while(!(temp==rear.next));
} else System.out.println("Empty queue!");
}
Tell me if I helped you.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…