Hi guys. I've been reading Head First Java to get into Java. I'm at the beginning of the second chapter where things get more Object Oriented... oriented?
Anyways, pg61 (if you have the book) and it has me writing the following code:
When I execute this, all that comes out is the "Playing the movie." Am I missing the point, or isn't it supposed to do more than that? I have that all in one file and I'm thinking maybe I need to have the second class in another file or something. I'd really appreciate some insight on this.
I know this is a really dumb question and I probably have a few people laughing at me, but I'm really determined to learn Java so be prepared for a few more of my stupid questions. :P
I don't think I or anyone I know about has ever had an urge to laugh at anyone trying to learn complicated things like programming language
As for your code, lets look at the class Movie:
It has 3 member variables that indicates that it holds 3 kinds of information namely: Title, genre and rating
It has 1 member function which has one purpose: printing out the string "Playing the movie"
The main method goes through the trouble of creating two instances of that class, giving it names, genres and ratings but those attributes are never seen because the playIt() function doesn't include them in the output string.
I would assume that at some point you should be able to get the movie title, genre and rating, so what we are looking at is an incomplete class. I bet your assignment is to add new functions to it like getTitle(), getGenre() and getRating().
You could also modify the playIt() function to include the name of the movie: Playing the movie: Gone with the Stock
Joined: Jul 31, 2011
That makes sense now. So it was storing the info, just not printing it I assume.
I changed up the code a bit and made it actually display all the info for each of the movies.