Business Programming

Course announcements for INFS1609 and INFS2609

Business Programming random header image

Assignment 3

Posted by on September 20th, 2012 · Assignments

DUE DATE: Sunday 14th Oct, 23:59:59

Change Log

  • Sample Solution has been updated as of Sept 25th 17:30. If you downloaded the sample earlier than this, grab the latest copy

In this assignment you will be implementing a simple job queue.

Topics covered

This assignment covers the following ideas:

  • OO design: Abstraction and encapsulation
  • Implementing a class with fields, constructors and accessor methods,
  • Handling collections of objects with ArrayLists,
  • Implementing state using fields and mutator methods,
  • Using the null object to represent “nothing”.

The task

You need to implement two classes Job and JobQueue.

The Job class

The Job class is a simple data structure containing:

  • The job name (a String)
  • The duration of the job in seconds (a positive integer).

You need to implement a class called Job with appropriate fields to store this data.

You also need to implement:

  • A constructor: Job(String name, int duration) which initialises the fields to the given values.
  • Accessor methods: getName() and getDuration(). which return the field values.
  • run() method which prints “JOB COMPLETE: ” followed by the name of the job.
    E.g. The code:

    Job job = new Job("Wash the car.", 100);
    job.run();

    should print:

    JOB COMPLETE: Wash the car.

The JobQueue class

The JobQueue class implements a queue of jobs. When you create the queue it is initially empty. You can add jobs to the end of the queue. You can also add run time to the queue. When you run the queue, any available run time is used to execute jobs in the order they are added. As each job is completed, it is moved to the complete jobs list.

So for example, starting with an empty queue:

  1. Add a job “A” that takes 20 seconds.
  2. Add a job “B” that takes 10 seconds.
  3. Add a job “C” that also takes 10 seconds.
  4. Add 25 seconds to the clock.
  5. Run the queue:
    1. Job A is completed. 5 seconds remain on the clock.
    2. Job B is now the current job.
    3. There is not enough time to complete this job, so the queue stops.
  6. Add another 20 seconds to the clock, making the total 25.
  7. Run the queue:
    1. Job B is completed. 15 seconds remain on the clock.
    2. Job C is completed. 5 seconds remain on the clock.
    3. The jobQueue is now empty, so it stops with 5 seconds left on the clock

You need to implement:

  • The JobQueue class with appropriate fields.
  • A constructor with no parameters than initialises the pending and completed queues to empty and the clock to zero.
  • Accessor methods:
    • getPendingJobs() which returns the list of jobs that have not been completed (including the current job)
    • getCompletedJobs() which returns the list of jobs that have been completed.
    • getCurrentJob() which returns the job at the front of the pending queue, or null if the queue is empty.
    • getClockTime() which returns the amount of time left on the clock (as an integer)
    • getTotalDuration() which returns the total duration of all the pending jobs.
  • Mutator methods:
    • addJob(Job job) which adds a Job to the end of the Queue.
    • addTime(int seconds) which adds the specified number of seconds to the clock.
    • runOne() which runs the first job on the queue if there is enough time on the clock.
    • runAll() which runs all the jobs on the queue in order until it runs out of time.

Sample solution

We are not providing a skeleton solution for this assignment as we will be testing that you are able to write your own method signatures following the description above. However it is important that you follow the specification as closely as possible. To help in this, we have provided a sample solution as a BlueJ project with the source code removed. Please check carefully to make sure your program works exactly the sameas the sample solution.

Submission

  • From within your assignment 3 BlueJ project, select Project -> Create Jar File…
  • In the Dialog Box that appears:
    1. Set “Main Class” to none
    2. Ensure “Include Source” is checked
    3. Leave “Include Bluej project files” unchecked
    4. Press “Continue”
    5. Save the filename as “Assignment3.jar”
  • Open a web browser and go to the give web site
  • Log-in with you Z-Pass
  • Either enter “COMP1400″ in for the course and press “Search for Assignments”.
  • Select “Assignment3″ from the next drop down menu and press “Upload my Assignment”
  • Accept the student declaration
  • Press “Choose File” and select the “Assignment3.jar” file that you saved in step 4
  • Press “Submit my Files”
  • Wait for the page to completely load. Then carefully read the output. If the assignment is successful you should see the following lines:
    ================================================
    Checking your submission... 

    Checking for JobQueue.java
    JobQueue.java Compiled Sucessfully

    All files are OK
    ================================================
    If the page doesn’t load properly, that is OK just submit the assignment file again.
    If you don’t get the above output check the output to see what went wrong and resubmit.

Submission notes:

You can submit as many times as you wish, even after the deadline. Only your last submission will be marked.
Make sure you name everything the as instructed, including the classes and the submission file or the submission will not work.
If you have any problems with submission, email the class account. Include exact details of any error messages you get.

 

No Comments so far ↓

Comments are closed.