Question

A video store is made up of movies (and lots of other stuff too - but...

A video store is made up of movies (and lots of other stuff too - but let's keep it simple) - so start by defining a Movie class, then define the VideoStore class and finally a test for it all.

Movie Class:

Instance fields:

  • title (String)

  • star (String)

  • isCheckedOut (boolean)

  • numTimesCheckedOut (int)

Methods:

  • public String getTitle()

    • Returns title of movie

  • public String getStar()

    • Returns star of the movie

  • public int getNumTimesCheckedOut()

    • Returns number of times movie has been checked out

  • public boolean isItCheckedOut()

    • Returns whether or not movie is currently checked out

  • public void checkMovieIn()

    • Checks movie in by setting isCheckedOut to false

  • public void checkMovieOut()

    • Checks movie out by setting isCheckedOut to true and increases numTimesCheckedOut



VideoStore Class:

Instance fields:

  • movieCollection (array of Movies)

Methods:

  • public void addMovie(String title, String star)

    • Creates a new movie with given title and star and adds the movie to the movieCollection array

  • public String recommendAMovie(String star)

    • Parameter is the star wanted

    • Returns title of a movie with that star that is not currently checked out

  • public void checkOutAMovie(String name)

    • Parameter is the name of the movie

    • Uses Movie class method checkMovieOut()

  • public void removeOldMovies()

    • Removes all movies from the movieCollection that have been checked out more than 20 times

  • public String getMovieTitles()

    • Returns a String that contains all the titles in the video store


Test:

  • Create a VideoStore object

  • Add several Movies to the VideoStore

  • Check out some movies (at least 1 should be checked out over 20 times - USE A LOOP!)

  • Remove the old movies and print out the titles in the video store to check

  • Ask user for a star and recommend a movie with that star

In Java Please

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Movie.java:


public class Movie {
   String title;
   String star;
   boolean isCheckedout;
   int numTimesCheckedOut=0;
  
   public Movie() {
      
   }
   public String getTitle() {
       return title;
   }
   public String getStar() {
       return star;
   }
   public void setTitle(String title) {
       this.title = title;
   }
   public void setStar(String star) {
       this.star = star;
   }
   public int getNumTimesCheckedOut() {
       return numTimesCheckedOut;
   }
   public boolean isItCheckedOut() {
       return isCheckedout;
   }
   public void checkMovieIn() {
       this.isCheckedout=false;
   }
   public void checkMovieOut() {
       this.isCheckedout=true;
       this.numTimesCheckedOut=this.numTimesCheckedOut+1;
   }
}

VideoStore.java:

import java.util.ArrayList;

public class VideoStore {
   ArrayList<Movie> movieCollection=new ArrayList<Movie>();
   ArrayList<Movie> removeMovie =new ArrayList<Movie>();
   public void addMovie(String title, String star) {
       Movie m =new Movie();
       m.setStar(star);
       m.setTitle(title);  
       movieCollection.add(m);
   }
  
   public String recommendAMovie(String star) {
       for(Movie m:movieCollection) {
           if(m.getStar().equalsIgnoreCase(star) && m.isItCheckedOut()==true) {
               return m.getTitle();
           }
       }
       return "NO movie to be suggested";
   }
   public void checkOutAMovie(String name) {
       for(Movie m:movieCollection) {
           if(m.getTitle().equals(name)) {
          
               m.checkMovieOut();
           }
       }
   }
   public void removeOldMovies() {
       for(Movie m:movieCollection) {
          
           if(m.getNumTimesCheckedOut()>20) {
               System.out.println("removed movie is "+m.getTitle());
               removeMovie.add(m);
           }
       }
       movieCollection.removeAll(removeMovie);
   }
   public String getMovieTitles() {
       String allMovies="";
       for(Movie m:movieCollection) {
           allMovies=allMovies+", "+m.getTitle();
       }
       return allMovies;
       }

   public void getMovieTitlestoCheck() {
       for(Movie m:movieCollection) {
           if(m.isItCheckedOut()==false) {
               System.out.println(m.getTitle());
           }
       }
   }
  
}

Test.java:

import java.util.Scanner;

public class Test {

   public static void main(String[] args) {
       // TODO Auto-generated method stub
       VideoStore vs=new VideoStore();
       vs.addMovie("harry", "Emma");
       vs.addMovie("fast and furious", "vin");
       vs.addMovie("bahubali", "prabhas");
       for(int i=0;i<=25;i++) {
           vs.checkOutAMovie("harry");
       }
      
       vs.removeOldMovies();
       System.out.println("name of the movies to be checked in");
       vs.getMovieTitlestoCheck();
       vs.checkOutAMovie("bahubali");
       Scanner sc=new Scanner(System.in);
       System.out.println("Enter the name of a star");
       String star=sc.next();
       System.out.println("suggested movie is "+vs.recommendAMovie(star));
   }

}

Add a comment
Know the answer?
Add Answer to:
A video store is made up of movies (and lots of other stuff too - but...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Objective In this assignment, you will practice solving a problem using object-oriented programming and specifically, you...

    Objective In this assignment, you will practice solving a problem using object-oriented programming and specifically, you will use the concept of object aggregation (i.e., has-a relationship between objects). You will implement a Java application, called MovieApplication that could be used in the movie industry. You are asked to implement three classes: Movie, Distributor, and MovieDriver. Each of these classes is described below. Problem Description The Movie class represents a movie and has the following attributes: name (of type String), directorName...

  • LAB 7-Movie List Program Goali Your assignment is to write a C++program to implement the ADT...

    LAB 7-Movie List Program Goali Your assignment is to write a C++program to implement the ADT List by creating a list of movies. This assignment will help you practice: multiple file programming, classes, pablic and private methods, dynamie memory, constructors and destructors, arrays and files Implementation the required classes This lab assignment gives you the opportunity to practice creating classes and using dynamic memory in one of There are two classes to implement: Movie and MovieList. As you can see...

  • Modify the library program as follows: Create a method in the LibraryMaterial class that accepts a...

    Modify the library program as follows: Create a method in the LibraryMaterial class that accepts a string s as a parameter and returns true if the title of the string is equal to s. Create the same method for your library material copies. Note that it will need to be abstract in the LibraryMaterialCopy class MY CODE **************************************************************** LibraryCard: import java.util.List; import java.util.ArrayList; import java.time.LocalDate; import    java.time.temporal.ChronoUnit; public class LibraryCard {    private String id;    private String cardholderName;   ...

  • PLEASE COMPLETE THE CODES. package javaprogram; import java.io.PrintStream; import java.util.ArrayList; import java.util.Scanner; /** * Movie class...

    PLEASE COMPLETE THE CODES. package javaprogram; import java.io.PrintStream; import java.util.ArrayList; import java.util.Scanner; /** * Movie class definition. * * @author David Brown * @version 2019-01-22 */ public class Movie implements Comparable { // Constants public static final int FIRST_YEAR = 1888; public static final String[] GENRES = { "science fiction", "fantasy", "drama", "romance", "comedy", "zombie", "action", "historical", "horror", "war" }; public static final int MAX_RATING = 10; public static final int MIN_RATING = 0; /** * Converts a string of...

  •    moviestruct.cpp #include <iostream> #include <fstream> #include <cstdlib> #include <ostream> #include <fstream> #include <cstdlib> #include <cstring>...

       moviestruct.cpp #include <iostream> #include <fstream> #include <cstdlib> #include <ostream> #include <fstream> #include <cstdlib> #include <cstring> using namespace std; typedef struct{ int id; char title[250]; int year; char rating[6]; int totalCopies; int rentedCopies; }movie; int loadData(ifstream &infile, movie movies[]); void printAll(movie movies[], int count); void printRated(movie movies[], int count); void printTitled(movie movies[], int count); void addMovie(movie movies[],int &count); void returnMovie(movie movies[],int count); void rentMovie(movie movies[],int count); void saveToFile(movie movies[], int count, char *filename); void printMovie(movie &m); int find(movie movies[], int...

  • Need this in C++ Goals: Your task is to implement a binary search tree of linked...

    Need this in C++ Goals: Your task is to implement a binary search tree of linked lists of movies. Tree nodes will contain a letter of the alphabet and a linked list. The linked list will be an alphabetically sorted list of movies which start with that letter. MovieTree() ➔ Constructor: Initialize any member variables of the class to default ~MovieTree() ➔ Destructor: Free all memory that was allocated void printMovieInventory() ➔ Print every movie in the data structure in...

  • WONT COMPILE ERROR STRAY / TEXT.H AND CPP PROGRAM SAYING NOT DECLARED HAVE A DRIVER WILL...

    WONT COMPILE ERROR STRAY / TEXT.H AND CPP PROGRAM SAYING NOT DECLARED HAVE A DRIVER WILL PASTE AT BOTTOM MOVIES.CPP #include "movies.h" #include "Movie.h" Movies *Movies::createMovies(int max) { //dynamically create a new Movies structure Movies *myMovies = new Movies; myMovies->maxMovies = max; myMovies->numMovies = 0; //dynamically create the array that will hold the movies myMovies->moviesArray = new Movie *[max]; return myMovies; } void Movies::resizeMovieArray() { int max = maxMovies * 2; //increase size by 2 //make an array that is...

  • Help! Not sure how to create this java program to run efficiently. Current code and assignment...

    Help! Not sure how to create this java program to run efficiently. Current code and assignment attached. Assignment :Write a class Movies.java that reads in a movie list file (movies.txt). The file must contain the following fields: name, genre, and time. Provide the user with the options to sort on each field. Allow the user to continue to sort the list until they enter the exit option. ---------------------------------------------------------- import java.util.*; import java.io.*; public class Movies { String movieTitle; String movieGenre;...

  • \\ this is the code i need help to get this part working the rest works...

    \\ this is the code i need help to get this part working the rest works but this and im not sure what is missing or how to make it work. this is what they asking for to do and there is two errors the ones shown in the pictures this is all the information I have from zybooks\\ Q3. (54 Points) Complete a public class to represent a Movie as described below. (a-e 4 pts each) (f-h 8 pts...

  • Course.java import java.io.Serializable; /** * Represents a course that might be taken by a student. *...

    Course.java import java.io.Serializable; /** * Represents a course that might be taken by a student. * */ public class Course implements Serializable { private String prefix; private int number; private String title; private String grade; /** * Constructs the course with the specified information. * * @param prefix the prefix of the course designation * @param number the number of the course designation * @param title the title of the course * @param grade the grade received for the course...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT