Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Store {
- //array for Videos space allocated = 100
- static Video[] videos;
- //array for Customers space allocated = 3
- static Customer[] customers;
- static Scanner keyboard;
- public static void main(String[] args) {
- videos = new Video[100];
- //populate the array for Videos
- videos[0] = new DVD ("Star Wars", 3.5, "Lucas");
- videos[1] = new DVD ("Death Note", 2.5, "Tarantino");
- videos[2] = new VCD ("Death Note", 1.5, "A", 2006);
- videos[3] = new DVD ("Shrek", 2.0, "Agogo");
- videos[4] = new VHS ("Transformers", 3.25);
- videos[5] = new VHS ("The Eye", 3.0);
- videos[6] = new VCD ("Fantastic 4", 2.0, "B", 2004);
- videos[7] = new VCD ("Shampoo", 2.0, "B", 2007);
- videos[8] = new DVD ("Bourne Ultimatum", 3.0,"Ang Lee");
- videos[9] = new VCD ("Bourne Ultimatum", 3.0, "A", 2007);
- videos[10] = new VHS ("Bourne Ultimatum", 3.0);
- customers = new Customer[100];
- //populate the array for Customers
- customers[0] = new Customer("Lighto Yagami", "012-888-9808", 23, 0);
- customers[1] = new Customer("L.Lawliet", "011-222-3333", 24, 0 );
- customers[2] = new Customer("Misa Misa", "020-452-5656", 21, 0);
- //Declarations
- keyboard = new Scanner(System.in);
- boolean quit = false; //flag for do while loop
- String option;
- String movieTitle;
- double movieLength;
- String customerName;
- String mediumType;
- String directorName;
- String movieRating;
- int movieYear;
- int customerIndex = -1;
- do{
- //Menu for the user
- System.out.println("a) Renting a DVD, VCD, or VHS");
- System.out.println("b) Returning a DVD, VCD or VHS");
- System.out.println("c) Buy a video");
- System.out.println("d) Print out customer information");
- System.out.println("e) Add a video");
- System.out.println("f) Print out information for all the DVDs.");
- System.out.println("g) Exit Program");
- option = keyboard.nextLine();
- //See the user key in which option
- // Rent a video
- if (option.equals("a") || option.equals("A")) {
- rentingMovie();
- }
- //Returning a video
- else if (option.equals("b") || option.equals("B")) {
- returningMovie();
- }
- //Buying a video
- else if (option.equals("c") || option.equals("C")) {
- buyingMovie();
- } // end else if line 109
- //Print out customer information
- else if (option.equals("d") || option.equals("D")) {
- System.out.println("Please enter customer name");
- customerName = keyboard.nextLine();
- for (int i=0; i<customers.length; i++) {
- if (customers[i] == null) {
- customerIndex = -1;
- break;
- }
- if (customers[i].getName().toLowerCase().equals(customerName.toLowerCase())) {
- customerIndex = i;
- break;
- }
- if (i == (customers.length-1)) {
- customerIndex = -1;
- break;
- }
- }
- if (customerIndex != -1) {
- System.out.println("Customer :" + customers[customerIndex].getName());
- System.out.println("Phone :" + customers[customerIndex].getPhoneNumber());
- System.out.println("Age : " + customers[customerIndex].getAge());
- }
- }
- //Add a new video object
- else if (option.equals("e") || option.equals("E")) {
- for (int i=0; i<videos.length; i++) {
- if (videos[i] == null) {
- System.out.println("Please enter the title of movie:");
- movieTitle = keyboard.nextLine();
- System.out.println("Please enter the length of the movie:");
- movieLength = Double.parseDouble( keyboard.nextLine() );
- System.out.println("Please enter the medium type of this movie:");
- mediumType = keyboard.nextLine();
- if (mediumType.equals("DVD") || mediumType.equals("dvd")) {
- System.out.println("Please enter director name:");
- directorName = keyboard.nextLine();
- videos[i] = new DVD (movieTitle, movieLength,directorName);
- System.out.println("You've successfully added new DVD video.");
- }
- else if (mediumType.equals("VCD") || mediumType.equals("vcd")) {
- System.out.println("Please enter movie rating:");
- movieRating = keyboard.nextLine();
- System.out.println("Please enter movie year:");
- movieYear = Integer.parseInt(keyboard.nextLine() );
- videos[i] = new VCD (movieTitle, movieLength, movieRating, movieYear);
- System.out.println("You've successfully added new VCD");
- }
- else if (mediumType.equals("VHS") || mediumType.equals("vhs")) {
- videos[i] = new VHS (movieTitle, movieLength);
- System.out.println("You've successfully added new VHS.");
- }
- break;
- }
- }
- }
- //Print all information about video
- else if (option.equals("f") || option.equals("f")) {
- for (int i = 0; i <videos.length; i++) {
- if (videos[i] == null) {
- break;
- }
- videos[i].print();
- }
- }
- //Exit the program
- else if (option.equals("g") || option.equals("G")) {
- System.out.println("Thank you for using this system.");
- quit = true; //if quit = true then the loop will stop then program stops.
- }
- else {
- System.out.println("You do not enter a valid option, please try again.");
- }
- }while (quit == false); //if quit = false then the loop will continue.
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- public static void rentingMovie() {
- String movieTitle;
- String mediumType;
- int indexDVD = -1;
- int indexVCD = -1;
- int indexVHS = -1;
- boolean found = false;
- System.out.println("What movie do you want to rent?");
- movieTitle = keyboard.nextLine();
- for (int i=0; i<videos.length; i++) { //problem
- if (videos[i] == null) {
- break;
- }
- if (videos[i].getTitle().toLowerCase().equals(movieTitle.toLowerCase())) {
- found = true;
- if (videos[i] instanceof DVD) { // the 3 instanceof should be inside the first loop
- System.out.println("DVD");
- indexDVD = i; // remembering the index of the DVD
- }
- else if (videos[i] instanceof VCD) {
- System.out.println("VCD");
- indexVCD = i; // remembering the index of the VCD
- }
- else if (videos[i] instanceof VHS) {
- System.out.println("VHS");
- indexVHS = i; // remembering the index of the VHS
- }
- }
- if (i == (videos.length-1)) {
- }
- }
- if (found == false) {
- System.out.println("The movie name could not be found");
- return;
- }
- System.out.println("Which medium type do you want?");
- mediumType = keyboard.nextLine();
- if (mediumType.equals("DVD") || (mediumType.equals("dvd")) && indexDVD != -1) {
- if (videos[indexDVD].getStatus() == 'O') {
- System.out.println("Sorry, the DVD version of this video has been rented out.");
- return;
- }
- else
- videos[indexDVD].setStatus('O');
- System.out.println("Thank you. You've successfully rented this DVD.");
- }
- else if (mediumType.equals("VCD") || (mediumType.equals("vcd")) && indexVCD != -1) {
- if (videos[indexVCD].getStatus() == 'O') {
- System.out.println("Sorry, the VCD version of this video has been rented out.");
- return;
- }
- else
- videos[indexVCD].setStatus('O');
- System.out.println("Thank you. You've successfully rented this VCD.");
- }
- else if (mediumType.equals("VHS") || (mediumType.equals("vhs")) && indexVHS != -1) {
- if (videos[indexVHS].getStatus() == 'O') {
- System.out.println("Sorry, the VHS version of this video has been rented out.");
- return;
- }
- else
- videos[indexVHS].setStatus('O');
- System.out.println("Thank you. You've successfully rented this VHS.");
- }
- else {
- System.out.println("Sorry, the medium type you requested was not found.");
- }
- } //end of rentingMethod
- public static void returningMovie() {
- String movieTitle;
- String mediumType;
- int indexDVD = -1;
- int indexVCD = -1;
- int indexVHS = -1;
- boolean found = false;
- System.out.println("What movie do you want to return?");
- movieTitle = keyboard.nextLine();
- for (int i=0; i<videos.length; i++) {
- if (videos[i] == null) {
- break;
- }
- if (videos[i].getTitle().toLowerCase().equals(movieTitle.toLowerCase())) {
- found = true;
- if (videos[i] instanceof DVD) { // the 3 instanceof should be inside the first loop
- System.out.println("DVD");
- indexDVD = i; // remembering the index of the DVD
- }
- else if (videos[i] instanceof VCD) {
- System.out.println("VCD");
- indexVCD = i; // remembering the index of the VCD
- }
- else if (videos[i] instanceof VHS) {
- System.out.println("VHS");
- indexVHS = i; // remembering the index of the VHS
- }
- }
- if (i == (videos.length-1)) {
- }
- }
- if (found == false) {
- System.out.println("The movie name could not be found");
- return;
- }
- System.out.println("Which medium type do you want?");
- mediumType = keyboard.nextLine();
- if (mediumType.equals("DVD") || (mediumType.equals("dvd")) && indexDVD != -1) {
- if (videos[indexDVD].getStatus() == 'O') {
- videos[indexDVD].setStatus('I');
- System.out.println("Thank you. You've successfully returned this DVD");
- return;
- }
- else
- System.out.println("The DVD you attempted to return is in store. Please try again.");
- }
- else if (mediumType.equals("VCD") || (mediumType.equals("vcd")) && indexVCD != -1) {
- if (videos[indexVCD].getStatus() == 'O') {
- videos[indexVCD].setStatus('I');
- System.out.print("Thank you. You've successfully returned this VCD");
- return;
- }
- else
- System.out.println("The VCD you attempted to return is in store. Please try again.");
- }
- else if (mediumType.equals("VHS") || (mediumType.equals("vhs")) && indexVHS != -1) {
- if (videos[indexVHS].getStatus() == 'O') {
- videos[indexVHS].setStatus('I');
- System.out.println("Thank you. You've successfully returned this DVD");
- return;
- }
- else
- videos[indexVHS].setStatus('O');
- System.out.println("The VHS you attempted to return is in store. Please try again.");
- }
- else {
- System.out.println("Sorry, the medium type you requested was not found.");
- }
- }//end of returningMethod
- public static void buyingMovie() {
- String customerName;
- boolean found = false;
- String movieTitle;
- String mediumType;
- int indexDVD = -1;
- int indexVCD = -1;
- int indexVHS = -1;
- int customerIndex = -1;
- //get customer name
- System.out.println("Please enter name");
- customerName = keyboard.nextLine();
- for (int i=0; i<customers.length; i++) {
- if (customers[i] == null) {
- break;
- }
- if (customers[i].getName().toLowerCase().equals(customerName.toLowerCase())) {
- found = true;
- customerIndex = i;
- break;
- }
- if (i == (customers.length-1)) {
- found = false;
- }
- }
- if (found == false) {
- System.out.println("The customer name could not be found");
- return;
- }
- System.out.println("What movie do you want to buy?");
- movieTitle = keyboard.nextLine();
- for (int i=0; i<videos.length; i++) {
- if (videos[i] == null) {
- break;
- }
- if (videos[i].getTitle().toLowerCase().equals(movieTitle.toLowerCase())) {
- found = true;
- if (videos[i] instanceof DVD) { // the 3 instanceof should be inside the first loop
- System.out.println("DVD");
- indexDVD = i; // remembering the index of the DVD
- }
- else if (videos[i] instanceof VCD) {
- System.out.println("VCD");
- indexVCD = i; // remembering the index of the VCD
- }
- else if (videos[i] instanceof VHS) {
- System.out.println("VHS");
- indexVHS = i; // remembering the index of the VHS
- }
- }
- if (i == (videos.length-1)) {
- }
- }
- if (found == false) {
- System.out.println("The movie name could not be found");
- return;
- }
- System.out.println("Which medium type do you want?");
- mediumType = keyboard.nextLine();
- if (mediumType.equals("DVD") || (mediumType.equals("dvd")) && indexDVD != -1) {
- if (videos[indexDVD].getStatus() == 'O') {
- System.out.println("Sorry, the DVD version of this video has been rented out and is not available to purchase at this time");
- return;
- }
- else
- System.out.println("Customer:" + customers[customerIndex].getName());
- System.out.println("Video Title:" + videos[indexDVD].getTitle()); //
- System.out.println("Video Type: DVD");
- System.out.println("Actual Price:" + videos[indexDVD].getPrice());
- //customers[customerIndex].setAmount();
- System.out.println("Thank you. You've successfully purchased this DVD.");
- videos[indexDVD] = null;
- }
- else if (mediumType.equals("VCD") || mediumType.equals("vcd") && indexVCD != -1) {
- if (videos[indexVCD].getStatus() == 'O') {
- System.out.print("Sorry, the VCD version of this video has been rented out and is not available to purchase at this time");
- return;
- }
- else
- System.out.println("Customer:" + customers[customerIndex].getName());
- System.out.println("Video Title:" + videos[indexVCD].getTitle()); //
- System.out.println("Video Type: VCD");
- System.out.println("Actual Price:" + videos[indexVCD].getPrice());
- //customers[customerIndex].setAmount();
- System.out.println("Thank you. You've successfully purchased this VCD.");
- videos[indexVCD] = null;
- }
- else if (mediumType.equals("VHS") || (mediumType.equals("vhs")) && indexVHS != -1) {
- if (videos[indexVHS].getStatus() == 'O') {
- System.out.println("Sorry, the VHS version of this video has been rented out and is not available to purchase at this time");
- return;
- }
- else
- System.out.println("Customer:" + customers[customerIndex].getName());
- System.out.println("Video Title:" + videos[indexVHS].getTitle()); //
- System.out.println("Video Type: VHS");
- System.out.println("Actual Price:" + videos[indexVHS].getPrice());
- //customers[customerIndex].setAmount();
- System.out.println("Thank you. You've successfully purchased this VHS.");
- videos[indexVHS] = null;
- }
- else {
- System.out.println("Sorry, the medium type you requested was not found.");
- }
- Video[] temporaries = new Video[100];
- int n = 0;
- for (int i=0; i<videos.length; i++){
- if (videos[i] != null) {
- temporaries[n++] = videos[i];
- }
- }
- videos = temporaries;
- }//end of buyingMovie method
- }//end class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement