From 0b20f2b62dbf6d2287ba829d4d730b74a0df3ce6 Mon Sep 17 00:00:00 2001 From: siddhantdewani <47336797+siddhantdewani@users.noreply.github.com> Date: Sun, 24 Feb 2019 18:08:05 -0700 Subject: [PATCH] Update Warehouse.java --- src/Warehouse.java | 129 +++++++++++++++++++++++++-------------------- 1 file changed, 71 insertions(+), 58 deletions(-) diff --git a/src/Warehouse.java b/src/Warehouse.java index 80fa464..6b313af 100644 --- a/src/Warehouse.java +++ b/src/Warehouse.java @@ -5,7 +5,6 @@ public class Warehouse { private int wSilk = 0; private int wGeneral = 0; private int wArms = 0; - private int finalAmount = 0; private Player player; @@ -25,7 +24,24 @@ public class Warehouse { } - public void addAmount(int amount) { + public void addAmount() { + int amount = 0; + int finalAmount; + System.out.println("Please enter the amount of the good you would like to ADD."); + Scanner keyboard = new Scanner(System.in); + amount = keyboard.nextInt(); + if(amount <= player.getOpiumHeld()) { + finalAmount = amount; + } + else if(amount <= player.getSilkHeld()) { + finalAmount = amount; + } + else if(amount <= player.getGeneralHeld()) { + finalAmount = amount; + } + else if(amount <= player.getArmsHeld()) { + finalAmount = amount; + } String good; System.out.println("Please enter a good to transfer O, S, G, A :"); Scanner keyboard = new Scanner(System.in); @@ -33,23 +49,23 @@ public class Warehouse { int held = 0; if (amount > 0) { if (good.equalsIgnoreCase("O")) { - this.wOpium += amount; + this.wOpium += finalAmount; held = player.getOpiumHeld(); - player.setOpiumHeld(held - amount); + player.setOpiumHeld(held - finalAmount); System.out.println(player.getOpiumHeld()); } else if(good.equalsIgnoreCase("S")) { - this.wSilk += amount; + this.wSilk += finalAmount; held = player.getSilkHeld(); player.setSilkHeld(held - amount); } else if(good.equalsIgnoreCase("G")) { - this.wGeneral += amount; + this.wGeneral += finalAmount; held = player.getGeneralHeld(); player.setGeneralHeld(held - amount); } else if(good.equalsIgnoreCase("A")) { - this.wArms += amount; + this.wArms += finalAmount; held = player.getArmsHeld(); player.setArmsHeld(held - amount); } @@ -58,7 +74,26 @@ public class Warehouse { System.out.println("Sorry this transfer cannot be made"); } } - public void removeAmount(int amount) { + public void removeAmount() { + int amount = 0; + int finalAmount; + System.out.println("Please enter the amount of the good you would like to REMOVE"); + Scanner keyboard = new Scanner(System.in); + amount = keyboard.nextInt(); + if(amount <= this.wOpium) { + finalAmount = amount; + } + else if(amount <= this.wSilk) { + finalAmount = amount; + } + else if(amount <= this.wGeneral) { + finalAmount = amount; + } + else if(amount <= this.wArms) { + finalAmount = amount; + } + + } String good; System.out.println("Please enter a good to transfer O, S, G, A :"); Scanner keyboard = new Scanner(System.in); @@ -99,60 +134,38 @@ public class Warehouse { System.out.println("Arms : " + this.wArms); } - public void askAddAmount() { - int amount = 0; - System.out.println("Please enter the amount of the good you would like to ADD."); - Scanner keyboard = new Scanner(System.in); - amount = keyboard.nextInt(); - if(this.good.equalsIgnoreCase("O") && amount <= player.getOpiumHeld()) { - finalAmount = amount; - } - else if(this.good.equalsIgnoreCase("S") && amount <= player.getSilkHeld()) { - finalAmount = amount; - } - else if(this.good.equalsIgnoreCase("G") && amount <= player.getGeneralHeld()) { - finalAmount = amount; - } - else if(this.good.equalsIgnoreCase("A") && amount <= player.getArmsHeld()) { - finalAmount = amount; - } - } - - public void askRemoveAmount() { - int amount = 0; - System.out.println("Please enter the amount of the good you would like to REMOVE"); - Scanner keyboard = new Scanner(System.in); - amount = keyboard.nextInt(); - if(this.good.equalsIgnoreCase("O") && amount <= this.wOpium) { - finalAmount = amount; - } - else if(this.good.equalsIgnoreCase("S") && amount <= this.wSilk) { - finalAmount = amount; - } - else if(this.good.equalsIgnoreCase("G") && amount <= this.wGeneral) { - finalAmount = amount; - } - else if(this.good.equalsIgnoreCase("A") && amount <= this.wArms) { - finalAmount = amount; - } - - } public void changeWarehouse() { - this.showWarehouse(); - String input = " "; - System.out.println("Would you like to add(A) or remove(R) resources? "); - Scanner keyboard = new Scanner(System.in); - input = keyboard.next(); - if(input.equalsIgnoreCase("R")) { - this.askRemoveAmount(); - this.removeAmount(this.good, this.finalAmount); + boolean keepGoing = true; + while(keepGoing) { this.showWarehouse(); + String input = " "; + System.out.println("Would you like to add(A) or remove(R) resources? "); + Scanner keyboard = new Scanner(System.in); + input = keyboard.next(); + if(input.equalsIgnoreCase("R")) { + this.removeAmount(); + this.showWarehouse(); + } + else if(input.equalsIgnoreCase("A")) { + this.addAmount(); + this.showWarehouse(); + } + + String check; + System.out.println("Would you like to do any other business? Y / N?"); + Scanner keyboard = new Scanner(System.in); + check = keyboard.nextLine(); + + if(check.equalsIgnoreCase("Y")) { + keepGoing = true; } - else if(input.equalsIgnoreCase("A")) { - this.askAddAmount(); - this.addAmount(this.good, this.finalAmount); - this.showWarehouse(); + else if(check.equalsIgnoreCase("N")) { + keepGoing = false; + } } } + public static void main(String[] args){ + + } }