File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

program

 
Sam Gavis
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Something is wrong in the method playIt()

check it!
 
Campbell Ritchie
Sheriff
Pie
Posts: 47250
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic