Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading Head First Java - confused

 
Mark Ly
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Unnar Björnsson
Ranch Hand
Posts: 164
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Mark Ly
Greenhorn
Posts: 2
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.



Thanks for the help Unnar!
 
Benjamin Thvedt
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Reading the same book, just did that one myself! Yeah, it seems like there is a lot of extra stuff for something that just outputs "Playing the movie!"
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic