0% found this document useful (0 votes)
149 views10 pages

COMP1202 2012 13 Coursework

This document provides specifications for a coursework assignment to create a virtual orchestra in Java. The orchestra will consist of different types of musicians (violinist, cellist, etc.), organized into an orchestra with seats. A conductor will direct the musicians by providing music for them to play. Students are tasked with implementing classes for Musician, Violinist, Cellist, Orchestra, Conductor, and utilizing a provided SoundSystem class to play the music. The document outlines the requirements and properties for each class, how they relate through inheritance, and how the classes should interact to model the functioning of the orchestra.

Uploaded by

900kronor
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
149 views10 pages

COMP1202 2012 13 Coursework

This document provides specifications for a coursework assignment to create a virtual orchestra in Java. The orchestra will consist of different types of musicians (violinist, cellist, etc.), organized into an orchestra with seats. A conductor will direct the musicians by providing music for them to play. Students are tasked with implementing classes for Musician, Violinist, Cellist, Orchestra, Conductor, and utilizing a provided SoundSystem class to play the music. The document outlines the requirements and properties for each class, how they relate through inheritance, and how the classes should interact to model the functioning of the orchestra.

Uploaded by

900kronor
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

COMP1202 Coursework 2012/13

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.

How the ECS Orchestra Works


For this coursework you are expected to follow the specification of the orchestra as set out below. This may not correspond exactly an orchestra in reality but we have chosen particular aspects for you to model that help you to demonstrate your Java Programming. There are a number of people and objects that contribute to an orchestra. For our purposes these include: a Musician: This is any individual that plays an instrument in the orchestra. You will define a musician as an abstract class as all the musicians will share common properties and methods but these may have different values and be implemented in different ways. Musicians will have an instrument that they can play softly or loudly. a Violinist: As an example of a musician you will need to create a class representing a violinist. a Cellist: Other musicians will also be required, for example a cellist might go very nicely with the violinist. an Orchestra: Different musicians will be collected together into an orchestra. These could potentially be very large, but for pragmatic reasons our orchestra has only 16 seats in it. a Conductor: In order to tell the musicians what to play it will be necessary to have a conductor. Their job will be to arrange the musicians in the orchestra and to give the musicians their particular piece of music to play. They will also instruct the musicians when to play each note. a Lead Violinist: This is a specialist type of violinist. Their job is to lead all the other musicians in the orchestra. The conductor tells the lead violinist when to play and they in turn then give the cue to all the other musicians to play their notes. Not all orchestras need to have a lead violinist but the best orchestras tend to have one. a SoundSystem: This allows the musicians to play music through the computer. This class is supplied to you and instructions below tell you how to utilise it.

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.

Part 1 Modelling the Musician


To model the various types of musician you will need for your orchestra (Violinist, Cellist and LeadViolinist) you will need to use inheritance. You can create additional musicians if you choose and a table of instrument mappings is provided for you. The following simple diagram shows you how the minimum four classes that you will create are related to each other.

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

Table 1: Musicians and their settings

Part 2 Modelling the Orchestra


Our Orchestra class is where all our Musicians will be added. You should use an ArrayList to represent the sixteen seats (1-16) in the orchestra (our SoundSystem cant handle more seats than this.) The Orchestra needs a number of access methods. These should include: addMusician(musician) this adds the Musician into the next available seat. addMusician(musician,seatNo) this adds the Musician into the specified seat. If another Musician is already sat there then they are returned by the method. This method also allows us to make sure our LeadViolinist is always in seat 1. size() this returns the number of seated musicians in the Orchestra. getMusician(seatNo) this returns the Musician in the specified seat number.

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.

A note on the SoundSystem


