Think I fixed Sid's code

This commit is contained in:
KahootChampion
2019-02-24 20:26:05 -07:00
parent 5f1e566c8f
commit 1be615fcc4
2 changed files with 207 additions and 170 deletions

29
.idea/workspace.xml generated
View File

@@ -2,9 +2,7 @@
<project version="4"> <project version="4">
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="3114a2b9-4919-4fdf-8fd9-d03b60109ce4" name="Default Changelist" comment=""> <list default="true" id="3114a2b9-4919-4fdf-8fd9-d03b60109ce4" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/ShipWarfare.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/ShipWarfare.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/Warehouse.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Warehouse.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/Warehouse.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Warehouse.java" afterDir="false" />
</list> </list>
<ignored path="$PROJECT_DIR$/out/" /> <ignored path="$PROJECT_DIR$/out/" />
@@ -60,8 +58,8 @@
<file pinned="false" current-in-tab="true"> <file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/src/Warehouse.java"> <entry file="file://$PROJECT_DIR$/src/Warehouse.java">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="223"> <state relative-caret-position="408">
<caret line="68" column="13" selection-start-line="68" selection-start-column="13" selection-end-line="68" selection-end-column="13" /> <caret line="194" lean-forward="true" selection-start-line="194" selection-end-line="194" />
</state> </state>
</provider> </provider>
</entry> </entry>
@@ -208,7 +206,7 @@
<component name="PropertiesComponent"> <component name="PropertiesComponent">
<property name="WebServerToolWindowFactoryState" value="false" /> <property name="WebServerToolWindowFactoryState" value="false" />
<property name="aspect.path.notification.shown" value="true" /> <property name="aspect.path.notification.shown" value="true" />
<property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1551063342521" /> <property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1551065152391" />
<property name="extract.method.default.visibility" value="public" /> <property name="extract.method.default.visibility" value="public" />
<property name="last_opened_file_path" value="$PROJECT_DIR$" /> <property name="last_opened_file_path" value="$PROJECT_DIR$" />
<property name="project.structure.last.edited" value="Project" /> <property name="project.structure.last.edited" value="Project" />
@@ -424,14 +422,22 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1551060038524</updated> <updated>1551060038524</updated>
</task> </task>
<option name="localTasksCounter" value="18" /> <task id="LOCAL-00018" summary="Worked On Sid's class a bit">
<created>1551063376717</created>
<option name="number" value="00018" />
<option name="presentableId" value="LOCAL-00018" />
<option name="project" value="LOCAL" />
<updated>1551063376717</updated>
</task>
<option name="localTasksCounter" value="19" />
<servers /> <servers />
</component> </component>
<component name="TimeTrackingManager"> <component name="TimeTrackingManager">
<option name="totallyTimeSpent" value="43126000" /> <option name="totallyTimeSpent" value="45109000" />
</component> </component>
<component name="ToolWindowManager"> <component name="ToolWindowManager">
<frame x="0" y="23" width="1280" height="709" extended-state="6" /> <frame x="0" y="23" width="1280" height="709" extended-state="6" />
<editor active="true" />
<layout> <layout>
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.3101777" /> <window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.3101777" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" /> <window_info id="Structure" order="1" side_tool="true" weight="0.25" />
@@ -442,7 +448,7 @@
<window_info id="Favorites" order="6" side_tool="true" /> <window_info id="Favorites" order="6" side_tool="true" />
<window_info anchor="bottom" id="Message" order="0" /> <window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" /> <window_info anchor="bottom" id="Find" order="1" />
<window_info active="true" anchor="bottom" id="Run" order="2" sideWeight="0.4989339" visible="true" weight="0.3241491" /> <window_info anchor="bottom" id="Run" order="2" sideWeight="0.4989339" weight="0.3241491" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.4" /> <window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" /> <window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" /> <window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
@@ -486,7 +492,8 @@
<MESSAGE value="Added a few comments to ShipWarfare" /> <MESSAGE value="Added a few comments to ShipWarfare" />
<MESSAGE value="bunch of revisions, still in progress" /> <MESSAGE value="bunch of revisions, still in progress" />
<MESSAGE value="linked all the classes together. The project is functional." /> <MESSAGE value="linked all the classes together. The project is functional." />
<option name="LAST_COMMIT_MESSAGE" value="linked all the classes together. The project is functional." /> <MESSAGE value="Worked On Sid's class a bit" />
<option name="LAST_COMMIT_MESSAGE" value="Worked On Sid's class a bit" />
</component> </component>
<component name="editorHistoryManager"> <component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/TaipanClone.iml"> <entry file="file://$PROJECT_DIR$/TaipanClone.iml">
@@ -560,8 +567,8 @@
</entry> </entry>
<entry file="file://$PROJECT_DIR$/src/Warehouse.java"> <entry file="file://$PROJECT_DIR$/src/Warehouse.java">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="223"> <state relative-caret-position="408">
<caret line="68" column="13" selection-start-line="68" selection-start-column="13" selection-end-line="68" selection-end-column="13" /> <caret line="194" lean-forward="true" selection-start-line="194" selection-end-line="194" />
</state> </state>
</provider> </provider>
</entry> </entry>

