Sei sulla pagina 1di 9

COM1027

Programming Fundamentals
Summative Coursework

Working with Nested Collection Classes

Handout Date: Monday 28th November 2016
Deadline: Monday 19th December 2016 at 16:00 via SurreyLearn
Feedback: Individually via SurreyLearn
Module Weight: 40%

Academic Misconduct: Coursework will be routinely checked for academic misconduct.
Your submission must be your own work. Please read the Student Handbook to ensure that
you know what this means. Do not give your code to anyone else, either before or after the
coursework deadline.

Please read this sheet thoroughly and carefully. Many of the issues encountered in the
formative coursework came from misreading the UML diagram or missing out steps in the
instructions, so you can save a lot of hassle by digesting everything before you start to code.

Introduction

The purpose of this coursework is for you to demonstrate your ability to:

Manipulate collections of objects, lists and maps
Implement an inheritance hierarchy
Use JUnit to define your own test classes
Throw exceptions
Write code to conform to an interface contract

This should help you consolidate your understanding of inheritance and develop your use of
algorithms to manipulate nested data structures.

You will receive a mark and individual feedback via SurreyLearn. The mark scheme is
available in a separate document. This is a summative piece of work, so your mark will
contribute up to 40% of the mark for this module.

You are required to capture the following problem using Eclipse. We have provided a set of
test classes as part of the coursework package. You will need to add your own test class as
you implement your solution.





ST / November 2016 1
Problem Definition

You must develop Java code that allows a dancing competition to be modelled. This is based
loosely on the BBCs Strictly Come Dancing show, but with some significant differences.

A competition consists of a number of pro-celebrity couples, and each week the couples
perform one dance, for which they obtain a score. Each week the two couples with the
lowest score perform a dance off, and one of them is eliminated. The remaining couples go
through to the following week and dance again. When only two couples remain, they
perform a final dance and the couple with the best score for their dance wins the
competition. Note that this differs from the BBC show, so you should base your code on the
specification below and the test cases provided.

A professional dancer has a name and nationality
A celebrity dancer has a name and role (such as actor, model, athlete, etc.)
A couple consists of one professional dancer and one celebrity dancer
A couple performs a different dance each week, and this is stored by the system
Each dance is given a score that combines individual scores from the judges and
viewer vote, and this is stored by the system
The system will be able to list the dances performed by a couple, and calculate how
many dances were performed by a couple
The system will be able to say whether or not a couple danced a particular dance
The system will be able to retrieve judges, viewer and overall scores for a particular
dance by a couple
Given a week number, the system will be able to retrieve the dance and score for a
couple
The system will be able to compare two overall scores to see which is better, and in
the event of a tie the viewer score will always take precedence
A competition can in theory have any number of couples
A couple cannot be added to the competition if they are already in it
A professional dancer cannot belong to more than one couple
A celebrity dancer cannot belong to more than one couple
The system will be able to display the week in which a particular couple were
eliminated
The system will be able to display the overall winning couple for the competition
The system will be able to display the couples and their dances for a given week

Commenting Code

In this coursework we want you to spend time writing code and understanding how to
develop algorithms for nested data structures. Therefore you do not need to comment
every class. However, we do want to see that you understand how to write useful
comments, so please include them in the Couple class only. You can of course include
comments in any class if they help you to develop the solution.

ST / November 2016 2
Create a New Eclipse Project

Download the skeleton code for this coursework. It contains the test classes and a package
structure for each question. Import the zip file into your Eclipse workspace in the usual way.
Refactor the project name to include your own username.

Refactor the package names to include your username. Remember that some lines might be
hidden by default, so click the plus symbol to expand all the import statements.

Question 1

The classes for this question are shown in the diagram below. You should write the code
that implements this structure. Place your code in the q1 folder within the package.

<< enum >> Celeb Pro << enum >>
Dance - name : String - name : String Nationality
WALTZ - role : String - nation : Nationality EN
CHACHA + getInfo() : String + getInfo() : String RU
QUICKSTEP + toString() : String + toString() : String AU
RUMBA SI
TANGO IT
JIVE US
FOXTROT UA
PASODOBLE - nation : String
SAMBA
SALSA


Define the Dance and Nationality Enumerations

Define a new Java enumeration called Dance
Define a new Java enumeration called Nationality
Include the following values for the Nationality enumeration
EN = English; RU = Russian; AU = Australian; SI = Slovenian; IT = Italian;
US = American; UA = Ukrainian

Define the Celeb and Pro Classes

