aspose file tools*
The moose likes Beginning Java and the fly likes Beginner needs help with objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Beginner needs help with objects" Watch "Beginner needs help with objects" New topic
Author

Beginner needs help with objects

Dietrich Lehr
Greenhorn

Joined: Sep 06, 2010
Posts: 8
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?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

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.


[My Blog]
All roads lead to JavaRanch
Dietrich Lehr
Greenhorn

Joined: Sep 06, 2010
Posts: 8
Makes sense. Thanks for the help.
Ninad Kuchekar
Ranch Hand

Joined: Jan 05, 2010
Posts: 64
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


Don't walk as if you rule the world, walk as if you don't care who rules it...
Soniya Ahuja
Ranch Hand

Joined: Jul 20, 2008
Posts: 83
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


SCJP 1.5 | SCWCD 5 | SCJP 6.0
[url]http://a2zjava.webs.com[/url] - Online training for Java/JSPs and Servlets/SCJP/SCWCD
http://soniyaahuja.webs.com
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Beginner needs help with objects