Merge remote-tracking branch 'origin/master'

This commit is contained in:
Vikram
2019-02-25 18:43:11 -07:00

View File

@@ -1,5 +1,9 @@
import java.util.Scanner; import java.util.Scanner;
/**
* The purpose of this class is to create a warehouse where the goods
* can be safely stored without holing space on the ship!
*/
public class Warehouse { public class Warehouse {
/*private int wOpium = 0; /*private int wOpium = 0;
private int wSilk = 0; private int wSilk = 0;
@@ -7,43 +11,75 @@ public class Warehouse {
private int wArms = 0;*/ private int wArms = 0;*/
private Player player; private Player player;
/**
* setter method that takes in a Player object as an argument.
*
* @param player object of the class Player
*/
public void setPlayer(Player player) { public void setPlayer(Player player) {
Player playerDumy = new Player(player); Player playerDumy = new Player(player);
this.player = playerDumy; this.player = playerDumy;
} }
/**
* getter method for obtaining a player object.
*
* @return returns player object
*/
public Player getPlayer() { public Player getPlayer() {
Player playerDummy = new Player(player); Player playerDummy = new Player(player);
return playerDummy; return playerDummy;
} }
/**
* Class Constructor that takes in a type player as a parameter
*
* @param player object of the class Player
*/
public Warehouse(Player player) { public Warehouse(Player player) {
Player playerDummy = new Player(player); Player playerDummy = new Player(player);
this.player = playerDummy; this.player = playerDummy;
} }
/**
* This method adds an amount of a certain good
* the user is prompted to enter the amount they would like to
* add followed by the good they would like to add to the warehouse.
* the method checks if the player has sufficient goods to transfer, and if the player does
* then the method executes the transfer
* @exception e ensures the code does not fail due to an invalid input
*/
public void addAmount() { public void addAmount() {
boolean askGood = false; boolean askGood = false;
String amount; String amount;
int finalAmount = 0; int finalAmount = 0;
System.out.println("Please enter the amount of the good you would like to ADD."); System.out.println("Please enter the amount of the good you would like to ADD.");
Scanner keyboard = new Scanner(System.in); Scanner keyboard = new Scanner(System.in);
amount = keyboard.nextLine(); amount = keyboard.nextLine();//Asks the user for the amount of the good they would like to add
/*The try function ensures that the program does not crash
due to any errors while giving the program an incorrect input*/
try { try {
//The if statement checks that you have enough resources to make the transfer
if (Integer.parseInt(amount) <= player.getOpiumHeld() || Integer.parseInt(amount) <= player.getSilkHeld() || Integer.parseInt(amount) <= player.getGeneralHeld() || Integer.parseInt(amount) <= player.getArmsHeld()) { if (Integer.parseInt(amount) <= player.getOpiumHeld() || Integer.parseInt(amount) <= player.getSilkHeld() || Integer.parseInt(amount) <= player.getGeneralHeld() || Integer.parseInt(amount) <= player.getArmsHeld()) {
finalAmount = Integer.parseInt(amount); finalAmount = Integer.parseInt(amount);
askGood = true; askGood = true;
} else { }
//Else statement lets the user know that they do not hav enough goods to make the requested transfer
else {
System.out.println("Nice try but you don't have any items of that quantity!"); System.out.println("Nice try but you don't have any items of that quantity!");
askGood = false; askGood = false;
} }
//Ensures that goods are only transferred if they have the specified amount
//The user is prompted to enter which good they want to transfer
if (askGood == true) { if (askGood == true) {
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 :");
good = keyboard.nextLine(); good = keyboard.nextLine();
int held = 0; int held = 0;
//The following set of loops check to see which good the user has selected and makes the transfer
if (Integer.parseInt(amount) > 0) { if (Integer.parseInt(amount) > 0) {
if (good.equalsIgnoreCase("O")) { if (good.equalsIgnoreCase("O")) {
if (player.getOpiumHeld() >= Integer.parseInt(amount)) { if (player.getOpiumHeld() >= Integer.parseInt(amount)) {
@@ -81,22 +117,37 @@ public class Warehouse {
System.out.println("You don't even have that much Arms!"); System.out.println("You don't even have that much Arms!");
} }
} }
} else { }
//Ensures no negative amounts are entered
else {
System.out.println("Sorry this transfer cannot be made"); System.out.println("Sorry this transfer cannot be made");
} }
} }
//If the program errors out this is the message displayed and the method is re-run, so that the game does not end.
} catch (Exception e) { } catch (Exception e) {
System.out.println("Wait, that's not a valid input please try again"); System.out.println("Wait, that's not a valid input please try again");
} }
} }
/**
* This method removes an amount of a certain good
* the user is prompted to enter the amount they would like to
* remove followed by the good they would like to remove from the warehouse.
* the method checks if the player has sufficient goods to transfer, and if the player does
* then the method executes the transfer
* @exception e Ensures the code does not fail due to invalid response.
*
*/
public void removeAmount() { public void removeAmount() {
String amount; String amount;
boolean askGood = false; boolean askGood = false;
int finalAmount = 0; int finalAmount = 0;
System.out.println("Please enter the amount of the good you would like to REMOVE"); System.out.println("Please enter the amount of the good you would like to REMOVE");
Scanner keyboard = new Scanner(System.in); Scanner keyboard = new Scanner(System.in);
//Prompts the user for the amount they would like to remove
amount = keyboard.nextLine(); amount = keyboard.nextLine();
//The if statement checks that you have enough resources to make the transfer
try { try {
if (Integer.parseInt(amount) <= player.getwOpium() || Integer.parseInt(amount) <= player.getwSilk() || Integer.parseInt(amount) <= player.getwGeneral() || Integer.parseInt(amount) <= player.getwArms()) { if (Integer.parseInt(amount) <= player.getwOpium() || Integer.parseInt(amount) <= player.getwSilk() || Integer.parseInt(amount) <= player.getwGeneral() || Integer.parseInt(amount) <= player.getwArms()) {
finalAmount = Integer.parseInt(amount); finalAmount = Integer.parseInt(amount);