import java.text.*;
import java.util.*;
public class DailyLogRx
{
private int totalCost = 0;
private ArrayList<Job> waitingList;
private ArrayList<Job> completedList;
public DailyLogRx()
{
waitingList = new ArrayList<Job>();
completedList = new ArrayList<Job>();
}
public void addJob(Job job, int d, int m, int y)
{
job.setDate(d, m, y);
waitingList.add(job);
}
public Job[] getJobs(List<Job> list)
{
int size = list.size();
return list.toArray(new Job[size]);
}
private void allComplete()
{
completedList.addAll(waitingList);
}
public static void main(String[] argsd)
{
DailyLogRx test = new DailyLogRx();
test.addJob(new Job("East Side"), 6, 9, 2008);
test.addJob(new Job("Uptown"), 14, 6, 2010);
test.addJob(new Job("Harbor"), 13, 5, 2009);
Job[] jobs = test.getJobs(test.waitingList);
for(int j = 0; j < jobs.length; j++)
{
System.out.println(jobs[j]);
}
test.allComplete();
// total cost of all jobs in completedList:
jobs = test.getJobs(test.completedList);
int totalCost = 0;
for(int j = 0; j < jobs.length; j++)
{
totalCost += jobs[j].getCost();
}
System.out.println("totalCost = " + totalCost);
}
}
class Job
{
DateFormat df = new SimpleDateFormat("dd MMM yyyy");
private int reference;
private String name;
private int pagno;
private int copno;
private Time setTime;
private Date date;
private boolean doubleSided;
private int cost;
public Job(int refere, String nam, int pgno, int cpno,
int hour, int minute, boolean doubleSid)
{
reference = refere;
name = nam;
pagno = pgno;
copno = cpno;
doubleSided = doubleSid;
setTime = new Time(hour, minute);
date = null;
if (doubleSid)
{
cost = (pgno * cpno) * 2;
}
else
{
cost = (pgno * cpno) * 3;
}
}
public Job(String name)
{
this(0,name,0,0,0,0,false);
}
public int getCost() { return cost; }
public void setDate(int day, int month, int year)
{
Calendar calendar = Calendar.getInstance();
calendar.set(year, month, day);
date = calendar.getTime();
}
public String toString()
{
return "Job[name: " + name +
", date: " + df.format(date) + "]";
}
}
class Time
{
int hour;
int minute;
Time(int hour, int minute)
{
this.hour = hour;
this.minute = minute;
}
}