Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Beginner needs help with objects

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have 2 classes that I am using from the book Head First Java.
Here is the 1st class

And here is my other class that I guess should reference my first class



How do I get The MovieTestDrive class to get the info from the Movie class using the manual way (text edit and terminal on the mac) and the eclipse program? In eclipse i try to run them both at the same time, but I just get the output "Playing the movie". I thought it would tell me the name, genre, and rating as well. Actually, I guess it will only show the Playing the movie, but what is the point of the other information then?
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

In eclipse i try to run them both at the same time


You can only run one class, the one with the main() method. So you are actually running MovieTestDrive.

I thought it would tell me the name, genre, and rating as well.


Why did you think that ? Where are you printing the values ? All I see is System.out.println("Playing the movie");. This isn't going to print more than that. Maybe you wanted to code something like :


what is the point of the other information then?


The point is that the Movie class holds necessary information about movies. It's up to you to do what you want with it. Print it, or not.
 
Dietrich Lehr
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Makes sense. Thanks for the help.
 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just to add, it would be better if your class Movie overrides the toString() method of the Object class. Then you can simply call this method on each movie object to get its information, simple enough?

Something like...




-Ninad
 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The toString implementation as given by Ninad has one more advantage - instead of calling it manually even the following will give you all the information about a movie

System.out.println(one);

This will now print (assuming that you also include the code as mentioned by Ninad)
Title: Gone with the Stock Genre: Tragic Rating: -2
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic