hello everyone,

im trying to make a theatre program and im at a dead end so im hoping for some help please.
if someone can help see my problem clearer or post some sample code it will be much apperciated.

the problem is i need to create a Seat class in the theatre program but im unsure of how it will work or how i can do it.

i have been asked to create a seating system which will hold around 400 seats. but the seats are split into different sections. e.g upper circle will hold 100 seats etc. it needs to be oop based.

the seats are split into rows and a row of seats my have different pricing e.g. row 1 and 2 may be priced at £10 per seat.

also i have to make sure that the seats are not doubled booked but i really am struggling with how to do all the above.

Last but not least lol can java applets use mvc as i have only done mvc on jframes so im not totaly sure??

all feedback and help is much appericated

thanks
Superstar288

Recommended Answers

All 16 Replies

Depending on the attributes that different seats may have you can choose to either implement them as different type of seats or keep a 'type' attribute in the Seat class that gives their type, if they do not differ much.

>also i have to make sure that the seats are not doubled booked
To avoid double booking you can keep a flag isBooked in the seat class that tells whether the seat is booked or not.

I assume you are acqauinted with OOPS concepts, if not you can read about that on the net.

hey verruckt24 well im not even sure what attributes to have lol i mean i know i would have price, num of seats in row , number of rows and isbooked as you have suggested. can you think of anymore?? also im not sure how isbooked will work do i have to do some check in the class eg query the data in the database?? if you know what i mean.

ummm the thing is most of the seats areas eg upper circle the only difference is the price for each row ect otherwise there identical.
what do you mean by 'type' attribute??

yes i have done some oop before not much though lol thanks for your quick reply

also im not sure how isbooked will work do i have to do some check in the class eg query the data in the database??

In the constructer of your seat class, have a boolean for the booked status.

then have a method that simply returns the true or false value of the seat

What I meant was, if your seats do differ a lot in attributes other than price you would want to have a different class for each of them, say, UpperCircleSeat, DressCircleSeat, LowerCircleSeat etc. where all of these could be deriving from one common Seat base class. But as you mention that it's not the case, you can just have one Seat class with attributes such as Price, Type (UpperCircle,LowerCircle etc), isBooked, SeatNo which could be combination of row number and seat number within that row say, A4, F5 etc. These are all the attributes that come to mind.

ok kool thanks for the help so much everyone its much apperciated.
i will try and make this class tonight.
but what i dont understand is, do i then eg make an array for the rows and seats eg have an array for upper circle which has a1,a2, a3 ect. and have them as a default array so they can be used all the time if you know what i mean.

As I mentioned in first post you need to model your program close to the real world scenario. In our world a Theatre is made up of a collection of seats, so what you can do is, make a Seat class as suggested in the previous posts and then you could have an array of the Seat objects.

Hey thanks for your quick reply once again, i understand what you mean. but can i construct that array in the seat class like int[] upper= {1,2,3,4,5,6,7,8,9,10}; for the seats?
or would i have to make it seperate?? sorry im only learning java not had 2 much experince you see.

Superstar288 sent me a PM mentioning this:

Hey thanks for your quick reply once again, i understand what you mean. but can i construct that array in the seat class like int[] upper= {1,2,3,4,5,6,7,8,9,10}; for the seats?
or would i have to make it seperate?? sorry im only learning java not had 2 much experince you see.

Create a Seat class and then create an array of Seat objects the same way you would create one for String or int etc.,

Seat [] seats = new Seats [10];

kool thanks very much guys will try this later on tonight and try and get it done. i feel you have helped me understand this much better and i feel more confortable than before. i will let you know the end result cheers

There are two obvious things you could do as far as how you're thinking about the section of the Seats.

Scenario 1:
Think of the section the seat is in as a property of the seat. (In other words, since the seat will always be in the same section, you could have a variable in the Seat class called section).

Scenario 2:
Think of the section the seat is in as a property of the Theater- not of the seat. In this case, your Theater class could have an array of seats for each section. This is what I would personally do, I think.

commented: Helpful and patient responses in this thread. +18

lol thanks for that reply BestJewSinceJC is there any chance you can explain the second scenario please?? what i dont understand is where should i make the array of seats?? ahhhhhhh

Lets say you have three sections. Then you would have three arrays of seats, one for each section.

public class Theater{
-seat array here
-second seat array here
-third seat array here

}

@superstar288: You have been given enough hints on where and how to make the array of Seats, also on the attributes about the Seats etc. I suggest if you are still not able to figure this out then you go read some Java Tutorials on classes, array and how to make arrays within classes etc.

A more generalized Theater class design would have either a single collection of seats with the section, price, etc being properties of the seats, or another intermediate collection class to represent seating sections that contained their own collections of seats.

Theaters do not all share common layouts or number of seats, so hard-coding in three arrays for seats ties your implementation to a theater that had three distinct sections of seats with different properties.

I understand reusability and coupling (not sure if the OP does or doesn't) but if I was writing this, I'd probably feel that your suggestion is needlessly complex and doesn't offer enough benefit to justify the extra work. Maybe I'm wrong - I'd like to see a seating collection that actually offers some benefit

Putting in a SeatingSection class probably is more complex than the OP needs for this assignment. I just threw that in as a consideration to get them thinking a bit. I think all they really need is a single collection, List or array, of Seats.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.