I also really need the bonus for this project. I found the code for this project
ID: 3918638 • Letter: I
Question
I also really need the bonus for this project. I found the code for this project but it was in c++ and I need it in java. Thanks in advance!
VIDEO STORE Overview For a family or an individual, a favorite place to go on weekends or holidays is to a video store to rent movies. A new video store in your neighborhood is about to open. However, it does not have a program to keep track of its videos and customers. The store managers want someone to write a program for their system so that the video store can function. The program should be able to perform the following operations 1. Rent a video; that is, check out a video 2. Return, or check in, a videdo 3. Create a list of videos owned by the store 4. Show the details of a particular video 5. Print a list of all videos in the store 6. Check whether a particular video is in the store Your task in this project is to write a program for the video store to perform the aforementioned operations. To do so you need to design and implement the following three components: 1- Video Class: define the data and operations of a video object. 2- Video List: maintain a list of all the videos in the store. Use singly-linked list data structure for your implementation. 3- Main program: test and perform the aforementioned operations Components Details Video Class The common things associated with a video are the (see Figure 1) a) Name of the movie b) Names of the stars (limited to two stars in this project) c) Name of the producer d) Name of the director e) Name of the production company f) Number of copies in storeExplanation / Answer
main.cpp
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include "CustomerListType.h"
#include "UnorderedLinkedListType.h"
#include "QueueType.h"
using namespace std;
class Video {
string movieName;
int movieId;
string star1;
string star2;
string producer;
string director;
string productionCompany;
int numberOfCopies;
QueueType<int> waitingList; //holds up to 15 peeps
public:
Video() {
this->movieName = "";
this->movieId = -1;
this->star1 = "";
this->star2 = "";
this->producer = "";
this->director = "";
this->productionCompany = "";
this->numberOfCopies = 0;
}
Video(string movieName,
int movieId,
string star1,
string star2,
string producer,
string director,
string productionCompany,
int numberOfCopies) {
this->movieName = movieName;
this->movieId = movieId;
this->star1 = star1;
this->star2 = star2;
this->producer = producer;
this->director = director;
this->productionCompany = productionCompany;
this->numberOfCopies = numberOfCopies;
}
void addToWaitingList(int id) {
waitingList.add(id);
}
bool checkWaitingList() {
return waitingList.isEmptyQueue();
}
bool checkQueue(int id) {
if (id == waitingList.returnFront()->getInfo()) {
waitingList.deleteFront();
return true;
}
return false;
}
void printWaitingList() {
waitingList.print();
}
void displayAllInformation() {
cout << "Name: " << this->movieName << endl;
cout << "ID: " << this->movieId << endl;
cout << "Starring: " << this->star1 << endl;
cout << "Starring: " << this->star2 << endl;
cout << "Producer: " << this->producer << endl;
cout << "Director: " << this->director << endl;
cout << "Production Company: " << this->productionCompany << endl;
cout << "Copes in stock: " << this->numberOfCopies << endl;
system("Pause");
}
void rentVideo() {
if (this->numberOfCopies > 0) {
numberOfCopies--;
cout << "Renting: " << this->movieName << endl;
}
}
void checkInVideo() {
this->numberOfCopies++;
cout << this->movieName << " returned succesfully." << endl;
}
void createVideo() {
string strTemp;
int numTemp;
cout << "--Setting new movie-- ";
cout << "Movie Name: ";
cin >> strTemp;
this->movieName = strTemp;
cin.clear();
cout << "Movie ID: ";
cin >> numTemp;
this->movieId = numTemp;
cin.clear();
cout << "Actor 1: ";
cin >> strTemp;
this->star1 = strTemp;
cin.clear();
cout << "Actor 2: ";
cin >> strTemp;
this->star2 = strTemp;
cin.clear();
cout << "Producer: ";
cin >> strTemp;
this->producer = strTemp;
cin.clear();
cout << "Director: ";
cin >> strTemp;
this->director = strTemp;
cin.clear();
cout << "Production Company: ";
cin >> strTemp;
this->productionCompany = strTemp;
cin.clear();
cout << "Number of copies in stock: ";
cin >> numTemp;
this->numberOfCopies = numTemp;
cin.clear();
cout << "Movie data set." << endl;
system("pause");
}
string getName() {
return this->movieName;
}
int getId() {
return this->movieId;
}
string getStar1() {
return this->star1;
}
string getStar2() {
return this->star2;
}
string getProducer() {
return this->producer;
}
string getDirector() {
return this->director;
}
string getProductionCompany() {
return this->productionCompany;
}
int getNumOfCopies() {
return this->numberOfCopies;
}
void setName(string name) {
this->movieName = name;
}
void setId(int id) {
this->movieId = id;
}
void setStar1(string star) {
this->star1 = star;
}
void setStar2(string star) {
this->star2 = star;
}
void setProducer(string prod) {
this->producer = prod;
}
void setDirector(string direct) {
this->director = direct;
}
void setProductionCompany(string comp) {
this->productionCompany = comp;
}
void setNumOfCopies(int cop) {
this->numberOfCopies = cop;
}
};
class videoStore {
int numberOfVideos;
int numberOfCustomers;
Video video; //temp video
Customer customer; //temp customer
vector<Video> videolist;
vector<Customer> customerList;
vector<string> rentedVideos; //push video name of rented videos
public:
void rentVideo() {
int mId;
int cId;
cout << "Rent a movie" << endl;
for (int i = 0; i < videolist.size(); i++) {
cout << "Name: " << videolist[i].getName() << " Id: " << videolist[i].getId() << " Stock:" << videolist[i].getNumOfCopies() << endl;
}
cout << "Movie Id: ";
cin >> mId;
cout << "Customer Id: ";
cin >> cId;
if (videolist[mId].getNumOfCopies() > 0 && !(videolist[mId].checkWaitingList())) {
cout << "Movie is out of stock..." << endl;
cout << "Checking waitlist" << endl;
cout << endl;
if (videolist[mId].checkQueue(cId)) {
cout << "Congrats, your video is ready" << endl;
videolist[mId].setNumOfCopies(videolist[mId].getNumOfCopies() - 1);
customerList[cId].rent(videolist[mId].getName()); //sends video name to customer renting list
system("Pause");
return;
}
if (!(videolist[mId].checkWaitingList())) {
system("CLS");
cout << "Sorry there is a waiting list... these are the customers ID's who are still waiting" << endl;
cout << endl;
videolist[mId].printWaitingList();
cout << "You will be added to the waitlist" << endl;
videolist[mId].addToWaitingList(cId);
system("Pause");
return;
}
}
else if (videolist[mId].getNumOfCopies() <= 0) {
cout << "Sorry there is no more of this video in stock..." << endl;
cout << "You will be added to the waitlist" << endl;
videolist[mId].addToWaitingList(cId);
system("Pause");
return;
} else {
customerList[cId].rent(videolist[mId].getName()); //sends video name to customer renting list
videolist[mId].rentVideo(); //updates stock
rentedVideos.push_back(videolist[mId].getName()); //updates rented list
cout << customerList[cId].getName() << " - Renting: " << videolist[mId].getName() << endl;
system("Pause");
}
}
void returnVideo() {
int mId;
int cId;
cout << "Returning Video" << endl;
cout << "Movie Id:";
cin >> mId;
cin.ignore();
videolist[mId].checkInVideo();
cout << "Video is now available for renting" << endl;
for (int i = 0; i < rentedVideos.size(); i++) {
if (videolist[mId].getName() == rentedVideos[i]) {
rentedVideos[i].erase();
}
}
system("pause");
}
void displayAllRentedVideos() {
system("CLS");
cout << "All rented videos" << endl;
for (int i = 0; i < rentedVideos.size(); i++) {
cout << "[" << i << "]: " << rentedVideos[i] << endl;
}
cout << "~end of list~" << endl;
system("pause");
}
void addVideo() {
video.createVideo();
videolist.push_back(video);
}
void showVideoDetails() {
system("CLS");
int videoId;
cout << "~~ Videos ~~" << endl;
for (int i = 0; i < videolist.size(); i++) {
cout <<"Video [" << i << "]: " << videolist[i].getName() << endl;
if (!(videolist[i].checkWaitingList())) {
cout << "[ID] Waiting List:" << endl;
videolist[i].printWaitingList();
cout << endl;
}
}
cout << "End of list" << endl;
cout << endl;
cout << "Show video: ";
cin >> videoId;
system("CLS");
videolist[videoId].displayAllInformation();
cin.clear();
}
void displayCustomerRentedVideos() {
system("CLS");
cout << "Customer ID:";
int cId;
cin >> cId;
cin.ignore();
cout << endl;
cout << "List:" << endl;
customerList[cId].displayRentedVideos();
system("pause");
}
void showCustomerDetails() {
system("CLS");
int customerId;
for (int i = 0; i < customerList.size(); i++) {
cout << "~~ Customers ~~" << endl;
cout << "Customer [" << i << "]: " << customerList[i].getName() << endl;
}
cout << "End of list" << endl;
cout << endl;
cout << "Show customer: ";
cin >> customerId;
system("CLS");
customerList[customerId].displayAllInformation();
cin.clear();
}
void createNewCustomer() {
customer.newCustomer();
customerList.push_back(customer);
}
videoStore() {
numberOfVideos = 0;
numberOfCustomers = 0;
}
};
int main() {
videoStore store;
bool inUse = true;
int userInp;
while (inUse) {
system("CLS");
cout << "--Welcome-- ";
cout << "[0]Rent a video ";//rents video for a customer
cout << "[1]Add video ";//adds to video database
cout << "[2]Show video detail ";//show detail, check in stock
cout << "[3]Return video ";
cout << "[4]List of videos rented by a customer ";
cout << "[5]Display videos being rented ";
cout << "[6]Create new customer ";
cout << "[7]Show customer details ";
cout << endl;
cout << "[-1 to exit]: ";
cin >> userInp;
cin.clear();
switch (userInp) {
case 0:
store.rentVideo();
break;
case 1:
store.addVideo();
break;
case 2:
store.showVideoDetails();
break;
case 3:
store.returnVideo();
break;
case 4:
store.displayCustomerRentedVideos();
break;
case 5:
store.displayAllRentedVideos();
break;
case 6:
store.createNewCustomer();
break;
case 7:
store.showCustomerDetails();
break;
case -1:
inUse = false;
break;
default:
cout << "Error... exiting progrom" << endl;
inUse = false;
break;
}
}
system("Pause");
return 0;
}
Customer.cpp
#include <string>
#include <iostream>
#include "Customer.h"
using namespace std;
Customer::Customer() {
name = "NA";
id = -1;
}
Customer::Customer(string name, int id) {
this->name = name;
this->id = id;
}
void Customer::newCustomer() {
system("CLS");
cout << "~~Creating new customer~~" << endl;
string name = "";
int id = -1;
cout << "Name: ";
cin >> name;
cin.clear();
cout << "Id: ";
cin >> id;
this->name = name;
this->id = id;
cout << "Customer created..." << endl;
system("Pause");
}
void Customer::displayAllInformation() {
cout << "Name: " << this->name << endl;
cout << "Id: " << this->id << endl;
system("pause");
}
void Customer::setName(string name) {
this->name = name;
}
string Customer::getName() {
return this->name;
}
void Customer::setId(int id) {
this->id = id;
}
int Customer::getId() {
return this->id;
}
void Customer::print() {
cout << "Name: " << this->name << endl;
}
Customer.h
#pragma once
#include <string>
#include <iostream>
#include "QueueType.h"
using namespace std;
class Customer {
string name;
int id;
QueueType<string> rentedVideos;
public:
Customer();
Customer(string, int);
void newCustomer();
void displayAllInformation();
void setName(string);
string getName();
void setId(int id);
int getId();
void rent(string name) {
rentedVideos.add(name);
}
void displayRentedVideos() {
rentedVideos.print();
}
void print();
};
CustomerListType.cpp
#include "CustomerListType.h"
#include "UnorderedLinkedListType.h"
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
void CustomerListType::createCustList() {
int numOfCustomers;
string tempName;
tempCust = new Customer();
inputfile.open(fileName);
inputfile >> numOfCustomers;
inputfile << endl;
for (int i = 0; i < numOfCustomers; i++) {
inputfile >> tempName;
tempCust->setName(tempName);
this->insert(*tempCust);
inputfile << endl;
}
inputfile.close();
cout << "Customers added" << endl;
cout << endl;
delete tempCust;
tempCust = 0;
}
void CustomerListType::addCustomer() {
string tempName;
tempCust = new Customer();
cout << "New Customer name: ";
cin.clear();
getline(cin, tempName);
tempCust->setName(tempName);
this->insert(*tempCust);
cout << "Customer added" << endl;
cout << endl;
numberOfCustomers++;
delete tempCust;
tempCust = 0;
outputfile.open(outputFileName);
outputfile << numberOfCustomers << endl;
for (int i = 0; i < numberOfCustomers; i++) {
outputfile << this->getAt(i)->getInfo().getName();
outputfile << endl;
}
outputfile.close();
}
CustomerListType.h
#pragma once
#include "UnorderedLinkedListType.h"
#include "Customer.h"
#include <fstream>
class CustomerListType : public UnorderedLinkedListType<Customer>
{
Customer* tempCust;
int numberOfCustomers;
string fileName;
string outputFileName;
fstream inputfile;
ofstream outputfile;
public:
CustomerListType(string fileName, string outputFileName) : UnorderedLinkedListType() {
this->fileName = fileName;
inputfile.open(fileName);
inputfile >> numberOfCustomers;
inputfile.close();
this->outputFileName = outputFileName;
cout << "Customer List Created" << endl;
system("pause");
}
void createCustList();
void addCustomer();
virtual void print() {
for (int i = 0; i < this->getSize(); i++) {
getAt(i)->getInfo().print();
}
}
};
QueueType.h
#pragma once
#include "Node.h"
template<class Type>
class QueueType {
int size;
int maxSize;
Node<Type>* front;
Node<Type>* back;
public:
QueueType() {
this->size = this->maxSize = 0;
maxSize = 15; //default size
front = 0;
back = 0;
}
void print() {
Node<Type>* temp;
temp = back;
while (temp != 0) {
cout << temp->getInfo() << endl;
temp = temp->getNext();
}
delete temp; //no leaks
}
void add(Type info) {
if (this->back == 0) {
back = new Node<Type>(info);
this->front = back;
size++;
return;
}
Node<Type>* temp = new Node<Type>(info);
temp->setNext(this->back);
this->back = temp;//temp address is the new element at the rear of the line
size++;
}
void deleteFront() {
Node<Type>* temp = this->back;
while (temp->getNext()!= 0) {
temp = temp->getNext();
}
front = temp; //sets last element as the temp address which should be 1 before the last...
temp = temp->getNext(); //last element
delete temp; //removes last element address
front->setNext(0);
size--; //updates counter
}
bool isEmptyQueue() {
if (this->size == 0) {
return true;
}
return false;
}
bool isFullQueue() {
if (this->size == maxSize) {
return true;
}
return false;
}
void initializeQueue() {
this->front = 0;
this->back = 0;
size = 0;
maxSize = 99; //default size
}
Node<Type>* returnFront() {
return this->front;
}
Node<Type>* returnBack() {
return this->back;
}
};
Node.h
#pragma once
template <class Type>
class Node {
Type info;
Node<Type>* next;
Node<Type>* previous;
public:
Node() {
this->next = 0;
this->previous = 0;
}
Node(Type info) {
this->next = 0;
this->previous = 0;
this->info = info;
}
Type getInfo() {
return info;
}
Node<Type>* getNext() {
return this->next;
}
void setNext(Node<Type>* next) {
this->next = next;
}
void setPrev(Node<Type>* prev) {
this->previous = prev;
}
void setInfo(Type info) {
this->info = info;
}
};
StackType.h
#include "Node.h"
template<class Type>
class StackType {
int maxSize;
int size;
Node<Type>* head;
public:
StackType() {
this->maxSize = 99; //default
cout << "Creating stack..." << endl;
system("pause");
system("CLS");
initializeStack();
}
StackType(const StackType<Type>* otherStack) {
copyStack();
}
void initializeStack() {
this->head = 0;
size = 0;
}
void push(Type info) {
if (this->size <= this->maxSize) {
Node<Type>* temp = new Node<Type>();
temp->setInfo(info);
temp->setNext(this->head);
this->head = temp;
size++;
}
else {
cout << "Stack is full..." << endl;
system("pause");
}
}
void push(Node<Type>* info) {
if (this->size <= this->maxSize) {
info->setNext(this->head);
this->head = info;
size++;
}
else {
cout << "Stack is full..." << endl;
system("pause");
}
}
void pop() {
if (this->head != NULL) {
Node<Type>* temp = head;
if (head->getNext() != NULL) {
this->head = head->getNext();
}
else {
this->head = 0;
}
size--;
}
}
bool isFullStack() {
if (this->size == this->maxSize) {
return true;
}
else {
return false;
}
return false;
}
bool isEmptyStack() {
if (this->size == 0) {
return true;
}
return false;
}
int getSize() {
return this->size;
}
int getMaxSize() {
return this->maxSize;
}
Node<Type>* top() {
return this->head;
}
void copyStack(StackType<Type>& otherStack) {
int x = this->size;
for (int i = 0; i < x; i++) {
this->pop();
}
this->head = 0;
this->size = otherStack.getSize();
this->maxSize = otherStack.getMaxSize();
Node<Type>* temp;
temp = otherStack.top();
this->head = temp;
}
StackType<Type>& operator=(StackType<Type>& oStack) {
if (this == &oStack) {
return *this;
}
copyStack(oStack);
}
void reverseStack(StackType<Type> &otherStack) {
this->maxSize = otherStack.getMaxSize();
for (int i = 0; i < this->size; i++) {
this->pop();
}
for (int i = 0; i < otherStack.getSize(); i++) {
Node<Type>* temp;
Node<Type>* getInf;
getInf = otherStack.top(); //getInfo holds the address of the otherstack's head
for (int j = i; j > 0; j--) {
getInf = getInf->getNext();
}//this loop should run through the linked list of the other stack...
temp = new Node<Type>(getInf->getInfo()); //creates a new ptr that holds the address of the info from the old ptr
this->push(temp);
}
}
};
#pragma once
UnorderedLinkedListType.h
#pragma once
#include "Node.h"
template <class Type>
class UnorderedLinkedListType {
int size;
Node<Type>* head;
Node<Type>* tail;
public:
UnorderedLinkedListType() {
size = 0;
head = 0;
tail = 0;
}
void insert(Type info) {
if (head == 0) {
head = new Node<Type>(); //create new node
head->setInfo(info); //insert info to node
tail = head;
size++;
return;
}
Node<Type>* temp;//create temp node
temp = new Node<Type>();
temp->setNext(head);
temp->setInfo(info);
head->setPrev(temp);
head = temp;
tail->setNext(head);
size++;
}
int getSize() {
return this->size;
}
Node<Type>* getHead() {
return this->head;
}
Node<Type>* getTail() {
return this->tail;
}
Node<Type>* getAt(int pos) {
Node<Type>* temp;
temp = this->head; //starts at head address position
for (int i = 0; i < pos; i++) {
temp = temp->getNext();
}
return temp;
}
virtual void print() = 0;
};
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.