COMP1202 2012 13 Coursework
COMP1202 2012 13 Coursework
Information
Deadline: Wednesday 12th December 2012 at 17.00 via https://handin.ecs.soton.ac.uk Lecturers: David Millard, Mark Weal, Rikki Prince Value: 30% of the marks available for this module. This coursework is to be completed individually. Please note: Any alterations to the coursework and answers to frequently asked questions will be submitted to the course wiki: https://secure.ecs.soton.ac.uk/student/wiki/w/COMP1202/Coursework Coursework is the continuously assessed part of the examination, and is a required part of the degree assessment. Assessed work must be submitted as specified below. You are reminded to read all of the following instructions carefully.
Coursework Aims
This coursework allows you to demonstrate that you: Understand how to construct simple classes and implement methods. Are able to take simple pseudo-code descriptions and construct working Java code from them. Can write a working program to perform a complex task. Have an understanding of object oriented programming. Can correctly use polymorphism, exceptions and I/O. Can write code that it is understandable and confirms to good coding practice.
Contacts
General programming queries related to the coursework should be made to your demonstrator in the timetabled labs. Queries about the coursework specification should be made to Mark Weal ([email protected]). Any issues that may affect your ability to complete the coursework should be made known to Mark Weal ([email protected]) or David Millard ([email protected]), ideally before the submission deadline.
Specification
The aim of this coursework is to construct a virtual representation of an orchestra. This orchestra will consist of a number of musicians that each play part of a larger musical piece under the direction of a conductor. You are not required to have any musical knowledge in order to complete this coursework. The ECS orchestra may bear some similarities to a real orchestra but is very simplified and in some cases likely to be quite different to how a real orchestra might work. Your task is to implement the specification as written. No marks will be awarded for deviating from the specification in order to increase the realism of the orchestra in fact it may well cost you marks.
The next sections will take you through the construction of the various people in your orchestra. You are recommended to follow this sequence of development as it will allow you to slowly add more functionality and complexity to your orchestra.
Abstract
Musician
Extends Extends
Cellist
Violinist
Extends
LeadViolinist
Fig 1: Class diagram for the musician classes. The first class to create is the Musician class. This is an abstract class that defines the basic properties and methods that all the different musician classes will use. The properties that you will need to define are: instrument the type of instrument the musician plays. This is represented by an int. A mapping table of instruments can be found below. MAXNOTES our musicians cant play more than 100 notes before they get tired so a constant is needed to make sure no more than this many notes are contained in the music they are given to play.
soft and loud all our musicians can either play softly or loudly (represented by integer values). The volumes of these for some of the instruments are included in the instrument mapping table.
The abstract Musician class will also need to define some methods for use by the conductor. These methods can be overridden by the other musician classes. The methods you need to create are readMusic(array of ints), playNextNote(), getType(), playSoft()and playLoud(). You should now have a musician class. As we progress you may choose to add additional methods to your abstract class. Musician Violinist Cellist Trumpeter Pianist Instrument Violin Cello Trumpet Piano InstrumentID 41 43 57 1 Soft volume 50 50 100 75 Loud volume 100 100 200 150
You should now have an Orchestra class that you can add Musicians to. Musicians will need to know what seat they are sitting in and later it may be necessary to move musicians so you should add an additional method to the musician class called setSeat(int) that can be used to tell the musician what seat they are sitting in should they need to be moved. We should now move on and create some actual Musicians, but first a quick note on the SoundSystem.
You will now need to define the readMusic method. This is how the violinist receives their music. The method takes an array of integers as a parameter that represents the musical notes. These should be stored in the class. You will then need to define the playNextNote() method. The Violinist will need to keep track of which note was last played. When the playNextNote() method is called the Violinist will need to play the next note in the music (if there is one left) using the SoundSystem. To do this it calls the method soundSystem.playNote(seat,note,loudness); The loudness will either be loud or soft. For a violin useful starting settings for these would be 100 for loud and 50 for soft. A blank note (one not to be played) will be represented in the music by a 0. You will need to define methods to allow the conductor to indicate whether to play loud or soft. These methods should be called playLoud() and playSoft(). You should now have a Violinist class. You can now create other types of Musician for inclusion in your orchestra. Examples might include Cellists, Pianists and Trumpeters. You can test your Violinist using the test harness we have provided called TestViolin.java.
static int[] bubbles = new int[] {67,69,67,66,65,69,67,72,0,0,72,74,72,71,72,69,67}; A zero means that the musician shouldnt play a note at that point. For those of you interested, the table below shows you one octave of the mappings between note values and their corresponding notes. Middle C is note 60. Complete mappings can be found here.
Note Value
C 60
C# 61
D 62
D# 63
E 64
F 65
F# 66
G 67
G# 68
A 69
A# 70
B 71
You can pass an array of notes to the musician using the readMusic() method you created. Dont forget to pass the SoundSystem to the musicians in their constructors, they will require it to play their notes. Once you have created a musician you can add them to your orchestra using the addMusician() method in the orchestra object. Once you have a fully set up orchestra you can then get them to play. To do this, the conductor should loop over all the notes in the music and for each note call the playNote() method on each Musician. To make sure the music is played at a sensible pace, the conductor should pause between the playing of each set of notes. To do this, you can use the following piece of code. It tells the conductor to go to sleep for half a second and then wake up again. You can put the code at the end of your loop. try { Thread.sleep(500); } catch (InterruptedException e) { } You may find for your music half a second is too long to wait so feel free to adjust this to your liking.
You should now have a working Conductor class and hopefully an orchestra that is playing sweet music (well MIDI at least.)
Some example music files of varying complexity will be found on the WIKI. You should modify the main method in your Conductor class so that it can take a file on the command line. This will enable you to start your conductor by typing java conductor mymusic.mus When the conductor receives the music it should read the music file a line at a time. For each line the conductor will need to identify the musician, create a new musician of this type, set the volume of the musician and give the musician their music to play. You may wish to create specific methods or indeed a helper class, to parse the music file and extract the information that the conductor needs. Once the orchestra has been successfully created the conductor can then get the musicians to play the music.
Exceptions
You should be appropriately using exceptions in the construction of your orchestra. You might consider the use of exceptions to correctly manage: The input of music that does not conform to the specified file format. Attempts to add more than sixteen musicians. Attempting to conduct an empty orchestra. Cases where musicians run out of music to play.
Extensions
You are free to extend your code beyond the basic orchestra as described above. You are advised that your extensions should not alter the basic structures and methods described above as marking will be looking to see that you have met the specification as we have described it. If you are in any doubt about the alterations you are making please include your extended version in a separate directory. Some extensions that we would heartily recommend include: Try modifying the conductor so that instead of sleeping for a period of time the next note is triggered by input from the user. That way, you can perform the role of conductor yourself. Try adding a new musician KeyboardPlayer. This musician has the ability to pretend to be any other musician through the magic of MIDI. They will need an additional method selectInstrument(instrumentID) that allows the Conductor to tell them which instrument to pretend to be. A Conductor could fill their entire Orchestra with keyboard players if they wished. Try extending the music notation format in interesting ways. Currently instruments are either loud or soft for the entire duration of the performance; perhaps you want the conductor to be able to change whether an instrument plays loudly or softly during the performance. This will require the conductor holding additional information about when to tell musicians to change the way they are playing. You could provide support to pause, rewind or jump to a particular point in a song.
15% of the marks are available for implementing extensions. Any of the above examples would be suitable, it is not necessary to attempt multiple extensions in order to gain these marks.
Space Cadets
You might want to add a GUI to your Orchestra to enable the user to carry out the various acts of a Conductor. No marks are available for a GUI, we put the suggestion forward simply for the challenge of it.
Marking
Marks are available for: Applications that compile and run Meeting the specification properly Successful completion of one or more extensions Good coding style Good comments in your source code
Submission
Submit all Java source files you have written for this coursework in a zip file orchestra.zip. Do not submit class files. As a minimum this will be: Musician.java, Violinist.java, Cellist.java, Orchestra.java, Conductor.java,LeadViolinist.java Also include a text file orchestra.txt that contains a brief listing of the parts of the coursework you have attempted. Submit your files by Wednesday 12th December 2012 17:00 to: https://handin.ecs.soton.ac.uk
Originality of Work
Students' attention is drawn to Section IV of the University Calendar on Academic Integrity: http://www.calendar.soton.ac.uk/sectionIV/part8a.html