Update Warehouse.java

This commit is contained in:
siddhantdewani
2019-02-24 18:08:05 -07:00
committed by GitHub
parent 915c58bcc5
commit 0b20f2b62d

View File

@@ -5,7 +5,6 @@ public class Warehouse {
private int wSilk = 0; private int wSilk = 0;
private int wGeneral = 0; private int wGeneral = 0;
private int wArms = 0; private int wArms = 0;
private int finalAmount = 0;
private Player player; 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; String good;
System.out.println("Please enter a good to transfer O, S, G, A :"); System.out.println("Please enter a good to transfer O, S, G, A :");
Scanner keyboard = new Scanner(System.in); Scanner keyboard = new Scanner(System.in);
@@ -33,23 +49,23 @@ public class Warehouse {
int held = 0; int held = 0;
if (amount > 0) { if (amount > 0) {
if (good.equalsIgnoreCase("O")) { if (good.equalsIgnoreCase("O")) {
this.wOpium += amount; this.wOpium += finalAmount;
held = player.getOpiumHeld(); held = player.getOpiumHeld();
player.setOpiumHeld(held - amount); player.setOpiumHeld(held - finalAmount);
System.out.println(player.getOpiumHeld()); System.out.println(player.getOpiumHeld());
} }
else if(good.equalsIgnoreCase("S")) { else if(good.equalsIgnoreCase("S")) {
this.wSilk += amount; this.wSilk += finalAmount;
held = player.getSilkHeld(); held = player.getSilkHeld();
player.setSilkHeld(held - amount); player.setSilkHeld(held - amount);
} }
else if(good.equalsIgnoreCase("G")) { else if(good.equalsIgnoreCase("G")) {
this.wGeneral += amount; this.wGeneral += finalAmount;
held = player.getGeneralHeld(); held = player.getGeneralHeld();
player.setGeneralHeld(held - amount); player.setGeneralHeld(held - amount);
} }
else if(good.equalsIgnoreCase("A")) { else if(good.equalsIgnoreCase("A")) {
this.wArms += amount; this.wArms += finalAmount;
held = player.getArmsHeld(); held = player.getArmsHeld();
player.setArmsHeld(held - amount); player.setArmsHeld(held - amount);
} }
@@ -58,7 +74,26 @@ public class Warehouse {
System.out.println("Sorry this transfer cannot be made"); 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; String good;
System.out.println("Please enter a good to transfer O, S, G, A :"); System.out.println("Please enter a good to transfer O, S, G, A :");
Scanner keyboard = new Scanner(System.in); Scanner keyboard = new Scanner(System.in);
@@ -99,60 +134,38 @@ public class Warehouse {
System.out.println("Arms : " + this.wArms); 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() { public void changeWarehouse() {
this.showWarehouse(); boolean keepGoing = true;
String input = " "; while(keepGoing) {
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);
this.showWarehouse(); 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")) { else if(check.equalsIgnoreCase("N")) {
this.askAddAmount(); keepGoing = false;
this.addAmount(this.good, this.finalAmount); }
this.showWarehouse();
} }
} }
public static void main(String[] args){
}
} }