Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main;
- import java.util.ArrayList;
- import java.util.Iterator;
- import java.util.Scanner;
- import javax.xml.ws.spi.Invoker;
- import model.Game;
- import model.Inventory;
- import model.Item;
- import model.Movie;
- public class Store {
- public static Scanner in;
- public static Inventory inventory;
- public static int day = 1;
- public static void main(String[] args) {
- String command;
- in = new Scanner(System.in);
- inventory = new Inventory();
- while (true) {
- showMenu();
- command = in.nextLine();
- System.out.println();
- switch (command) {
- case "L":
- listItemMenu();
- break;
- case "AG":
- addGameMenu();
- break;
- case "AM":
- addMovieMenu();
- break;
- case "RG":
- rentGameMenu();
- break;
- case "RM" :
- rentMovieMenu();
- break;
- case "GG" :
- returnGameMenu();
- break;
- case "GM" :
- returnMovieMenu();
- break;
- case "BG" :
- buyGameMenu();
- break;
- case "E":
- System.out.println("Program terminated");
- System.exit(0);
- break;
- case "T":
- timePassingMenu();
- break;
- default:
- System.out.println("Invalid command.");
- break;
- }
- System.out.println();
- }
- }
- private static void showMenu(){
- System.out.println("########################################");
- System.out.println("Video Store Menu (Day " + day + ")");
- System.out.println("########################################");
- System.out.println("AG)\tAdd game\tAM)\tAdd movie");
- //System.out.println("AM)\tAdd movie");
- System.out.println("RG)\tRent game\tRM)\tRent movie");
- //System.out.println("RM)\tRent movie");
- System.out.println("GG)\tReturn game\tGM)\tReturn movie");
- //System.out.println("GM)\tReturn movie");
- System.out.println("BG)\tBuy game\tL)\tList all items");
- System.out.println("T)\tTime passing\tE)\tExit");
- System.out.println("----------------------------------------");
- System.out.print("Enter input command : ");
- }
- private static void listItemMenu() {
- // TODO Auto-generated method stub
- System.out.println("----------------------------------------");
- System.out.println("List all items in inventory");
- System.out.println("----------------------------------------");
- System.out.println("Game (Total " + inventory.getTotalGames() + "):");
- System.out.println("----------------------------------------");
- inventory.listGames();
- System.out.println("----------------------------------------");
- System.out.println("Movie (Total " + inventory.getTotalMovies() + "):");
- System.out.println("----------------------------------------");
- inventory.listMovies();
- }
- private static void addGameMenu() {
- // TODO Auto-generated method stub
- System.out.println("----------------------------------------");
- System.out.println("Add game to inventory");
- System.out.println("----------------------------------------");
- int rand = (int)(Math.random() * 9);
- System.out.println("Name : " + Inventory.gameNames[rand]);
- System.out.println("Rate : " + Inventory.gameRatings[rand]);
- System.out.println("Price : " + Inventory.gamePrices[rand]);
- inventory.addItem(new Game(Inventory.gameNames[rand],Inventory.gameRatings[rand],Inventory.gamePrices[rand]));
- inventory.sortItems();
- }
- private static void addMovieMenu() {
- // TODO Auto-generated method stub
- System.out.println("----------------------------------------");
- System.out.println("Add movie to inventory");
- System.out.println("----------------------------------------");
- int rand = (int)(Math.random() * 9);
- System.out.println("Name : " + Inventory.movieNames[rand]);
- System.out.println("Rate : " + Inventory.movieRatings[rand]);
- System.out.println("Price : " + Inventory.moviePrices[rand]);
- inventory.addItem(new Movie(Inventory.movieNames[rand],Inventory.movieRatings[rand],Inventory.moviePrices[rand]));
- inventory.sortItems();
- }
- private static void rentGameMenu(){
- System.out.println("----------------------------------------");
- System.out.println("Rent game");
- System.out.println("----------------------------------------");
- String gameName;
- String renterName;
- int rentOption;
- // TODO Fill Code
- System.out.println("Enter game name : ");
- gameName = in.nextLine();
- int index = inventory.searchForRentableGame(gameName);
- Game t = null;
- if(index != -1) {
- t = (Game) Inventory.items.get(index);
- System.out.println("Choose the rental options from 1-4 : ");
- System.out.println("1) $3.00 for 1 week");
- System.out.println("2) $5.40 for 2 weeks");
- System.out.println("3) $7.00 for 3 weeks");
- System.out.println("4) $9.00 for 4 weeks");
- System.out.println("Enter your option : ");
- rentOption = in.nextInt();
- in.next();
- System.out.println("Enter your name : ");
- renterName = in.next();
- System.out.println("You rented the game successfully. The game ID is "+t.getId()+".");
- System.out.println("Please inform the game ID when you return it.");
- System.out.println("Please return the game within Day "+(rentOption*7+1)+"."+ " Late fee is "+t.getLateFeePerDay()+ "/days.");
- t.rent(renterName, rentOption);
- }
- else {
- System.out.println("The game is not available to rent. Back to menu.");
- }
- }
- private static void rentMovieMenu(){
- System.out.println("----------------------------------------");
- System.out.println("Rent movie");
- System.out.println("----------------------------------------");
- String movieName;
- String renterName;
- // TODO Fill Code
- System.out.println("Enter movie name : ");
- movieName = in.next();
- int index = inventory.searchForRentableGame(movieName);
- Movie t = (Movie) Inventory.items.get(index);
- if(index != -1) {
- System.out.println("Enter your name : ");
- renterName = in.next();
- System.out.println("You rented the movie successfully. The movie ID is "+t.getId()+".");
- System.out.println("Please inform the movie ID when you return it.");
- t.rent(renterName, 0);
- }
- else {
- System.out.println("The movie is not available to rent. Back to menu.");
- }
- }
- private static void returnGameMenu(){
- System.out.println("----------------------------------------");
- System.out.println("Return Game");
- System.out.println("----------------------------------------");
- int gameID;
- // TODO Fill Code
- System.out.println("Enter game ID : ");
- gameID = in.nextInt();
- in.next();
- Game t = null;
- for(int i=0;i<Inventory.items.size();++i) {
- if(Inventory.items.get(i) instanceof Game && Inventory.items.get(i).getId()==gameID) {
- t = (Game) Inventory.items.get(i);
- break;
- }
- }
- if(t!=null) {
- if(day-t.getGiveBackDate()<=0) {
- System.out.println("The rental fee is $"+t.giveBack()+".");
- }
- else {
- System.out.println("The rental fee is $"+t.giveBack()+". (Late "+(day-t.getGiveBackDate())+" days)");
- }
- }
- else {
- System.out.println("the game is not rented. Back to menu.");
- }
- }
- private static void returnMovieMenu(){
- System.out.println("----------------------------------------");
- System.out.println("Return movie");
- System.out.println("----------------------------------------");
- int movieID;
- // TODO Fill Code
- System.out.println("Enter movie ID : ");
- movieID = in.nextInt();
- in.next();
- Movie t = null;
- for(int i=0;i<Inventory.items.size();++i) {
- if(Inventory.items.get(i) instanceof Game && Inventory.items.get(i).getId()==movieID) {
- t = (Movie) Inventory.items.get(i);
- break;
- }
- }
- if(t!=null) {
- System.out.println("The rental fee is $"+t.giveBack()+".");
- }
- else {
- System.out.println("the movie is not rented. Back to menu.");
- }
- }
- private static void buyGameMenu(){
- System.out.println("----------------------------------------");
- System.out.println("Buy Game");
- System.out.println("----------------------------------------");
- String gameName;
- String buyerName;
- // TODO Fill Code
- System.out.println("Enter game name : ");
- gameName = in.next();
- int index = inventory.searchForRentableGame(gameName);
- Game t = (Game) Inventory.items.get(index);
- if(index != -1) {
- System.out.println("Enter your name : ");
- buyerName = in.next();
- System.out.println("The price is $"+t.getPrice()+".");
- System.out.println("Thank you for buying");
- }
- else {
- System.out.println("The game is not available to buy. Back to menu.");
- }
- }
- private static void timePassingMenu() {
- // TODO Auto-generated method stub
- System.out.println("----------------------------------------");
- System.out.println("Simulate Time Passing");
- System.out.println("----------------------------------------");
- System.out.print("Enter the number of days passing : ");
- try{
- int days = in.nextInt();
- if (days <= 0)
- {
- System.out.println("The number of days should be more than 0.");
- }
- else
- {
- Store.day += days;
- System.out.println("Now is Day " + Store.day + ".");
- }
- }
- catch(Exception e)
- {
- System.out.println("The input should be an integer.");
- }
- in.nextLine(); // For '\n' from pressing enter;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement