CE 152 Object-Oriented Programming
Spring Term 2015 Module Supervisor: Paul Scott
Assignment 2
This assignment is worth 20% of the marks for the course
Deadline: 11:59:59 am, April 20th 2015
Module Web Pages:
A copy of this assignment is on the Assignments page of CE152 web site. You will need to use this to access the files required for Task 2.
Submission:
The assignment should be submitted through the Online Coursework Submission System (OCS). Your submission should comprise a single zip file containing the source code (i.e. the .java files) for all the classes that you have written as solutions to the assignment tasks.
The name of your zip file should include both your name and your registration number.
If you fail to submit your solutions by the deadline, you will receive zero for the assignment even if you subsequently demonstrate them in the labs. Please refer to the Undergraduate Students Handbook for details of the Departmental policy regarding late submission (pages 20-21).
If you do not submit the source files (i.e. the .java files) you will receive zero for the assignment .
Demonstration:
You will be required to demonstrate your solutions to the assignment tasks. A time will be allocated for your demonstration during resit examination week. If you fail to attend for your demonstration at the allocated time, you will receive zero for the assignmenteven if you have submitted solutions before the deadline.
You will be expected to demonstrate your solutions on the lab machines using IntelliJ .If you have developed your programs on another machine, please allow time to port them before the time scheduled for your demo.
All the classes that comprise your solutions plus the two supplied test classes should be in the same IntelliJ project for your demonstration.
The solutions that you demonstrate must be those that you submitted by FASER before the deadline. Any attempt to demonstrate work that has been improved since the deadline may result in a mark of zero for the whole assignment .
Originality:
Your solutions should be your own unaided work. Please refer to the Undergraduate Students Handbook for details of the University regulations regarding plagiarism (pages 54-57).
The Assignment Tasks:
The assignment comprises four tasks.
Task 1: Adding error handling to MyArrayList [10%]
Note: This task requires material that was covered in Lecture 10.
For this task you are asked to add some error handling to the MyArrayListclass that you implemented as Task 5 of Assignment 1. Your starting point can be either your own solution to that task or the model answer posted on the module website. Your choice will make no difference to the mark you receive.
Some of the methods of Javas ArrayListthrow an IndexOutOfBoundsExceptionif a method is called with an index argument that requires it to access an element of the list that does not in fact exist. For this task you should modify those methods so that they throw an IndexOutOfBoundsExceptionwith a message that indicates the method where the problem occurred. If you are not sure which methods should throw such an exception and when, you can check the API documentation for ArrayList. It is not necessary to deal with any methods other than those required by Task 5 of Assignment 1.
A test class, Task1Test, will be made available on the module website during the last week of Spring term.
Task 2: Marks Processing [30%]
Note: This task requires material that was covered in Lecture 11.
Students taking the first year of a degree in Irrational Studies take two modules: IR101 and IR102. The rules of assessment stipulate the following:
Students must pass both modules in order to proceed to Stage 2.
The pass mark for a module is 40.
Students who do not pass both modules will be deemed to have failed.
Students who fail only one of the two modules will be allowed a resit attempt.
Students who fail both modules will be required to repeat the year.
Students who pass both modules will be awarded a class based on their aggregate mark using the following scale:
70 100 1st
60 69.9 2.1
50 59.9 2.2
40 49.9 3rd
The aggregate mark is the mean of the two module marks
A list of students taking Irrational Studies is contained in the following file. Each line of the file contains a student id number (an integer) followed by the students name (a string).
The marks obtained by the students are contained in the following two files. Each line contains the students id number followed by the mark they obtained (a double). (Note that the students do not appear in the same order in the three files.)
You should make copies of these three files in any convenient directory on your M drive.
Your task is to write a program that reads in the information from the three files and outputs a list of transcripts, ordered in descending order of aggregate mark, to a file in the current directory called RankedList.txt.
A transcript comprises three lines:
Line 1: Student id followed by student name
Line 2: Both module marks followed by the aggregate mark
Marks should show one digit after the decimal point.
Line 3: The class and the outcome.
The class should be Fail, 3rd, 2.1, 2.2, or 1st.
The outcome should be Repeat Year, Resit a specified exam or Proceed to Stage 2.
In the transcript list, each transcript should be separated by a row of -. The following is an example extract from such a list:
37695 Aristotle
IR101 52.0 IR102 49.8 Aggregate 50.9
Class: 2.2 Outcome: Proceed to Stage 2
–
37622 Socrates
IR101 38.3 IR102 47.5 Aggregate 42.9
Class: Fail Outcome: Resit IR101
–
You may assume that the input file contains no errors.
Task 3: Belisha Beacon [30%]
Note: This task requires material that will be covered in Lectures 12, 13 and 14.
For this task you should create a class called BelishaBeaconthat provides a 2D graphical animation of the flashing orange lights that are used to mark the location of pedestrian crossings often called Belisha Beacons (in honour of the Minister of Transport who introduced them).
When the class is run it should display a window similar to the following:
Initially the lamp should flash; that is, its colour should alternate between orange and light grey with a period of about half a second. When the Steady button is clicked the flashing should stop and the lamp remain permanently on (i.e. orange); when the Flash button is pressed, the lamp should resume flashing. Closing the window should terminate the program.
You may use the code included in Lecture 14 as a starting point for this task.
Task 4: Adding an iterator to MyArrayList [30%]
Note: This task requires material that will be covered in Lecture 16.
Like Task 1, this task asks you to extend the functionality of the MyArrayListclass specified for Task 5 of Assignment 1. Your solution to Task 1 (of this assignment) should be your starting point.
The MyArrayListpresented as a model solution to Task 5 of Assignment 1 could not be used in a for-each loop such as:
for(Object animal: zoo) System.out.println(animal);
where zoois an instance of MyArrayList. Your solution almost certainly suffered from the same limitation. This is because the for-each loop construct requires that the object through which it iterates implements the java.lang.Iterableinterface. For this task you asked to modify MyArrayListso it implements this interface.
To do this requires rather more than simply changing the class signature to:
public class MyArrayList implements Iterable
To find out what, you will have to consult the API documentation for Iterable.You will find that you must supply a method that returns an instance of a class that implements the Iteratorinterface. To do this you will have to create such a class. The obvious place to do this is to make it an inner class of MyArrayList. Again, you will have to consult the API documentation to find out what is entailed in implementing the Iteratorinterface.
Provided you have done all this correctly, and the methods you provide to the class that implements Iteratordo what they should, you will be able to use your MyArrayListin a for-each construct.
A test class, Task4Test, will be made available on the module website during the last week of Spring term.
Note that your solution need only include one version of MyArrayListincluding the modifications required by Tasks 1 and 4 of this assignment.
Assessment Criteria
Task1: Adding error handling to MyArrayList
Based entirely on correct behaviour.
Task 2: Marks Processing
Based entirely on correct behaviour. Any program that behaves exactly as required will get the full 40%. Partial credit may be given for programs that produce partial or incorrect output or do not format the output correctly.
Task 3: Controlled Ball
Based entirely on correct behaviour.
15% will be awarded for a solution that correctly displays a window with a frame that contains a suitable image.
A further 15% will be awarded for correct behaviour in response to button clicks.
Task 4: Adding an iterator to MyArrayList
Based entirely on correct behaviour.
Reviews
There are no reviews yet.