Object Oriented Programming and Design

University of Westminster

Department of Computer Science

5COSC001W Object Oriented Programming – Coursework 2 (2017/18)

Module leader

Barbara Villarini


Coursework 2



Qualifying mark



Object Oriented Programming and Design

Learning Outcomes Covered in this Assignment:

This assignment contributes towards the following Learning Outcomes (LOs):

LO1  Identify and justify good practices in the development of object oriented software; 

LO2  Apply acquired knowledge of concepts, characteristics, tools and environments to adapt to new computational environments and programming languages which are based on object oriented principles; 

LO3  Design, implement efficiently and test applications based on a OOP language, given a set of functional requirements. Describe the aspects of object oriented programming which are advantageous when compared to non-object oriented paradigms. Use APIs which have not been exposed to previously, in order to develop an application requiring specialised functionality; 

LO4  Implement GUI interfaces using an OOP language; 

LO5  Describe and justify the basic principles and the need of concurrency and how threads can 
be implemented in an OOP language. 

Handed Out:

13th November 2017

Due Date

Monday 11 December 2017 Submissions by 10:00am

Expected deliverables

Submit on Blackboard a zip file containing:

A folder with all the UML documents attached

A folder with the developed project

Method of Submission:

Electronic submission on BB via a provided link close to the submission time.

Type of Feedback and Due Date:

Written feedback by 04/01/2018 and generic feedback during the demonstration.


2.1.1 Knowledge and understanding of facts, concepts, principles & theories

2.1.2 Use of such knowledge in modelling and design

2.1.3 Problem solving strategies

2.2.1 Specify, design or construct computer-based systems

2.2.4 Deploy tools effectively

2.3.2 Development of general transferable skills

3.1.1 Deploy systems to meet business goals

4.1.1 Knowledge and understanding of scientific and engineering principles

4.1.3 Knowledge and understanding of computational modelling

Assessment regulations

Refer to section 4 of the “How you study” guide for undergraduate students for a clarification of how you are assessed, penalties and late submissions, what constitutes plagiarism etc.

Penalty for Late Submission

If you submit your coursework late but within 24 hours or one working day of the specified deadline, 10 marks will be deducted from the final mark, as a penalty for late submission, except for work which obtains a mark in the range 40 – 49%, in which case the mark will be capped at the pass mark (40%). If you submit your coursework more than 24 hours or more than one working day after the specified deadline you will be given a mark of zero for the work in question unless a claim of Mitigating Circumstances has been submitted and accepted as valid.

It is recognised that on occasion, illness or a personal crisis can mean that you fail to submit a piece of work on time. In such cases you must inform the Campus Office in writing on a mitigating circumstances form, giving the reason for your late or non-submission. You must provide relevant documentary evidence with the form. This information will be reported to the relevant Assessment Board that will decide whether the mark of zero shall stand. For more detailed information regarding University Assessment Regulations, please refer to the following website:http://www.westminster.ac.uk/study/current-students/resources/academic-regulations

Coursework Description


The aim of this assessment is to evaluate your skills in developing Graphical User Interface using Object Oriented Principles. You will be asked to implement a game application using Java following the requirements described below.

Analyze the statement:

Analyze the problem statement in order to identify the details needed to develop a solution.

In this assignment the first task you should perform is a carful analysis of the problem statement in order to make sure you have all the information to elaborate a solution. If you are not sure about the information provided ask questions.

Design a solution:

The design of your system should be consistent with the Object Oriented principles and easy to understand by an independent programmer.

You are required to design your program using an UML class diagram (4 marks).

Handle Errors and Exceptions

You are required to write a robust code. Keep in mind to handle the errors and exceptions during the development of your application (4 marks).

Problem description and requirement statement

You are required to complete a Java program that implements a Slot Machine application.

In your GUI application you should be able to resize the window of your application keeping the component in the same “relative” position (6 marks).

Also note that all code must be manually written, do not use any tools that generates code automatically. You are NOT allowed to use design tools with drag and drop functionality (such as those found in Netbeans) to create the graphical user interface for any part of this coursework!

You must follow the specification below for the implementation of the GUI and the program.

Winning or Losing the game

In the reel can appear one of six different symbols. You can download the image for each symbol from the link “Images” that you find in Blackboard under “Assessment Details” -> “Assignment 2”. To win a game, the symbols on two or all three reels must be the same when the reels are stopped. The payout in credits for each of the symbols is as follows.

Seven: 7

Bell: 6

Watermelon: 5

Plum: 4

Lemon: 3

Cherry: 2

So, for example, say you start the game and you have your initial 10 credits. You bet 3 credits, so you now have 7 credits (your bet was deposited in the machine). You spin the reels, and when they stop, they are all watermelons. You have won 15 credits (the 3 you bet multiplied by the 5 credits that a watermelon is worth). The 15 credits are then added to your 7 credits, giving you a total of 22 credits.

