Small thing, changed an output of warehouse a bit, shows user its the warehouse they are concerned with.
This commit is contained in:
@@ -2,28 +2,51 @@ import java.util.Scanner;
|
|||||||
|
|
||||||
public class loanShark {
|
public class loanShark {
|
||||||
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 playerDummy = new Player(player);
|
Player playerDummy = new Player(player);
|
||||||
this.player = playerDummy;
|
this.player = playerDummy;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 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 loanShark(Player player){
|
public loanShark(Player player){
|
||||||
Player playerDummy = new Player(player);
|
Player playerDummy = new Player(player);
|
||||||
this.player = playerDummy;
|
this.player = playerDummy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This methods purpose is to loan the player the funds it wants
|
||||||
|
* or pay its outstanding debts. The method prompts the user if they
|
||||||
|
* would like to borrow money or repay. depending on what the player chooses
|
||||||
|
* the corresponding loop is evoked. The player can only be loaned 2 times the
|
||||||
|
* money they have minus the debt id their debt exceeds the cash balance, the loan
|
||||||
|
* cannot be given.
|
||||||
|
*/
|
||||||
public void loanMoney() {
|
public void loanMoney() {
|
||||||
boolean keepGoing = true;
|
boolean keepGoing = true;
|
||||||
while(keepGoing) {
|
while(keepGoing) {
|
||||||
String check;
|
String check;
|
||||||
Scanner keyboard = new Scanner(System.in);
|
Scanner keyboard = new Scanner(System.in);
|
||||||
System.out.println("Would you like to return money or borrow money?");
|
System.out.println("Would you like to return money or borrow money?");
|
||||||
|
//Prompts the user or what they would like to do
|
||||||
check = keyboard.nextLine();
|
check = keyboard.nextLine();
|
||||||
|
//If the user chooses to return money, the money is subtracted from the cash amount and debt
|
||||||
if(check.equalsIgnoreCase("r")){
|
if(check.equalsIgnoreCase("r")){
|
||||||
int returnAsk = 0;
|
int returnAsk = 0;
|
||||||
System.out.println("Please enter how much you would like to return?");
|
System.out.println("Please enter how much you would like to return?");
|
||||||
@@ -31,26 +54,34 @@ public class loanShark {
|
|||||||
if(returnAsk <= player.getDebt() && returnAsk >= 0) {
|
if(returnAsk <= player.getDebt() && returnAsk >= 0) {
|
||||||
player.setDebt(player.getDebt() - returnAsk);
|
player.setDebt(player.getDebt() - returnAsk);
|
||||||
player.setMoney(player.getMoney() - returnAsk);
|
player.setMoney(player.getMoney() - returnAsk);
|
||||||
}//updated
|
}
|
||||||
|
//if you try to return more money than you owe it wont allow you to
|
||||||
else if(returnAsk > player.getDebt()){
|
else if(returnAsk > player.getDebt()){
|
||||||
System.out.println("You don't need to return that much!");
|
System.out.println("You don't need to return that much!");
|
||||||
}else{
|
}
|
||||||
|
//No negative amounts are allowed
|
||||||
|
else{
|
||||||
System.out.println("You can't return a negative amount.");
|
System.out.println("You can't return a negative amount.");
|
||||||
}
|
}
|
||||||
}else if(check.equalsIgnoreCase("b")){
|
|
||||||
|
}
|
||||||
|
//If the user chooses to borrow, the money is added to cash and the debt is increased
|
||||||
|
else if(check.equalsIgnoreCase("b")){
|
||||||
int loanAsk = 0;
|
int loanAsk = 0;
|
||||||
System.out.println("Please enter how much you would like to borrow");
|
System.out.println("Please enter how much you would like to borrow");
|
||||||
|
//Prompts user for the amount they would like to borrow
|
||||||
loanAsk = keyboard.nextInt();
|
loanAsk = keyboard.nextInt();
|
||||||
if(loanAsk <= 2*(player.getMoney() - player.getDebt())&& loanAsk >= 0) {
|
if(loanAsk <= 2*(player.getMoney() - player.getDebt())&& loanAsk >= 0) {
|
||||||
player.setDebt(player.getDebt() + loanAsk);
|
player.setDebt(player.getDebt() + loanAsk);
|
||||||
player.setMoney(player.getMoney() + loanAsk);
|
player.setMoney(player.getMoney() + loanAsk);
|
||||||
}//updated
|
}
|
||||||
|
//If the requested money exceeds 2*(cash - debt) then the loan cannot be given
|
||||||
else{
|
else{
|
||||||
System.out.println("Sorry you can't be loaned that much");
|
System.out.println("Sorry you can't be loaned that much");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//Asks the player if they have any other things to do with the load shark
|
||||||
System.out.println("Would you like to do any other business? Y / N?");
|
System.out.println("Would you like to do any other business? Y / N?");
|
||||||
check = keyboard.nextLine();
|
check = keyboard.nextLine();
|
||||||
check = keyboard.nextLine();
|
check = keyboard.nextLine();
|
||||||
|
|||||||
Reference in New Issue
Block a user