我在java中实现了一个循环队列,它将接受对象(Employee)作为条目。现在我有一个方法来编辑特定对象的姓氏,但不知何故,即使我正在导入所有必需的包,我也无法Employee
从类中访问在类中找到的姓氏 setter 方法。CQueue
这是代码:
//PACKAGES IMPORTED
package linearstructures;
import dataobjects.*;
import linearnodes.*;
public class CQueue{
Node front, rear, temp;
boolean full = false;
String key;
public AnyClass searchKey(String key)
{
temp = rear.next; // first node
do
{
if (temp.obj.getKey().equals(key))
return temp.obj;
temp = temp.next;
} while (temp != rear.next);
return null;
}
public AnyClass editObject(String key){
int choice, newSeqNo;
double newPay;
boolean exit = false;
Employee etemp = new Employee(); //INCLUDED THIS AFTER EDIT
searchKey(key);
if(searchKey(key) != null){
temp.obj.getData();
System.out.println();
System.out.println("------------------------");
System.out.print("Enter new Salary: ");
newPay = sc.nextDouble();
System.out.println("------------------------");
System.out.println();
etemp.setPay(newPay); //INCLUDED THIS AFTER EDIT
else
System.out.println("NO OBJECT WAS FOUND!");
return null;
}
}
Employee
班级:
package dataobjects;
public class Employee extends AnyClass
{
public String surname;
public double pay;
public Employee(){}
public Employee(int seqNo, String surname, double pay)
{
super(seqNo);
this.surname = surname;
this.pay = pay;
}
public double getSalary()
{
return pay;
}
public void setPay(double newPay)
{
pay = newPay;
}
public String getData()
{
return super.getData() + ", Surname: " + surname + ", Pay: " + pay;
}
public String getKey()
{
return surname;
}
}
AnyClass
班级:
package dataobjects;
public class AnyClass
{
public int seqNo;
public AnyClass(){}
public AnyClass(int seqNo)
{
this.seqNo = seqNo;
}
public int getseqNo()
{
return seqNo;
}
public void setseqNo(int seqNo) {
this.seqNo = seqNo;
}
public String getData()
{
return "Sequential Number - " + seqNo;
}
public String getKey()
{
return Integer.toString(seqNo);
}
public void edit(){}
}
Node
班级
package linearnodes;
import dataobjects.*;
public class Node{
public AnyClass obj;
public Node next;
public Node(AnyClass obj){
next = null;
this.obj = obj;
}
}