Java Bootcamp – Workbooks and Challenges
)}

Movie Store – Part 3

In this workbook, you will apply the Big 3 steps to the Store class.

The store is identified by the movies that it manages. It can add movies, sell them, and allow the user to rent/return them.

Task 1 – Adding the field


Add the movies field to the Store class. The number of movies can increase or decrease so use an ArrayList.

Task 2 – The Big 3


  1. Constructor.

    • It receives no parameters.

    • It sets the field equal to a new object of the ArrayList class.

  2. Getter: getMovie

    • It receives one parameter: int index.

    • It returns an object at the requested index.

  3. Setter: setMovie

    • It receives two parameters: int index, Movie movie.

    • It sets an element equal to a copy of the object being passed in.

As you're applying each step, careful not to fall into the reference trap.

Task 3 – addMovie.


  • This method is void

  • Receives one parameter: Movie movie.

  • Adds a movie to the ArrayList.

Task 4 – sellMovie.


  • This method is void.

  • Receives one parameter: String movieName.

  • Removes the movie that matches the name passed in.

Task 5 – rentMovie.


  • This method is void.

  • Receives one parameter: String movieName.

  • Sets isAvailable equal to false.

Task 6 – returnMovie.


  • This method is void.

  • Receives one parameter: String movieName.

  • Sets isAvailable equal to true.

Task 7 – Remove sellMovie, rentMovie and returnMovie


You probably noticed that rentMovie, sellMovie and returnMovie have identical code. Instead of three methods, create one:

  • named action.

  • accepts two parameters: String name, String action.

  • runs three cases: sell, rent, and return.

Task 8 – toString.


  • Set a String variable temp that equals "".

  • Loop through every movie in the movies field.

  • During each run, add the toString of each movie.

  • During each run, add two new lines \n\n to temp.

  • return temp;

Task 9 – Testing the code


  • Inside main(), create an object of the Store class.

  • add three movies to the movies field. Use the following values:

    • The Shawshank Redemption--Blue-Ray--9.2

    • The Godfather--Blue-Ray--9.1

    • The Godfather: Part II--DVD--9.0

  • Print the Store.

Expected Output:

  • call action and sell "The Godfather".

Expected Output:

  • call action and rent "The Shawshank Redemption"

Expected Output:

  • call action and return the movie "The Shawshank Redemption"

Expected Output:

Good Luck!


Feedback Summary
4.8
39 students
5

92%
4

3%
3

0%
2

0%
1

5%
Written Reviews
There are no written reviews yet.