如何为员工创建计划?例如,我想创建一个名字和工作需要多少工作时间的工人。此外,我想设定一个特定的时间来处理每个工人,特定的休息时间和他们应该开始工作的开始时间。我正在寻找的是这个结果:
9:00 Worker 1
10:00 break
10:15 Worker 2
11:15 break
等等,直到所有工人的工作时间结束。
当前代码:
import java.awt.List;
import java.util.ArrayList;
import java.util.Calendar;
public class Main {
public static void main(String[] args) {
Schedule s1 = new Schedule();
s1.addSchedule("John", 120); // 2hours
s1.addSchedule("William", 180); // 3 hours
Schedule s;
ArrayList<String> eventData = new ArrayList<String>();
for(ScheduleBlock ev : s.getSchedule())
{
eventData.add(ev.getStartTime().get(Calendar.HOUR_OF_DAY)+":" + ev.getStartTime().get(Calendar.MINUTE) +" " + ev.getTopic() + " (" + ev.getDuration() + ")" );
}
System.out.println(eventData);
}
}
import java.awt.List;
import java.util.ArrayList;
import java.util.Calendar;
public class Schedule {
private ArrayList<Worker> workers = new ArrayList<Worker>();
private ArrayList<ScheduleBlock> schedule = new ArrayList<ScheduleBlock>();
public void addSchedule(String name, int duration){
workers.add(new Worker(name, duration));
}
public List<Worker> getWorkers() { return workers; }
public List<ScheduleBlock> getSchedule() { return schedule; }
public void generateStudyPlan(){
schedule = new ArrayList<ScheduleBlock>();
for(Worker w : workers){
schedule.add(new ScheduleBlock(w.getSubject(), Calendar.getInstance(), w.getDuration()));
}
}
public void generateStudyPlan(Calendar startStudy) { }
public void setBlockSize(int size) { }
public void setBreakLength(int i) { }
}
public class Worker {
private String name;
private int duration;
public Worker(String name, int duration)
{
this.name = name;
this.duration = duration;
}
public String getSubject() { return name; }
public int getDuration() { return duration; }
}
ScheduleBlock类:
import java.util.Calendar;
public class ScheduleBlock {
private String subject;
private Calendar startTime;
private int duration;
public ScheduleBlock(String subject, Calendar startTime, int duration)
{
this.subject = subject;
this.startTime = startTime;
this.duration = duration;
}
public String getTopic(){ return subject; }
public int getDuration() { return duration; }
public Calendar getStartTime() { return startTime; }
}
我无法添加一个开始时间并将我的Arraylist设置为从那时开始。我也无法设置休息时间
答案 0 :(得分:1)
首先,您尚未初始化Schedule s
Schedule s; // hasn't been initialized
ArrayList<String> eventData = new ArrayList<String>();
for(ScheduleBlock ev : s.getSchedule()) // you're trying to use s here