Lab 5

Create a class (Movie) with private data members, and with a second "driver" class use the first class.

In the Moive class, instance variables must be declared as private.  Write the following in the Movie class:

1 point:

A default constructor and a fully qualified constructor

1 point:

The toString() method

1 point:

get() and set() methods for the instance variables

1 point extra credit:

A method that given two movies as parameters prints them out in chronological order, with the

earliest movie printing first.  You would call this using: movie1.printInOrder( movie2).

class Movie 

{

     private String name;

     private char rating;   //e.g. 'G', 'P', 'R', 'X'

     private year int;

     // Default constructor and fully qualified constructor

     // get() and set() methods for the instance variables

     // toString() to allow printing

}

Write the Movie class so that the following MovieDriver class works as written below:

class MovieDriver 

{

       public static void main(String[] args) {

          Movie movie1 = new Movie();       // default constructor, which should supply default values of "The Muppets", 'G', 1975

          Movie movie2 = new Movie("Planet of the Apes", 'P', 2011);     // fully qualified constructor

          // display both movies

          System.out.println( movie1);

          System.out.println( movie2);

//use set methods

          movie1.setName("Jaws");

          movie1.setRating( 'R');

          movie1.setYear( 1979);

 //display movies in chronological order

movie1.printInOrder( movie2);

       }

}