but first
play

but first. Project 1: Movie Theatre Simulation Inheritance and - PDF document

but first. Project 1: Movie Theatre Simulation Inheritance and Polymorphism Handouts / Description now on Web site Due Dates: The Payroll App Minimum Effort Due: April 7, 2002 Full Project Due: April 14, 2002 Movie


  1. but first…. • Project 1: Movie Theatre Simulation Inheritance and Polymorphism – Handouts / Description now on Web site – Due Dates: The Payroll App • Minimum Effort Due: April 7, 2002 • Full Project Due: April 14, 2002 Movie Theatre Simulation Movie Theatre Simulation • You are to program a simulation of the workings • You will be programming a simulation of a multiplex theatre complex. – There will be a global “clock” indicating the • Rules: current time of day of the simulation – A Theatre Complex has a number of individual theatres – You will be updating the current time as the – Each theatre shows an individual movie a number of simulation progresses through “the day” times based on a given schedule – The state of the objects of the system will – A movie may be shown in more than one theatre change as the current time changes. – Customers can buy tickets in advance for $7 ($4 if ticket is purchased before 4pm) Movie Theatre Simulation Movie Theatre Simulation • Major objects • You will need to implement the following classes: – TheatreSim – main object that drives the simulation – TheatreComplex – represents a multiplex containing a – Movie multitude theatres – Schedule – Theatre – an individual theatre – Theatre – Movie – a movie – TheatreComplex – Schedule – The schedule that a movie will follow at a given individual theatre. Will also maintain the “state” • Specs for these classes are given via of a movie playing at a given theatre. Javadocs and UML diagrams. – Clock – Master clock for the simulation – Time – representing time of day 1

  2. Movie Theatre Simulation Movie Theatre Simulation • A simulation will be defined by two input files (to • Minimum Effort Requirement TheatreSim) – At the very least, you will need to implement – Complex Definition File – the Movie class. • Contains what theatres are playing what movies and when. – Simulation Control file – Submission of this is due April 7 th • List of “events” that happen during the day – Must submit minimum effort requirement to – “buy” – customer buys ticket pass the course. – “advance” – advance the global clock – “status” – Print status report (what’s going on “now” at each theatre) – “summary” – Print summary (how many tickets sold and $$ collected for each theatre) – “schedule” – Print s schedule Movie Theatre Simulation Movie Theatre Simulation • Grading • Submission – First criteria: Program must run correctly! – All submissions (minimum effort + final code) – Deductions for are done using try • Unclear or bad implementation (35%) – Minimum effort due: April 7 th • Bad programming style (including non-use of RCS) (30%) – Weighting – Complete project due: April 14 th • Movie 15% • Schedule 25% • Theatre 25% – No late submissions! • TheatreComplex 25% • All classes together 10% Movie Theatre Simulation Interface data • Questions? • All data associated with an interface, regardless of how they are declared are: – Read-only – Public – Final – Static 2

  3. Interface data A bit more on interfaces public interface Foo { • The Observable/Observer design pattern – Use this pattern when you have one class that public int a = 30; must react to the changes in another class. public static int b = 40; public static final int c = 50; – The second class(Observer) is said to observe the first class (Observable). private int d = 34; // not allowed – In the project, the Clock will be observed by the protected int e = 444; // not allowed Theatre objects. } Observer/Observable ( java.util ) Observer/Observable ( java.util ) • The Observable public void update (Observable o, Object arg) – Observable is defined as a class. – The Observable maintains a set of Observers who are interested when the Observable o – the observable object changes arg – an argument with optional details about • Observer the change. – Observer is defined as an interface – Classes that implement Observer must define an update method Observer/Observable ( java.util ) Observer/Observable ( java.util ) • When an update is made to an Observable, • In our simulation an update message is sent to all Observers – All Theatre objects are registered with the currently in the Observable’s set. global Clock as observers. – When the current time of the Clock changes (via the simulation), the Clock will • Observable.notifyObservers(Ob notifyObservers() ject arg) is used for this purpose • I.e. the update method for all Theatres will be called. 3

  4. Back to our Payroll app Observer/Observable • Questions? • Class hierarchy for theatre app Performer isA isA Actor Musician Guitarist Pianist Drummer Back to our Payroll app Changes to the Payroll class • Instrument hierarchy public class Payroll { private Performer performer[]; private int nPerf; Instrument public void addPerformer (Performer P) { if (nPerf == MAXPERF) { System.err.println ("Payroll is full!"); Guitar Piano Drums } else { performer[nPerf] = P; nPerf++; } } calculateTotalPay A look at Instruments public abstract class Instrument { public double calculateTotalPay() private double rentalCost; { double sum = 0.0; protected Instrument (double cost) for (int i=0; i < nPerf; i++) { sum += performer[i].calculatePay(); rentalCost = cost; } return sum; } public double getWeeklyRental () { return rentalCost; } } 4

  5. A look at instruments A look at Performer public class Guitar extends Instrument { public abstract class Performer implements Comparable { private String myName; public Guitar () private double payPerPerf; { private int nPerformances; super (200.0); } protected Performer (String name, double rate) { protected Guitar (double rate) myName = name; { payPerPerf = rate; super (rate); nPerformances = 0; } } } } A look at Performer Now Actor public abstract double calculatePay(); public class Actor extends Performer { private static final double PAYRATE = 200.0; protected double getBasePay() { public Actor (String name) return nPerformances * payPerPerf; { super (name, PAYRATE); } } public void perform (int n) public double calculatePay () { { nPerformances = n; return getBasePay(); } } } And Musician Finally Musician subclasses public class Drummer extends Musician { public class Musician extends Performer { public Drummer (String name) private Instrument myInstrument; private static final double PAYRATE = 100.0; { super (name, new Drums()); public Musician(String name, Instrument I) } { super(name, PAYRATE); } myInstrument = I; } public double calculatePay() { return getBasePay() + myInstrument.getWeeklyRental(); } 5

  6. • Any questions? • Tomorrow – Exceptions 6

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend