[UML图]时,[1]类返回类型创建方法
下周我学习了期中考试,我练从我的教授给出一些例子;然而,我在类返回类型方法中遇到了一些麻烦。
我附加了UML图以防万一。
我想了解的是Job类中的getPerson方法。我不认为我需要Job类中的数组列表来存储所有员工。因为我在公司类中已经有了一个数组列表。另外,返回类型是Employee类,我不确定如何使用此类返回类型获取人员的信息。
我的问题
- 公务员getPerson(){}在作业类
- 公共布尔isVacant(){}在作业类
- 此外,你会介意检查getVacantJobs,getFilledJobs和getAllJobs方法如果这些构建正确?
我用迭代器来显示所有存储的作业。
--------------------------- Employee Class ----------------- ------------
public class Employee {
private String name;
private int id;
public Employee(int id, String name) {
this.name = name;
this.id =id;
}
public final String getName() {
return name;
}
public final void setName(String name) {
this.name = name;
}
public final int getId() {
return id;
}
public final void setId(int id) {
this.id = id;
}
@Override
public String toString() {
return "Employee [name=" + name + ", id=" + id + "]";
}
}
---------------------------- Job Class- -------------------------------------
public class Job {
private String description;
private int id;
private double maxSalary;
public Job(int id, double maxSalary, String description) {
this.description = description;
this.id = id;
this.maxSalary = maxSalary;
}
public Job(int id, double maxSalary, String description, Employee e1) {
this.description = description;
this.id = id;
this.maxSalary = maxSalary;
}
@Override
public String toString() {
return "Job [description=" + description + ", id=" + id
+ ", maxSalary=" + maxSalary + "]";
}
public final String getDescription() {
return description;
}
public final void setDescription(String description) {
this.description = description;
}
public final double getMaxSalary() {
return maxSalary;
}
public final void setMaxSalary(double maxSalary) {
this.maxSalary = maxSalary;
}
public final int getId() {
return id;
}
public Employee getPerson() {
retrun
}
public final void setPerson(Employee person) {
this.id = person.getId();
}
}
------ --------------------公司类---------------------------
import java.util.ArrayList;
import java.util.Iterator;
public class Company {
static ArrayList list = new ArrayList();
Iterator itr = list.iterator();
private String name;
public Company(String name) {
this.name = name;
}
public Company() {
// TODO Auto-generated constructor stub
}
public static void addJob(Job j1) {
list.add(j1);
}
public void removeJob(int id) {
list.remove(id);
}
public ArrayList<Job> getVacantJobs() {
while (itr.hasNext()) {
if ((itr == null)) {
System.out.println(itr);
}
}
return null;
}
public ArrayList<Job> getFilledJobs() {
while (itr.hasNext()) {
if (!(itr == null)) {
System.out.println(itr);
}
}
return null;
}
public ArrayList<Job> getAllJobs() {
while (itr.hasNext()) {
System.out.println(itr.next());
}
return null;
}
}
当你说_“我的问题:1'公务员getPerson(){}'在招聘类” _你不解释你的问题是什么,只是在那里发生。你的问题是无关紧要的,因为你没有真正解释任何问题。 –
我看到的一个问题是,您在'Employee'和'Job'中混淆了'id'属性。 UML图表明'Employee.id'是一个字符串而不是int。因此你的方法'Job.setPerson()'没有多大意义。 – Turamarth
感谢您的建议,我会牢记这一点。 –