divider

Objective

Design a class that models a movie by defining instance variables, constructing objects with meaningful state, and implementing methods that describe or display information about the movie.

Skills to Practice

  • icon Defining classes
  • icon Declaring instance variables
  • icon Writing no-argument and full-argument constructors
  • icon Creating methods that operate on object data
  • icon Creating and using objects in a main program
divider

Tasks

  1. Create a new project named Sprint-4-1
  2. Complete the following tasks:
    • Create a class named Movie with the following required instance variables:
      • title (text)
      • director (text)
      • runtime (number of minutes)
      • rating (text or age rating)
    • Create a no-argument constructor that assigns default values to all instance variables.
    • Create a full-argument constructor that accepts values for all instance variables and stores them.
    • Write a method named getDetails that prints or returns formatted information about the movie, such as its title, director, runtime, and rating.
    • In your main program, create:
      • One movie using the no-arg constructor
      • One movie using the full constructor
      • Call the getDetails method on both objects
divider

Sample Output

Sample Output
--- Movie Details ---
Title: Inception
Director: Christopher Nolan
Runtime: 148 minutes
Rating: PG-13

Begin Challenge