Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Help Testing Objects

  1. #1
    Junior Member
    Join Date
    May 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help Testing Objects

    Hey, World. Recently I've cracked open a book dealing with java for beginners. Each page my fingers turned, there was a problem to be solved, it led to brain busters, teasers, and much more. Unfortunately for me today, I've crossed a puzzle that I cannot crack. Here's my code:

     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;
    		two.playIt();
    		Movie three = new Movie ();
    		three.title = "Btye Club";
    		three.genre = "Tragic but ultimately uplifting";
    		three.rating = 127;
    		}
    	}

    The problem is that I don't think it's working correctly, what exactly is this example in this book is trying to make me understand? The only result that I'm getting is "playing the movie." This is my first time working with a main class and sub class. Anyway, please explain this to me as you would a uneducated 10 year old.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Help Testing Objects

    I don't think it's working correctly
    Please explain why you think that? What were you expecting?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    May 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help Testing Objects

    Well, there are more methods below dealing with movie titles. I mean, is the sole purpose to just print "playing the movie" and nothing more?

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Help Testing Objects

    It does seem silly. So much code and it only prints that message when the playIt() method is called.
    Time to read some more of the book to see why the author shows that code and what he is going to do with it.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    May 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help Testing Objects

    After much effort I've managed to get it working. I believe this is how it should be. There maybe useless codes in the program, not sure.

    class Movie {
    	String title;
    	String genre;
    	int rating;
    	boolean movies = false;
    	void playIt() {
    		System.out.println(" playing the movie |Title| " + title + " |Genre| " + genre + " |Rated| " + rating);
    	}
    }
    public class MovieTestDrive {
    	public static void main (String [] args){
     
    	Movie one = new Movie();
    	one.movies = true;
     
    	if (one.movies ==true){
    	}
    	one.title = "Gone with the Stock";
    	one.genre = "Tragic";
    	one.rating = -2;
    	one.playIt();
    	Movie two = new Movie ();
    	two.title = "Men & Black";
    	two.genre = "Action";
    	two.rating = 5;
    	two.playIt();
    	Movie three = new Movie ();
    	three.title = "Star Wars";
    	three.genre = "Drama/Action";
    	three.rating = 5; 
    	three.playIt();
    	}
    }

    Thanks for the hint!
    Last edited by ChocolateThunder; May 4th, 2013 at 07:46 PM. Reason: more info.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Help Testing Objects

    That looks like it would do a much more useful print out.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. testing
    By neeraj bhatt in forum Java Theory & Questions
    Replies: 1
    Last Post: November 4th, 2012, 03:48 PM
  2. [Question] Objects instantiated within objects.
    By Xerosigma in forum Object Oriented Programming
    Replies: 6
    Last Post: April 25th, 2012, 10:53 AM
  3. Java automated testing tools for Unit testing
    By rameezraja in forum Member Introductions
    Replies: 2
    Last Post: April 14th, 2012, 08:51 AM
  4. If Testing, testing for another if?
    By Rusticus in forum Loops & Control Statements
    Replies: 10
    Last Post: October 1st, 2011, 10:18 AM
  5. Need Help on testing Code
    By indidude89 in forum Java Theory & Questions
    Replies: 2
    Last Post: May 9th, 2011, 12:53 PM