In order to remove some of the complexity of using MIDI in this coursework we have supplied you with a class that carries out the interactions with the MIDI system. MIDI is a set of standard commands that enables devices to communicate musical information to each other. In this coursework your orchestra will instruct the computer to play musical notes using the standard MIDI interface through this soundSystem. If you are interested feel free to read more about MIDI but it shouldnt be necessary to complete this coursework. To use this class you will need to initialise it correctly and pass an instance of the class to your Musicians. It is important that only one instance of this class is created. Think of it like your conductor switching on the SoundSystem and then passing a microphone to each of the Musicians for them to use. Musicians shouldnt create their own instance of the SoundSystem. To setup the SoundSystem you will need to. Create a new instance of the SoundSystem in your Conductor class using: soundSystem = new SoundSystem(); Call the init function on the SoundSystem when you initialise your conductor using: soundSystem.init(); You can get the SoundSystem to work in silent mode by calling soundSystem.init(false), which instructs it to write the notes to the standard output rather than playing them with MIDI. Pass the SoundSystem to your musicians in their constructors. Your musician can then set its instrument in the SoundSystem by telling it which instrument it is and in which seat it is sitting using: soundSystem.setInstrument(seat, instrument); Everything is now initialised and your musicians can call the playNote() method in the SoundSystem when they are requested to play a note. We will remind you of these steps as we proceed through the following parts.

Part 3 Modelling the Violinist


Your Violinist is an extension of the Musician class. You will need to create a constructor for the class that takes a SoundSystem and a seat number (N.B. the musicians need to know their seat position in order to tell the sound system. The Violinist should let the SoundSystem know what instrument it is by using the method soundSystem.setInstrument(seat, instrument); In our orchestra, the violin is instrument number 41.

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.

Part 4 Modelling the Conductor


The Conductor is the heart of your orchestra, responsible for putting the orchestra together, reading in the music and then conducting the orchestra in playing it. You will need to create a constructor for your Conductor. When you initialise your Conductor it will need to create and initialise the SoundSystem using: soundSystem = new SoundSystem(); soundSystem.init(); This is the soundSystem that can then be passed to all the musicians. Your Conductor should now create a new Orchestra. The conductor can populate this orchestra with different musicians using the access methods for the orchestra and the constructors of the musicians. Create a new musician with the appropriate constructor. Give the musician some music to play. For testing purposes feel free to use the following piece of music. More musical pieces will be uploaded onto the WIKI and feel free to add your own should you wish to.

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

Table 2: Corresponding note values for Octave 0

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.)

Part 5 Reading Music Files


Now you hopefully have a working orchestra with a conductor able to get musicians to play simple pieces of music. Having the music compiled into your classes is fine for testing but it will be much better to be able to read any piece of music in from a file. To do this, we are going to use a simple file format that lets the conductor know what musicians are needed for the orchestra and what music each of them needs to play. Our file format looks like violin:loud: 67,69,67,66,65,69,67,72,0,0,72,74,72,71,72,69,67 cello:soft: 67,69,67,66,65,69,67,72,0,0,72,74,72,71,72,69,6767

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.

Part 6 - Modelling a LeadViolinist


The final musician that you need to create is the LeadViolinist. This is an extension of the Violinist class you created earlier as they can do everything a Violinist can do and more. When created, the LeadViolinist should be passed the Orchestra object as they will need to be able to communicate with the other musicians. LeadViolinists always sit in seat 1. Should another musician be sitting there when the LeadViolinist is added to the orchestra then they need to move. If there isnt a spare seat for the musician to move to then they will unfortunately have to leave the orchestra. When the LeadViolinist is asked to play a note, they will play their own note through the sound system and then instruct all the other musicians to play their next note. This makes life very easy for our Conductor as if there is a LeadViolinist in their Orchestra then they only need to ask them to play a note and dont have to worry about the other musicians. If there isnt though, they need to tell all musicians to play their notes. Now you have a LeadViolinist your Orchestra is complete. You may want to attempt some of the extensions below and you should read the section below on Exceptions as you will be expected to demonstrate that you can use system provided Exceptions to make your program more resilient.

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

85% of the marks are available without attempting any extensions.

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

You might also like