Define a new Java class called Celeb
Define a new Java class called Pro
Add the necessary fields and methods to the class definitions

Define the ProTest Class

Define a new test class called ProTest and place this in the correct folder within the
package (checking the toString method outputs their name and full nationality)

After completing the code, test it against the test classes provided for this question.
Remember that if you see any errors in the test classes, this is because you have probably

ST / November 2016 3
misread the UML diagram or instructions, or forgotten to change the package and import
statements to include your username.

Question 2

Copy your Code

Copy your source code from the q1 folder to the q2 folder
Make sure all package names refer to the correct version

The classes for this question are shown in the diagram below. You should write the code
that implements this structure. Refactor your code in the q2 folder within the package.

Couple
- pro : Dancer
- celeb : Dancer
- dances : List<Dance>
+ haveDanced(in Dance) : boolean
+ addDance(in Dance) : void
+ getDances() : String
+ toString() : String
1

2
<< enum >> Dancer << enum >>
Dance - name : String Nationality
WALTZ + getInfo() : String EN
CHACHA + toString() : String RU
QUICKSTEP AU
RUMBA SI
TANGO IT
JIVE US
FOXTROT Celeb Pro UA
PASODOBLE - role : String - nation : Nationality - nation : String
SAMBA + getInfo() : String + getInfo() : String
SALSA


Define the Dancer Class and Refactor the Celeb and Pro Classes

Define a new Java class called Dancer
Refactor the Celeb and Pro classes to reflect the inheritance structure shown in the
diagram

Define the Couple class

This class stores information about the dances a couple has performed. They are stored in a
list in the order of performance. In other words, the dance performed in week two of a
competition will be the second item in the list.

Define a new class called Couple
Add the required fields to the class

ST / November 2016 4
Add the haveDanced method This should return true if the given dance has been
danced by the couple, or false otherwise
Add the addDance method This should add the given dance to the list of dances,
but only if it has not already been danced by the couple
Add the getDances method This should return a newline-delimited string of
everything danced by the couple, such as:

JIVE
QUICKSTEP
TANGO

Add the toString method This should combine both dancers names, such as:

Aljaz Skorjanec & Daisy Lowe

Perform Correct Validation

Look at the code in the CoupleTest class and ensure your Couple class throws the necessary
exceptions, otherwise the tests will fail. In particular this means:

a couple cannot be created with invalid (null) parameters
a couple cannot do the same dance more than once

After completing the code, test it against the test classes provided for this question. Looking
at the format of the test classes will give you an insight into how to write the correct code.

Question 3

Copy your Code

Copy your source code from the q2 folder to the q3 folder
Make sure all package names refer to the correct version

The classes for this question are shown in the diagram on the next page. You should write
the code that implements this structure. Refactor your code in the q3 folder within the
package.

Define the Score Class

This class should implement the Comparable interface, to enable scores to be compared to
each other (ie. less than, equal to, greater than).

Add the required fields The class should store a judges score and a viewer score,
both of which should be within the range 0 to 10
Add the getOverallScore method This should return the combined scores
Implement the compareTo method When comparing two Score objects with the
same overall score, the viewer score should take precedence over the judges score

ST / November 2016 5
Competition
- name : String
- couples : List<Couple>
+ addCouple(in Couple) : void
+ setCoupleDanceScore(in Couple, in Dance, in Score) : void 1
+ getEliminationWeek(in Couple) : int
+ displayDanceListWeek(in int) : void
+ displayWinningCouple() : void
+ displayDanceOff(in int) : void
+ displayBestCoupleDance(in Dance) : void
+ displayLeaderboardWeek(in int) : void
*
Couple
- pro : Dancer
T - celeb : Dancer
<< interface >> - dances : List<Dance>
Comparable - scores : Map<Dance,Score>
+ compareTo(in T) : int 1 + haveDanced(in Dance) : boolean
+ addDanceScore(in Dance, in Score) : void
+ getDanceScore(in Dance) : Score
<< bind T :: Score >>
+ getDanceCount() : int
+ getScoreWeek(in int) : Score
+ getDanceWeek(in int) : Dance
Score
+ getDances() : String
- judges : int * + toString() : String
- viewer : int
+ getOverallScore() : int 1
+ compareTo(in Score) : int

2
<< enum >> Dancer << enum >>
Dance - name : String Nationality
WALTZ + getInfo() : String EN
CHACHA + toString() : String RU
QUICKSTEP AU
RUMBA SI
TANGO IT
JIVE US
FOXTROT Celeb Pro UA
PASODOBLE - role : String - nation : Nationality - nation : String
SAMBA + getInfo() : String + getInfo() : String
SALSA


Refactor the Couple Class

The Couple class should now also store the score for each dance, using a Map data
structure. It has some additional methods that make use of this data.

Refactor the addDance method into addDanceScore This should now also record
the score for the given dance
Add the getDanceScore method and the getDanceCount method
Add the getDanceWeek method Should return the couples dance for a given week
Add the getScoreWeek method Should return the couples score for a given week

Where these methods return an object, you should return null if the couple did not perform
a dance in the given week (ie. they were eliminated) or have not done the given dance at all.

ST / November 2016 6
Perform Correct Validation

Look at the code in the CoupleTest class and ensure your Couple class throws the necessary
exceptions, otherwise the tests will fail. In particular this means:

a score cannot be retrieved for a week that is out of range
a dance cannot be retrieved for a week that is out of range

After completing the code, test it against the test classes provided for this question. Looking
at the format of the test classes will give you an insight into how to write the correct code.

Define the Competition Class

This class stores a list of couples in the dancing competition, along with the name of the
competition. The methods in this class require you to navigate the nested data structures so
the relevant information can be displayed.

Add the addCouple method
Add the setCoupleDanceScore method This should store the given dance and score
for the appropriate couple
Add the getEliminationWeek method This should return the week number in which
the given couple were eliminated from the competition
Add the displayDanceListWeek method This should display on the console all the
couples and their dances for a given week, such as:

Strictly Come Dancing: Dance List (Week 1)
AJ Pritchard & Claudia Fragapane (CHACHA)
Oksana Platero & Robert Rinder (FOXTROT)
Aljaz Skorjanec & Daisy Lowe (JIVE)
Katya Jones & Ed Balls (QUICKSTEP)
Kevin Clifton & Louise Redknapp (RUMBA)
Natalie Lowe & Greg Rutherford (SALSA)

Add the displayWinningCouple method This should find the week in which only
two couples remained in the competition, and display the one with the best score,
such as:

Strictly Come Dancing: Winning Couple
Aljaz Skorjanec & Daisy Lowe (18)

For this question, you do not need to implement the methods shown in red on the
diagram.





ST / November 2016 7
Question 4 Optional Extra Tasks

Copy your Code

Copy your source code from the q3 folder to the q4 folder
Make sure all package names refer to the correct version

Choose TWO of these tasks and implement them to gain marks that you might have lost in
earlier questions. Make sure you edit the code within the q4 folder. If you implement more
than two of these tasks, we will use the marks from the best two.

Optional Extra Task for the Dancer and Couple Classes

Refactor the Dancer and Couple classes so that a gender is stored for each dancer,
and throw an exception if a couple is created that is not male/female

If you choose this task, you will need to modify the associated test classes to include
relevant assertions and check the thrown exception.

Optional Extra Tasks for the Competition Class

Look at the CompetitionTest class and uncomment the exception test cases, then
ensure each method in the Competition class throws the appropriate exceptions
Add the displayDanceOff method This should display the two lowest-scoring
couples for a given week, such as:

Strictly Come Dancing: Dance Off (Week 4)
Aljaz Skorjanec & Daisy Lowe (15)
Katya Jones & Ed Balls (11)

Add the displayBestCoupleDance method This should display the name of the
couple who scored best for a given dance, such as:

Strictly Come Dancing: Best Score (WALTZ)
Natalie Lowe & Greg Rutherford (16)

Add the displayLeaderboardWeek method This should display an ordered list of
couples with their scores for a given week, such as:

Strictly Come Dancing: Leaderboard (Week 3)
Natalie Lowe & Greg Rutherford (15)
Aljaz Skorjanec & Daisy Lowe (14)
Katya Jones & Ed Balls (12)
AJ Pritchard & Claudia Fragapane (10)

You should uncomment the relevant method calls in the CompetitionTest class, so you can
see if the output matches what is expected. You can define a helper class and/or private
methods if it makes any of these tasks easier.

ST / November 2016 8
What to Submit

Your code must be exported from Eclipse as an archive, including all source and test classes.
There is a help sheet on SurreyLearn that explains how to do this. Name your archive file
username_com1027_summative.zip (making sure to use your own username). Upload this
file to the submission area on SurreyLearn.




Use the discussion forum on SurreyLearn to ask questions about this coursework.

ST / November 2016 9

Potrebbero piacerti anche