Practice Midterm Lab Exam

Practice Midterm Lab Exam

COSC 1010Name:______

Practice Midterm Lab Exam

Directions: Create a Bluej project called Exam1 that implements the classes described in this handout.

  1. The Movie class represents an individual movie. It stores the movie’s title: title, cost: cost, number in stock: inStockand total times it has been rented: totalRentals. Write the Movie class according to the following requirements.
  2. Add the four (4) fields that are used by the Movie class and create a constructor that takes two (2) parameters. The first parameter is a String that is used to initialize the title of the movie. The second parameter is an integer that is used to initialize the cost of the movie. The number in stock is initialized to a random number between 5 and 15. The total times the movie has been rented is initialized to zero (0). All fields must be declared private.
  3. Write a mutator method that rents a movie. This method takes one parameter of type String that is the title of a movie. If the movie title passed in to this method and title are the same and the movie is in stock, then increment the total times this movie has been rented, decrement the number of this movie in stock and return true. Otherwise, return false.
  4. Write an accessor method that returns the cost of this movie.
  5. Write an accessor method that returns the total number of times this movie has been rented.
  6. Write a method that prints the details of this class. This method should print the following: the title, the cost, the total number in stock and the total number rented. This output should be formatted as example 1 (on last page).
  7. The MovieStore class represents a movie rental store that rents movies. It stores three (3) Movie objects.
  8. Add the three (3) fields that are used by the MovieStore class and create a constructor that initializes the three (3) fields with the values: field one (“Batman”, 3), field two (“Clueless”, 5), and field three (“Serenity”, 4).
  9. Write a mutator method that rents a movie. This method takes one (1) parameter of type String that is the title of the movie that is to be rented.
  10. If the title passed in to the method is a movie that we have in stock print the following message: “You have rented: title for cost.” (title Is the name of the movie and cost is how much it costs to rent the movie)
  11. Otherwise print the following message: “Sorry, we do not have title in stock.” (title is the name of the movie that is trying to be rented)
  12. Write a method that shows the details of the movies in stock and how much we have made in rentals. You will show: the titles of the movies, the cost to rent of each movie, the number of each movie in stock, the number of times each movie has been rented and the total amount made from renting all movies. This output should be formatted as example 2 (on last page).

Example 1 (output format for 1e.)

------

Title:Batman

Cost:3

In Stock:9

Rented:1

------

Example 2 (output format for 2c.)

Store Inventory Sheet

------

Title:Batman

Cost:3

In Stock:9

Rented:1

------

------

Title:Clueless

Cost:5

In Stock:12

Rented:0

------

------

Title:Serenity

Cost:4

In Stock:10

Rented:0

------

Total revenues for movie rentals were: $3