View File

@@ -1,169 +1,199 @@
import java.util.Scanner; import java.util.Scanner;
public class Warehouse { public class Warehouse {
private int wOpium = 0; private int wOpium = 0;
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 Player player; private Player player;
public void setPlayer(Player player) {
Player playerDumy = new Player(player);
this.player= playerDumy;
}
public Player getPlayer(){
Player playerDummy = new Player(player);
return playerDummy;
}
public Warehouse(Player player){
Player playerDummy = new Player(player);
this.player = playerDummy;
}
public void addAmount() {
boolean askGood = false;
String amount;
int finalAmount = 0;
System.out.println("Please enter the amount of the good you would like to ADD.");
Scanner keyboard = new Scanner(System.in);
amount = keyboard.nextLine();
try {
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);
askGood=true;
} else {
System.out.println("Nice try but you don't have any items of that quantity!");
askGood=false;
}
if(askGood==true) {
String good;
System.out.println("Please enter a good to transfer O, S, G, A :");
good = keyboard.nextLine();
int held = 0;
if (Integer.parseInt(amount) > 0) {
if (good.equalsIgnoreCase("O")) {
this.wOpium += finalAmount;
held = player.getOpiumHeld();
player.setOpiumHeld(held - finalAmount);
System.out.println(player.getOpiumHeld());
} else if (good.equalsIgnoreCase("S")) {
this.wSilk += finalAmount;
held = player.getSilkHeld();
player.setSilkHeld(held - finalAmount);
} else if (good.equalsIgnoreCase("G")) {
this.wGeneral += finalAmount;
held = player.getGeneralHeld();
player.setGeneralHeld(held - finalAmount);
} else if (good.equalsIgnoreCase("A")) {
this.wArms += finalAmount;
held = player.getArmsHeld();
player.setArmsHeld(held - finalAmount);
}
} else {
System.out.println("Sorry this transfer cannot be made");
}
}
}catch(Exception e){
System.out.println("Wait, that's not a valid input please try again");
}
}
public void removeAmount() {
String amount;
int finalAmount = 0;
System.out.println("Please enter the amount of the good you would like to REMOVE");
Scanner keyboard = new Scanner(System.in);
amount = keyboard.nextLine();
if(Integer.parseInt(amount) <= this.wOpium) {
finalAmount = Integer.parseInt(amount);
}
else if(Integer.parseInt(amount) <= this.wSilk) {
finalAmount = Integer.parseInt(amount);
}
else if(Integer.parseInt(amount) <= this.wGeneral) {
finalAmount = Integer.parseInt(amount);
}
else if(Integer.parseInt(amount) <= this.wArms) {
finalAmount = Integer.parseInt(amount);
}
String good;
System.out.println("Please enter a good to transfer O, S, G, A :");
good = keyboard.nextLine();
int held = 0;
if (Integer.parseInt(amount) > 0) {
if (good.equalsIgnoreCase("O")) {
this.wOpium -= Integer.parseInt(amount);
held = player.getOpiumHeld();
player.setOpiumHeld(held + finalAmount);
}
else if(good.equalsIgnoreCase("S")) {
this.wSilk -= Integer.parseInt(amount);
held = player.getSilkHeld();
player.setSilkHeld(held + finalAmount);
}
else if(good.equalsIgnoreCase("G")) {
this.wGeneral -= Integer.parseInt(amount);
held = player.getGeneralHeld();
player.setGeneralHeld(held + finalAmount);
}
else if(good.equalsIgnoreCase("A")) {
this.wArms -= Integer.parseInt(amount);
held = player.getArmsHeld();
player.setArmsHeld(held + finalAmount);
}
}
else {
System.out.println("Sorry this transfer cannot be made");
}
}
public void showWarehouse() { public void setPlayer(Player player) {
System.out.println("Opium : " + this.wOpium); Player playerDumy = new Player(player);
System.out.println("Silk : " + this.wSilk); this.player = playerDumy;
System.out.println("General : " + this.wGeneral); }
System.out.println("Arms : " + this.wArms);
}
public Player getPlayer() {
public void changeWarehouse() { Player playerDummy = new Player(player);
boolean keepGoing = true; return playerDummy;
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?");
check = keyboard.nextLine();
check=keyboard.nextLine();
if(check.equalsIgnoreCase("Y")) {
keepGoing = true;
}
else if(check.equalsIgnoreCase("N")) {
keepGoing = false;
}
}
}
public static void main(String[] args){ public Warehouse(Player player) {
Player playerDummy = new Player(player);
this.player = playerDummy;
}
public void addAmount() {
boolean askGood = false;
String amount;
int finalAmount = 0;
System.out.println("Please enter the amount of the good you would like to ADD.");
Scanner keyboard = new Scanner(System.in);
amount = keyboard.nextLine();
try {
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);
askGood = true;
} else {
System.out.println("Nice try but you don't have any items of that quantity!");
askGood = false;
}
if (askGood == true) {
String good;
System.out.println("Please enter a good to transfer O, S, G, A :");
good = keyboard.nextLine();
int held = 0;
if (Integer.parseInt(amount) > 0) {
if (good.equalsIgnoreCase("O")) {
if (player.getOpiumHeld() >= Integer.parseInt(amount)) {
this.wOpium += finalAmount;
held = player.getOpiumHeld();
player.setOpiumHeld(held - finalAmount);
System.out.println(player.getOpiumHeld());
} else {
System.out.println("You don't even have that much opium!");
}
} else if (good.equalsIgnoreCase("S")) {
if (player.getSilkHeld() >= Integer.parseInt(amount)) {
this.wSilk += finalAmount;
held = player.getSilkHeld();
player.setSilkHeld(held - finalAmount);
} else {
System.out.println("You don't even have that much silk!");
}
} else if (good.equalsIgnoreCase("G")) {
if (player.getGeneralHeld() >= Integer.parseInt(amount)) {
this.wGeneral += finalAmount;
held = player.getGeneralHeld();
player.setGeneralHeld(held - finalAmount);
} else {
System.out.println("You don't even have that much general cargo!");
}
} else if (good.equalsIgnoreCase("A")) {
if (player.getArmsHeld() >= Integer.parseInt(amount)) {
this.wArms += finalAmount;
held = player.getArmsHeld();
player.setArmsHeld(held - finalAmount);
} else {
System.out.println("You don't even have that much Arms!");
}
}
} else {
System.out.println("Sorry this transfer cannot be made");
}
}
} catch (Exception e) {
System.out.println("Wait, that's not a valid input please try again");
}
}
public void removeAmount() {
String amount;
boolean askGood = false;
int finalAmount = 0;
System.out.println("Please enter the amount of the good you would like to REMOVE");
Scanner keyboard = new Scanner(System.in);
amount = keyboard.nextLine();
if (Integer.parseInt(amount) <= wOpium || Integer.parseInt(amount) <=wSilk || Integer.parseInt(amount) <= wGeneral || Integer.parseInt(amount) <= wArms) {
finalAmount = Integer.parseInt(amount);
askGood = true;
} else {
System.out.println("Nice try but you don't have any items of that quantity in the warehouse!");
askGood = false;
}
if (askGood == true) {
String good;
System.out.println("Please enter a good to transfer O, S, G, A :");
good = keyboard.nextLine();
int held = 0;
if (Integer.parseInt(amount) > 0) {
if (good.equalsIgnoreCase("O")) {
if (this.wOpium >= Integer.parseInt(amount)) {
this.wOpium -= Integer.parseInt(amount);
held = player.getOpiumHeld();
player.setOpiumHeld(held + finalAmount);
} else {
System.out.println("You don't have that much opium stored in the warehouse!");
}
} else if (good.equalsIgnoreCase("S")) {
if (this.wSilk >= Integer.parseInt(amount)) {
this.wSilk -= Integer.parseInt(amount);
held = player.getSilkHeld();
player.setSilkHeld(held + finalAmount);
}
else{
System.out.println("You don't have that much silk stored in the warehouse!");
}
} else if (good.equalsIgnoreCase("G")) {
if (this.wGeneral >= Integer.parseInt(amount)) {
this.wGeneral -= Integer.parseInt(amount);
held = player.getGeneralHeld();
player.setGeneralHeld(held + finalAmount);
}
else{
System.out.println("You don't have that much general cargo stored in the warehouse!");
}
} else if (good.equalsIgnoreCase("A")) {
if (this.wArms >= Integer.parseInt(amount)) {
this.wArms -= Integer.parseInt(amount);
held = player.getArmsHeld();
player.setArmsHeld(held + finalAmount);
}
else{
System.out.println("You don't have that much arms stored in the warehouse!");
}
}
} else {
System.out.println("Sorry this transfer cannot be made");
}
}
}
public void showWarehouse() {
System.out.println("Opium : " + this.wOpium);
System.out.println("Silk : " + this.wSilk);
System.out.println("General : " + this.wGeneral);
System.out.println("Arms : " + this.wArms);
}
public void changeWarehouse() {
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?");
check = keyboard.nextLine();
check = keyboard.nextLine();
if (check.equalsIgnoreCase("Y")) {
keepGoing = true;
} else if (check.equalsIgnoreCase("N")) {
keepGoing = false;
}
}
}
public static void main(String[] args) {
} }
} }