When none of the reels match, you lose. The credits that you bet are left in the machine.


The GUI has to present the following graphical component (67 marks):

An “Add coin” button: this lets the user to add a coin to the credit

A “Credit Area”: this informs the user of the number of credits that he/she has left to play with. Note that you can’t continue to play with no credits. When you begin the program, you are given 10 free credits.

A “Bet One” button: This allows the user to bet a single credit.

A “Bet Max” button: This allows the user to add a maximum number of credits in the bet. The maximum number of credits is permanently set to 3. This button is just a convenience, as you may add more credits if you like by clicking the “Bet One” button.

A “Reset” button. This allows the user to return the amount that he/she has bet to the credits that he/she still has.

A “Spin” button. This causes the three reels to spin.

A “Bet area”. This informs the user of the number of credits that he/she is betting on the current game.

Three reels. When the Spin button is clicked, all three reels will begin to spin. To stop the reels from spinning, you can simply click on any of them.

Statistics” button: This allows the user to check his/her number of wins, losses, and the average number of credits that she/he has netted per game. If the average is positive, then the player has been, on average, winning more credits than losing. If it is negative, then the player has been, on average, losing more credits than winning.

A game is over after all three reels have been clicked and have stopped spinning. The results of the game will be displayed.

Note that you cannot play if your credit is zero or if your bet is zero.

1) Create an interface ISymbol, which contains the following methods:

setImage(…), which sets the image associated with one of the symbols in a reel, represented by the Symbol class implementing the interface.

getImage(), which return the image.

setValue(int v) which sets the value of the symbol as defined above.

getValue(), which returns the value of the symbol.

2) Create a class Symbol, which represents one of the symbols in a reel and implements the ISymbol interface.

3) Design and implement a class Reel which contains a list of 6 instances of Symbol objects each one of them having a different value (implement the 6 symbols defined above). 
The class should include a method spin() which returns the list with the six symbol. The array should be randomly populated and the position of the symbols should change every time a new reel is created.

You must use one of the API container class to hold the three reels.

The class may contain any additional methods that you choose as appropriate and necessary for the rest of your game application.

The SlotMachine GUI application has to follow the requirements below:

5) Press the “Add Coin” button to add one coin to the credit. Every time the game starts the initial credit is 10. (e.g. If you want credit equal 15 you need to press five times the “Add Coin” button).

6) Display a “Credit Area” where the user can visualize the current credit. Note that you cannot continue to play with no credits. When you begin the program, you are given 10 free credits. If the user tries to play with no credit the application will show a warning message.

7) Display a “Bet area” to inform the user of the number of credits that he/she is betting on the current game.

8) Pressing the “Bet One” button the user bet a single credit. The number in the bet area is incremented by one.

9) Pressing “Bet Max” button the user adds a maximum number of credits to the bet. The maximum number of credits is permanently set to 3. This button is just a convenience, as you may add more credits if you like by clicking the “Bet One” button.

10) Implement a “Reset” button to allow the user to return the amount that he/she has bet to the credits area.

11) Pressing the “Spin button” each reel will show a new symbol, selected randomly among the 6 symbols above.

12) If two or three symbols in the three reels are the same the game is won. Compute the amount of money that are won and add them to the credit. Implement a method in the class Symbol to compare two symbols. If the user lost the game (three different symbols) the amount bet is lost and the bet area displays zero.

13) Modify the implementation in section 11) when the user press the “Spin” button. When the button is pressed the three reels start to spin. In each reel the images of the 6 symbols are visualized continually simulating a real spinning behavior. That means that once the reel starts to spin you will see appearing in sequence all the six symbol. The three reels are spinning at the same time but they show different random sequence of symbols. Implement the spinning in three different threads.

12) When the Spin button is clicked, all three reels will begin to spin. To stop a reel from spinning, simply click on one of them. (To stop the threads, do not use the stop method, which has been deprecated.)

13) Display the message “You win!” and the amount of money won, when the user win, or “You lose” if the user lost the game.

14) Pressing “Statistics button” a new window will be opened. In this window the user can check the wins, losses, and the average number of credits that he/she has netted per game. You can choose how to visualize this information in the windows. Write in the comment which graphical component you chose and explain the reason.

15) In the “Statistics Window” has to be a button call “Save statistics”. Pressing this button the statistics will be saved in a .txt file in the current path. The name of the file has to be the current date/time.

16) Analyzing the winning combinations, model the slot machine in order to assure a payout of approximately 90%. Develop and implement the algorithm that computes the payout based on the model that you identified.

This assignment is evaluated also based on the following:

Code readability (structure, comments, naming, etc.) (4 marks)

Code reusability, efficiency, etc. (10 marks)

Quality of the GUI (5 marks)

Understanding of the code (10 marks)