• Post Reply Bookmark Topic Watch Topic
  • New Topic

Video store program  RSS feed

 
Raecheal Miller
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to make a video store program that allows customers to search for videos and either buy or rent them. I have already made a class with 3 subclasses, VHS, DVD and VCD. for the meantime, i have two problems, how to change the status to "in" and "out" to show video availabilty and how to set a price for vhs, dvd and vcd individually...

video class:



dvd class:



vcd class:


vhs class:



for not the boolean will later be used to allow the customer to search by (name,type)
 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don’t overload your equals method. Override it. That is, however, by no means easy. You will of course have to override the hashCode method in parallel. I am pretty sure the equals methods you have written will not work.
Why have you got a String for status? Why don’t you use an enum?
I think you have misunderstood inheritance. You would have a class called Recording (possibly abstract) which has subclasses eg DVD CD Video. You can put all the fields and methods in the Recording class and implement the subclasses simply by giving them constructors. And restrict the number of constructors. If you have name length and director fields, then give them one constructor taking those three parameters. One and only one constructor. In every class. That way you force users of the class to provide that information.
Don’t go changing the fields in each subclass. If a DVD has a price and a VHS has a price, why isn’t that price field in the superclass? That is what I meant by all fields in the Recording class.
 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Raecheal Miller wrote:for the meantime, i have two problems, how to change the status to "in" and "out" to show video availabilty and how to set a price for vhs, dvd and vcd individually...

OK, there's a few issues here.

What is a Video? Is it a film (or, as Campbell says, a Recording), or is it an individual cassette or DVD?

If it's the latter, and you've just received 10 copies of 'Gone With The Wind' to put on your shelves, how are you going to identify a specific one?

Strangely enough, I wrote a system professionally specifically for this, and it's a very important distinction to understand. Assume, for a moment, that your store deals only with films:
  • 1. A "Film" is a film, NOT the cassette/DVD/whatever it comes in. It's usually identified by a name or title, and may come in various forms of "media" (DVD, VHS etc) and will probably have an MSRP (likely a different one for each form). It is also likely to specify the director, stars, production company, running time, etc.
    The main thing to remember is that a Film exists independently of your store. Many of them were made long before your store existed and will still be played long after it's gone.
  • 2. A "Title" is a Film that is part of your inventory, and it will probably have its own price (and/or maybe a discount), so that the store can put on special offers for specific titles.
  • 3. A "Video" is a Title tied to a specific type of Media (ie, 'Gone With The Wind' in DVD form, or 'Caddyshack' on VHS). Again, it may have it's own price or discount, and it will probably have a SKU.
  • 4. A "Copy" is a specific copy of a Video - ie, it is the cassette/DVD/whatever - and your store may have several copies of each one. Many stores identify individual copies with a barcode; and it's the Copy that you will want to put your 'Status' on.

  • The names I've chosen for the types aren't particularly important, but the distinction between them is.

    Hope I haven't overloaded you with too much detail, but I thought you should be aware of what it is that you're modelling. Now how much of this you decide to include in your program is up to you.

    Winston
     
    Raecheal Miller
    Greenhorn
    Posts: 4
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    It's a movie rental store, and it rents 3 diff videos. DVD, VCD, VHS. I need to use inheritance for the 3 types of video.

    When video objects are first put into the store, the status should be “IN”. Each time a video is rented, the status of that video is set to “OUT”. When a rented video is returned, the status is set back to “IN”. This is my problem right here...

    the dvd, vcd and vhs are subclasses of the superclass video, and the super class video has the following information:

    vid_name= vidName;
    vid_length=vidLength;

    while the DVD has additional information irector
    The VCD has additional information :Year Made. and Movie Rating
    VHS has additional information :Year Made

    the reason im putting price in each subclass is because all the subclasses have different prices :

    In addition to renting out videos, customers are also allowed to buy them. Hence, all of the videos have a price tag associated with them. For VCD, all videos are $10.00. For VHS, they are $12.00 and for DVD, they are $50.00. However, if the VCD has a movie rating of „A‟, then the price is $20.00.

    To buy a video, a user needs to specify both the movie name and the medium type (DVD, VCD, or VHS). You will need to use both the movie name and the medium type to find the movie. You will need to use the instanceof operator. This is why there is this method at the end of my video class :
     
    Winston Gutkowski
    Bartender
    Posts: 10575
    66
    Eclipse IDE Hibernate Ubuntu
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Raecheal Miller wrote:It's a movie rental store, and it rents 3 diff videos. DVD, VCD, VHS. I need to use inheritance for the 3 types of video.

    Why? Have you been told to? The "type" could be just a list of valid types, viz:and then you could use the Title/Video hierarchy I suggested above, with Video having a "mediaType" field.

    However, if you've been told to do it, then you should; in which case your four classes would be equivalent to my "Video" type.

    When video objects are first put into the store, the status should be “IN”. Each time a video is rented, the status of that video is set to “OUT”. When a rented video is returned, the status is set back to “IN”. This is my problem right here...

    Exactly, because what you're renting/returning is a COPY of a Video - ie, A single DVD - and I see nothing in your classes that allows you to identify a specific one.

    All copies will have the same name, director, price, running time, etc, so there's not much point in repeating it for each copy. If you only had a single Video class you could extend it, but since you have 3, it's probably easier just to have each copy contain a reference to the Video that it's a copy of (in fact, it might be the best way to do it anyway).
    Either way, you must include some way of identifying it and, like I said, most stores use barcodes (which is basically a unique number).

    Winston
     
    Raecheal Miller
    Greenhorn
    Posts: 4
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Winston, I will take care of that later with this:



    this allows the customer to call for specific video name, and type. It's implemented in each video subclass.
    later I have an instance of method that will allow me to implement a discount method, but thats not my problem right now... i just wanna figure out a way to show availability as in our out.


    if i use this to check for availbilty and mutate to out for purchase or rental, will it work?
     
    Raecheal Miller
    Greenhorn
    Posts: 4
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    and btw i don't have to worry about repetitive objects, im only allowed to have ONE of each vid title in an array
     
    Winston Gutkowski
    Bartender
    Posts: 10575
    66
    Eclipse IDE Hibernate Ubuntu
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Raecheal Miller wrote:and btw i don't have to worry about repetitive objects, im only allowed to have ONE of each vid title in an array

    Oh, OK. I still think it's probably worth thinking about; otherwise you may have a lot of refactoring to do if you ever need to "develop" your design. After all, if your 'store' can handle many similar Videos, it will certainly handle one; but the reverse is NOT true. But don't worry too much about it at the moment if it's "doing your head in".

    I'd also say that a "type" enum as I described above might not be a bad thing anyway.

    Another general point: Your code seems to use an awful lot of Strings, including for things like "type", which really isn't a String; which is why (I suspect) so many of your comparisons involve equalsIgnoreCase().
    Strings are Strings, and you shouldn't use them to hold values that aren't (like numbers; or, in your case, 'type'). They make bad substitutes for other types.
    It's true that you will receive values from your user in String form, but these should be converted to a proper form for internal use (and verified for correctness) as quickly as possible.

    A good example is in your last question:
    A method that changes the status of a Video should take a Video object, not a String (in fact, it should probably be defined IN your Video class). Obviously, you may need to find a Video by its title (which is a String) and type (which isn't), but once you've got the object you want, use it.

    HIH

    Winston
     
    It is sorta covered in the JavaRanch Style Guide.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!