aspose file tools*
The moose likes Beginning Java and the fly likes program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "program" Watch "program" New topic
Author

program

Sam Gavis
Greenhorn

Joined: Oct 27, 2007
Posts: 2
What is wrong with this program?



class Movie {
String title;
String genre;
int rating;

void playIt() {
System.out.println("Playing the movie");
}
}

public class MovieTestDrive {
public static void main(String[] args) {
Movie one = new Movie();
one.title = "Gone with the Stock";
one.genre = "Tragic";
one.rating = -2;
Movie two = new Movie();
two.title = "Lost in Cubicle Space";
two.genre = "Comedy";
two.rating = 5;
Movie three = new Movie();
three.title = "Byte Club";
three.genre = "Tragic but ultimately uplifting";
three.rating = 127;
}
}
Nacho Espinosa
Ranch Hand

Joined: Jan 17, 2007
Posts: 30
Something is wrong in the method playIt()

check it!


Greetings<br />Nacho Espinosa<br />SCJP 1.4
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36482
    
  16
Welcome to the Ranch. Please use the "code" tags when posting code; it makes it much easier to read.

You are putting info into the Movie objects and not accessing it again. You are not calling the playIt method anywhere.

Move the Movie class into a file of its own and give the class public access. Please make all the attributes "private" and set up a public constructor in the Movie class. Also public access for the playIt method.
Then you can call it more like this:Give the Movie identifiers better names than one, two, three.
Alter the playIt method so it prints out something more informative.

I hope that lot is helpful-and I am not trying to be critical.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: program
 
Similar Threads
Question about HashSet
Exception in thread "main" java.lang.NoSuchMethodError: main
Beginner needs help with objects
Java OO - First time help!
Reading Head First Java - confused