Description.
In this assignment you have to use the following PrinterQueue class. In this class, you have to implement the parts marked as //TODO. You are not allowed to change the other parts and you are not allowed to add new public methods. You can create another class or use existing structures of Java (see java.util. package) for implementing a priority queue. Do not forget to add comments in your code and to create a documentation using javadoc.
public class PrinterQueue{
private static PrinterQueue queue;
//TODO –add private fields to imlement a priority queue
private PrinterQueue(){
// TODO –initialize the priority queue
}
public static PrinterQueue getQueue(){
if (queue==null) queue=new PrinterQueue();
return queue;}
public void addJob (PrintJob job) {
//TODO –add the job to the printer queue based the priority of the job.
// Use the job’s getPriority method to check its priority
System.out.println(“Job ”+ job.getName()+ “is added to the printer queue”);
}
public boolean isEmpty(){
//TODO
}
public PrintJob removeJob(){
//TODO –remove the highest priority job from the queue
System.out.println(“Job ”+ job.getName()+ “has been printed”);
}
public boolean isFull(){
//TODO
}
//TODO –you may add private methods as helper methods.
}
Part b.
After implementing the PrinterQueue an the required classes to compile (such as PrintJob), you need to implement a TestPrinterQueue class. TestPrinterQueue class should have a main method.
When the program runs, it takes the following inputs for each job in this order from user until the user enters -1 as priority.
- Priority (int)
- Jobname (String)
- number of pages in this printjob (int)
There are 4 levels of priority, 0 being the lowest priority.
TestPrinterQueue class, either in its main method or in a helper method invoked by the main method, should use an instance of the PrinterQueue class. I.e. you need to get access to a PrinterQueue object.
The program first takes the jobs from the user, creates job objects, adds them to the queue, then remove the items from the queue (it is encouraged to have these functionality in separate methods of the TestPriotiyQueue class)
Part c.
Now you have to extend the program you have implemented.In this part, you are required to have specific print jobs. A printjob can be a textjob, a binary job ( such as a ps file), or an imagejob . Implement these specific printJobs.
One change caused by this extension is user entries. This time a user enters
- Priority (int)
- Jobname (String)
- number of pages in this printjob (int)
- job type (one of these Strings: “textjob” “binaryjob” or “imagejob”)
While extending your program, which methods have changed? Please indicate the classes and the methods that are affected by this extension in their source code. I.e. write comments in the code saying which ones are affected.
Submission: Put all your code in a java package and zip that folder. Submit the zip file to METU online. If you have used an IDE such as eclipse, do not forget to create a buld.xml for deployment. Make sure your code gets compiled.
PrinterQueue
public class PrinterQueue {
private static PrinterQueue queue;
private in size, cap;
private PrintJob[] jobs;
//private static OrderedVectorOfPrintJob jobs;
private PrinterQueue() {
size = 0;
cap = 10;
jobs = new PrintJob[cap];
}
public static PrinterQueue getQueue() {
if (queue == null)
queue = new PrinterQueue();
return queue;
}
public void addJob(PrintJob job) {
if (size == cap)
makeBigger();
for (int pos = size-1; pos >= 0; pos--)
if (jobs[pos].getPriority() > b.getPriority())
jobs[pos+1] = jobs[pos];
else {
jobs[pos+1] = b;
size++;
return;
}
jobs[0] = b;
size++;
}
public boolean isEmpty() {
if (size == 0)
return true;
return false;
}
public PrintJob removeJob() {
PrintJob temp = PrintJob[size-1];
size--;
return temp;
}
public boolean isFull() {
if (size == cap)
return true;
return false;
}
}
PrintJob
public class PrintJob {
private int Priority;
private String JobName;
private int No_Of_Pages;
public PrintJob(int Prio, String Name, int Number ){
setPriority(Prio);
setName(Name);
setNo_Of_Pages(Number);
}
public void setPriority(int Prio){
Priority = Prio;
}
public void setName(String Name){
JobName = Name;
}
public void setNo_Of_Pages ( int Number){
No_Of_Pages = Number;
}
public String getName(){
return JobName;
}
public int getPriority(){
return Priority;
}
public int getNumberOfPages(){
return No_Of_Pages;
}
}
This post has been edited by lilVaratep: 12 October 2012 - 08:24 PM

New Topic/Question
Reply



MultiQuote





|