Write a class called Movie that contains the following infor

Write a class called \"Movie\" that contains the following information: Private instance variables for the title (string), director (string) and duration in minutes (\'float\') A three-argument constructor to set each of the instance variables above. If the title or author is null or the duration is less than 0.0, throw an Illegal Argument Exception stating the argument that is not correct. Get and set methods for instance variables.

Solution

Please find my code.

Please let me know in case of any issue.

######## Movie.java ###############

public class Movie {

  

// instance variables

   private String title;

   private String director;

private float duration;

  

// three argument constructor

   public Movie(String title, String director, float duration){

      

       // validating parameters

       if(title==null || director==null || duration < 0.0){

           throw new IllegalArgumentException(\"Please pass valid parameters.\");

       }

      

       this.title = title;

       this.director = director;

       this.duration = duration;

   }

// getters and setters

  

   public String getTitle() {

       return title;

   }

   public void setTitle(String title) {

       this.title = title;

   }

   public String getDirector() {

       return director;

   }

   public void setDirector(String director) {

       this.director = director;

   }

   public float getDuration() {

       return duration;

   }

   public void setDuration(float duration) {

       this.duration = duration;

   }

}

############ MovieTest.java ##############

public class MovieTest {

  

   public static void main(String[] args) {

      

       // creating Movie Object

      

       Movie movie = new Movie(\"The Landon\", \"Teem Cook\", 3.2f);

      

       System.out.println(\"Titls: \"+movie.getTitle());

       System.out.println(\"Director: \"+movie.getDirector());

       System.out.println(\"Duration: \"+movie.getDuration()+\" hours\");

      

   }

}

/*

Sample Output:

Titls: The Landon

Director: Teem Cook

Duration: 3.2 hours

*/

 Write a class called \
 Write a class called \
 Write a class called \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site