Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you convert this code into a C++ code? //////////////////////////////////////////// DVD.java package movie; public class DVD { private String movieTitle; private String movieStars[]; private String

Can you convert this code into a C++ code?

////////////////////////////////////////////

DVD.java

package movie;

public class DVD {

private String movieTitle; private String movieStars[]; private String movieDirector; private String movieProducer; private String movieProductionCo; private int numberOfCopies; DVD(String title, String[] stars, String director, String producer, String production, int copies) { movieTitle = title; movieStars = stars; movieDirector = director; movieProducer = producer; movieProductionCo = production; numberOfCopies = copies; }

public String getMovieTitle() { return movieTitle; }

public void setMovieTitle(String movieTitle) { this.movieTitle = movieTitle; }

public String[] getMovieStars() { return movieStars; }

public void setMovieStars(String[] movieStars) { this.movieStars = movieStars; }

public String getMovieDirector() { return movieDirector; }

public void setMovieDirector(String movieDirector) { this.movieDirector = movieDirector; }

public String getMovieProducer() { return movieProducer; }

public void setMovieProducer(String movieProducer) { this.movieProducer = movieProducer; }

public String getMovieProductionCo() { return movieProductionCo; }

public void setMovieProductionCo(String movieProductionCo) { this.movieProductionCo = movieProductionCo; }

public int getNumberOfCopies() { return numberOfCopies; }

public void setNumberOfCopies(int numberOfCopies) { this.numberOfCopies = numberOfCopies; } public void incrementCopies() { numberOfCopies++; } public boolean checkOut() { if(numberOfCopies>0) { numberOfCopies--; return true; } else return false; } public void checkIn() { numberOfCopies++; } @Override public String toString() { return "Movie: " + movieTitle + ", Stars: " + movieStars[0] + " and " + movieStars[1] + ", Director: " + movieDirector + ", Producer: " + movieProducer + ", Production Company: "+movieProductionCo; } }

PersonType.java

package movie;

public class PersonType { private String firstName; private String lastName; PersonType(String firstName, String lastName) { this.firstName = firstName; this.lastName = lastName; }

public String getFirstName() { return firstName; }

public void setFirstName(String firstName) { this.firstName = firstName; }

public String getLastName() { return lastName; }

public void setLastName(String lastName) { this.lastName = lastName; } }

Customer.java

package movie;

import java.util.ArrayList; import java.util.List;

public class Customer extends PersonType{ List rentedDVDs; List rentalCount; int accountNumber; private static int counter = 1001; Customer(String firstName, String lastName) { super(firstName, lastName); rentedDVDs = new ArrayList(); rentalCount = new ArrayList(); accountNumber = counter++; }

public int getAccountNumber() { return accountNumber; } public String getName() { return getFirstName() + " " + getLastName(); } public void setName(String firstName, String lastName) { setFirstName(firstName); setLastName(lastName); } public void rentDVD(DVD dvd) { for(int i=0; i1) rentalCount.set(i, rentalCount.get(i)-1); else if(rentalCount.get(i)==1) { rentalCount.remove(i); rentedDVDs.remove(i); } return; } } System.out.println("The DVD was not rented to the customer !"); } public int rentalCount() { int total = 0; for(int i: rentalCount) total += i; return total; } @Override public String toString() { return "Customer Name : " + getName() + "Account Number: " + accountNumber + "Total rental Count: " + rentalCount(); } }

DVDStore.java

package movie;

import java.util.ArrayList; import java.util.List;

public class DVDStore { List listOfDVDs; List customers; DVDStore() { listOfDVDs = new ArrayList(); customers = new ArrayList(); } public void addDVD(DVD newdvd) { DVD dvd = searchDVD(newdvd.getMovieTitle()); if(dvd == null) { listOfDVDs.add(newdvd); } else listOfDVDs.get(listOfDVDs.indexOf(newdvd)).incrementCopies(); } public void addCustomer(Customer customer) { customers.add(customer); } public DVD searchDVD(String title) { DVD dvd = null; for(DVD currentDVD: listOfDVDs) { if(currentDVD.getMovieTitle().equals(title)) { dvd = currentDVD; } } return dvd; } private int findCustomer(int accountNumber) { for(int i=0; i

DVDDriver.java

package movie;

import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner;

public class DVDDriver {

public static void menu(DVDStore store) { System.out.println("1. Search a DVD"); System.out.println("2. Check out a DVD"); System.out.println("3. Check in a DVD"); System.out.println("4. Check whether a DVD is in stock"); System.out.println("5. Print all titles of DVD"); System.out.println("6. Print all the DvDs"); System.out.println("9. Exit"); System.out.println("Enter your choice: "); Scanner consoleInt = new Scanner(System.in); Scanner consoleString = new Scanner(System.in); int choice = consoleInt.nextInt(); int accNumber; DVD dvd = null; String title = ""; if(choice != 9 && choice != 5 && choice != 6) { System.out.println("Enter the movie title: "); title = consoleString.nextLine(); } switch(choice) { case 1: dvd = store.searchDVD(title); if(dvd != null) { System.out.println(dvd); } menu(store); break; case 2: System.out.println("Enter account number of Customer: "); accNumber = consoleInt.nextInt(); if(store.rentDVD(title, accNumber)) System.out.println("Movie rented !"); menu(store); break; case 3: System.out.println("Enter account number of Customer: "); accNumber = consoleInt.nextInt(); store.returnDVD(title, accNumber); System.out.println("Movie returned !"); menu(store); break; case 4: dvd = store.searchDVD(title); if(dvd != null) { if(dvd.getNumberOfCopies()>0) System.out.println(title + " is in stock"); } menu(store); break; case 5:store.printMovieTitles(); menu(store); break; case 6: store.printAllDVDs(); menu(store); break; case 9: return; } } public static void main(String[] args) { DVDStore store = new DVDStore(); try { Scanner filereader = new Scanner(new File("movies.txt")); while(filereader.hasNextLine()) { String title = filereader.nextLine().replace("DVD ", ""); String star1 = filereader.nextLine().replace("movie ", ""); String star2 = filereader.nextLine().replace("movie ", ""); String producer = filereader.nextLine().replace("movie ", ""); String director = filereader.nextLine().replace("movie ", ""); String production = filereader.nextLine().replace("movie ", ""); String copies = filereader.nextLine(); store.addDVD(new DVD(title, new String[]{star1, star2}, director, producer, production, Integer.valueOf(copies))); } } catch (FileNotFoundException e) { System.out.println("File format is wrong !"); e.printStackTrace(); } System.out.println("Enter a customer first name: "); Scanner consoleReader = new Scanner(System.in); String fName = consoleReader.next(); System.out.println("Enter a customer last name: "); String lname = consoleReader.next(); Customer customer = new Customer(fName, lname); store.addCustomer(customer); menu(store);

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

How does an organization know if it is pursuing optimal strategies?

Answered: 1 week ago

Question

Distinguish between filtering and interpreting. (Objective 2)

Answered: 1 week ago