I'm currently trying to write a basic video store management program. I have already written a number of classes to help do this job, but I'm having a few doubts about my Video class.
Basically, will the following code allow me to access the information about video titles, stored in a seperate class called 'Title', and will the constructor 'Video' correctly read data from a text file for the other required information.
I know these questions may seem a bit simple, but I'm getting really lost with this program.
Code so far is as follows;
Any help or advice really appreciated!! [ November 19, 2005: Message edited by: celine scarlett ]
This confuses me - where are you getting title from? It is missing from the parameter list in the constructor, and nowhere else in your code is it instantiated, nor is a reference to an instance of a Title set up. As it stands, title will always be null, thus you will never have a reference to a Title, thus you cannot obtain any information from it.
On a side note, why is the "available" member variable declared public? This is usually fairly bad practice. I see you declared the rest of them private, making this one stand out all the more.
On a second side note, your isAvailable() method could just return the boolean "available". The true or false stored in this boolean will do the work you are trying to do in the if-else statement. There is nothing wrong with what you wrote, it will work, I am just offering a simpler alternative. [ November 19, 2005: Message edited by: Jody Brown ]
Joined: Nov 06, 2005
This is a version of the Video class I was working on before. I don't know whether this is an improvement or not?
Code so far is as follows,
Any help or advice appreciated!!
Joined: Nov 09, 2005
Not knowing enough about what your application's supposed to actually do, I can only speculate on certain things. But I will say, the constructor that takes all of the parameters for the class "Title" then simply instantiates one sets the alarm bells ringing. That is not to say it is wrong - you may have a valid reason to do it like this, I just do not know what that reason is. As you have it currently, this is how I would imagine the constructor of the Title class to look like, not the Video. You could at some point just pass an an instance of Title to the Video constructor to create the reference. What are the roles of the classes "Video" and "Title" anyway? Even that isn't clear to me, so I cannot even guess where the seperation of roles between the two lies, how they are supposed to work together and what information is supposed to be stored where. It is important that you get your roles and data structures clearly defined before attempting any coding, or you will quickly find yourself going in circles.
Joined: Nov 06, 2005
I think I see what you mean. The purpose of the Title class is to represent information about a video title. Specifically the title code, with four strings for the name, lead actor 1 and 2, and the director.
The Video class represents information about one of these video titles, with additional information about availability to rent and a method to get the total price for the rental.
I've modified the Video class as follows,
Is this better, will it work? Any help appreciated!!
subject: Video store program - persisting problems. Any advice !!