From 12c0aa5219ce1cbaaff8a162559006f206d48e3e Mon Sep 17 00:00:00 2001 From: Hanquan Liu Date: Fri, 11 Nov 2022 18:10:53 -0500 Subject: [PATCH 01/19] init --- .idea/.gitignore | 3 +++ .idea/compiler.xml | 16 ++++++++++++++++ .idea/misc.xml | 13 +++++++++++++ .idea/modules.xml | 8 ++++++++ .idea/vcs.xml | 6 ++++++ Hamurabi.iml | 13 +++++++++++++ pom.xml | 25 +++++++++++++++++++++++++ 7 files changed, 84 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/compiler.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 Hamurabi.iml create mode 100644 pom.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..c89203c --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..bcd41e5 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,13 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..16ae36c --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Hamurabi.iml b/Hamurabi.iml new file mode 100644 index 0000000..660429b --- /dev/null +++ b/Hamurabi.iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..d789654 --- /dev/null +++ b/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + + io.zipcoder + MicroLabs-Loops + 1.0-SNAPSHOT + + + + + junit + junit + 4.13.2 + + + + + + 1.8 + 1.8 + + \ No newline at end of file From f31be31c6f987b471e0f41ac37b40cea60412167 Mon Sep 17 00:00:00 2001 From: Yingjie <52tiffany.yang@gmail.com> Date: Fri, 11 Nov 2022 23:38:59 -0500 Subject: [PATCH 02/19] update methods --- .DS_Store | Bin 0 -> 6148 bytes .idea/compiler.xml | 2 +- .idea/jarRepositories.xml | 20 +++++ .idea/libraries/Maven__junit_junit_4_13_2.xml | 13 +++ .../Maven__org_hamcrest_hamcrest_core_1_3.xml | 13 +++ Hamurabi.iml | 4 +- docs/.DS_Store | Bin 0 -> 6148 bytes docs/matuszek/hamurabi.java | 84 ++++++++++++++++++ 8 files changed, 134 insertions(+), 2 deletions(-) create mode 100644 .DS_Store create mode 100644 .idea/jarRepositories.xml create mode 100644 .idea/libraries/Maven__junit_junit_4_13_2.xml create mode 100644 .idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml create mode 100644 docs/.DS_Store create mode 100644 docs/matuszek/hamurabi.java diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..09137cab749887a890e46382507f99a4194792b3 GIT binary patch literal 6148 zcmeHK%}T>S5Z-O0O({YS3Oz1(E!Y$)h?fxS3mDOZN=;1BV9b^#HHT8jSzpK}@p+ut z-H63{6|pn0`_1oe_JiyXV~qRr*k#ONjM>l-IVx)e-D^V)lZ?o5jHt|~Q7R*_-%RYU z1Ae>3VkX%g%fEhqG)X@Wg69b7+oZj za_sD$$gBvHY%)^?Nj!m+>&qmIW$DX#7U!xq&;h$`x5rL*u^1lp#K0Xcdt%}C2ZNqC zblv5$ZSUbluID+JWvR^W!B^+kd4$9OF+dCu1Dnf$ zITP&8=2Ac_CkBXt9~i*>K|n+F3|1P|)&U(}pD}JBqJWNX2}EJgGgxVa2ng4ufVz~M zCkEH$;1?#(GgxWV<&3MDVH`7a{dnPOcJK?8&bX(MdSZYWSY@E8O$X2aQ}|`pKJr&f z$RY-afq%vTw?@IpheesQ_1p6BtQF91p`l=2g$fAhE0+K;a3ATappFaFA` SugU@GBA^JNju`j_20j3GXG%i= literal 0 HcmV?d00001 diff --git a/.idea/compiler.xml b/.idea/compiler.xml index c89203c..639314b 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -10,7 +10,7 @@ - + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__junit_junit_4_13_2.xml b/.idea/libraries/Maven__junit_junit_4_13_2.xml new file mode 100644 index 0000000..606c352 --- /dev/null +++ b/.idea/libraries/Maven__junit_junit_4_13_2.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml b/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml new file mode 100644 index 0000000..f58bbc1 --- /dev/null +++ b/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/Hamurabi.iml b/Hamurabi.iml index 660429b..903044c 100644 --- a/Hamurabi.iml +++ b/Hamurabi.iml @@ -1,6 +1,6 @@ - + @@ -9,5 +9,7 @@ + + \ No newline at end of file diff --git a/docs/.DS_Store b/docs/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..f13b2b39ff6964506e50669c9f5d98c6142c2bbb GIT binary patch literal 6148 zcmeHKJ5EC}5S)b+Pohal=__ypD+(vz0wg3AK`BBSs#oP)9F5seLG++YnrK#9kG_A6VfN$KU+* ze!ufgnG}!$Qa}nw0V!}%1**Ib4;MXEhe-h`a0?3f_o2}pd*PTEpAHVu0uW~mhjAXg z1hIL5*bB!*Mrf8)Vp6SI3`;uWt@3)|n3!}}H6K9C%tQ3^ztTPDo9@PWP&h<6CPq2t!prev cBxPRnIrn?vm>6`%gHF`Xfa@ZY0@qgH2V!CszyJUM literal 0 HcmV?d00001 diff --git a/docs/matuszek/hamurabi.java b/docs/matuszek/hamurabi.java new file mode 100644 index 0000000..3ecf9c0 --- /dev/null +++ b/docs/matuszek/hamurabi.java @@ -0,0 +1,84 @@ +package hammurabi; // package declaration +import java.util.Random; // imports go here +import java.util.Scanner; + + public class Hammurabi { // must save in a file named Hammurabi.java + Random rand = new Random(); // this is an instance variable + Scanner scanner = new Scanner(System.in); + + public static void main(String[] args) { // required in every Java program + new Hammurabi().playGame(); + } + + void playGame() { + // declare local variables here: grain, population, etc. + // statements go after the declations + } + + //other methods go here + int askHowManyAcresToBuy(int price, int bushels){ + return 1; + } + + //Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. + + int askHowManyAcresToSell(int acresOwned){ + return 1; + } + + //Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. + //Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. + + int askHowMuchGrainToFeedPeople(int bushels){ + return 1; + } + + //Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You can feed them more than they need to survive. + + int askHowManyAcresToPlant(int acresOwned, int population, int bushels){ + return 1; + } + + //Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. + int plagueDeaths(int population){ + return 1; + } + + // Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). + int starvationDeaths(int population, int bushelsFedToPeople){ + return 1; + } + + // Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). + + boolean uprising(int population, int howManyPeopleStarved){ + return 1; + } + + // Return true if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) + + int immigrants(int population, int acresOwned, int grainInStorage){ + return 1; + } + + //Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: (20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1. + + int harvest(int acres, int bushelsUsedAsSeed){ + return 1; + } + + //Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. + + int grainEatenByRats(int bushels){ + return 1; + } + + //There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). + + int newCostOfLand(){ + return 1; + } + + //The price of land is random, and + } + From eb9eddc5767695248fa150f5cad112db04219e04 Mon Sep 17 00:00:00 2001 From: Yingjie Yang <102939225+Tiffany678@users.noreply.github.com> Date: Sat, 12 Nov 2022 00:31:33 -0500 Subject: [PATCH 03/19] Wrong file --- docs/hamurabi.java | 156 --------------------------------------------- 1 file changed, 156 deletions(-) delete mode 100644 docs/hamurabi.java diff --git a/docs/hamurabi.java b/docs/hamurabi.java deleted file mode 100644 index 9947af3..0000000 --- a/docs/hamurabi.java +++ /dev/null @@ -1,156 +0,0 @@ -import java.io.IOException; -import java.util.Scanner; - -// this seems to be an example of a solution that mimics the original BASIC code the author was writing from. -// -// it's a great example of Very Bad Java. -// Do not write Java like this. If you do, do NOT tell people you went to Zip Code. -// I'm serious. -// (how the hell would you ever be able to TEST this piece of code?) -// -public class HAMURABI { - static int totalDeaths = 0, percentDied = 0, year = 0, population = 95, stores = 2800, immigrants = 5, deaths, - harvest = 3000, yeild = 3, acres = harvest / yeild, eaten = harvest - stores, landPrice, fullPeople, temp; - static boolean plague = false; - final static String FINK = "DUE TO THIS EXTREME MISMANAGEMENT YOU HAVE NOT ONLY\n" + - "BEEN IMPEACHED AND THROWN OUT OF OFFICE BUT YOU HAVE\n" + - "ALSO BEEN DECLARED PERSONA NON GRATA!!\n"; - Scanner input = new Scanner(System.in); - - private void newYear() { - year += 1; - population += immigrants; - landPrice = (int) (10 * Math.random() + 17); - System.out.println(report()); - do { - System.out.print("HOW MANY ACRES DO YOU WISH TO BUY? "); - temp = input.nextInt(); - if (temp < 0) - epicFail(0); - if (temp * landPrice > stores) - System.out.println("HAMURABI: THINK AGAIN. YOU HAVE ONLY\n" + - stores + " BUSHELS OF GRAIN. NOW THEN,"); - } while (temp * landPrice > stores); - acres += temp; - stores -= temp * landPrice; - do { - System.out.print("HOW MANY ACRES DO YOU WISH TO SELL? "); - temp = input.nextInt(); - if (temp < 0) - epicFail(0); - if (temp > acres) - System.out.println("HAMURABI: THINK AGAIN. YOU OWN ONLY " + acres + " ACRES. NOW THEN,"); - } while (temp > acres); - stores += temp * landPrice; - acres -= temp; - do { - System.out.print("\nHOW MANY BUSHELS DO YOU WISH TO FEED YOUR PEOPLE? "); - temp = input.nextInt(); - if (temp < 0) - epicFail(0); - if (temp > stores) - System.out.println("HAMURABI: THINK AGAIN. YOU HAVE ONLY\n" + - stores + " BUSHELS OF GRAIN. NOW THEN,"); - } while (temp > stores); - fullPeople = temp / 20; - stores -= temp; - do { - System.out.print("\nHOW MANY ACRES DO YOU WISH TO PLANT WITH SEED? "); - temp = input.nextInt(); - if (temp < 0) - epicFail(0); - if (temp > acres) - System.out.println("HAMURABI: THINK AGAIN. YOU OWN ONLY " + acres + " ACRES. NOW THEN,"); - if (temp / 2 > stores) - System.out.println("HAMURABI: THINK AGAIN. YOU HAVE ONLY\n" + - stores + " BUSHELS OF GRAIN. NOW THEN,"); - if (temp > population * 10) - System.out.println("BUT YOU HAVE ONLY" + population + "PEOPLE TO TEND THE FIELDS. NOW THEN,"); - } while (temp > acres || temp / 2 > stores || temp > population * 10); - stores -= temp / 2; - yeild = (int) (Math.random() * 5 + 1); - harvest = temp * yeild; - temp = (int) (Math.random() * 5 + 1); - if (temp % 2 != 1) - eaten = (stores / temp); - else - eaten = 0; - stores += (harvest - eaten); - immigrants = (int) (Math.random() * 5 + 1) * - (20 * acres + stores) / population / 100 + 1; - if (population > fullPeople) { - deaths = population - fullPeople; - if (deaths > .45 * population) - epicFail(1); - percentDied = ((year - 1) * percentDied + deaths * 100 / population) / year; - population = fullPeople; - totalDeaths += deaths; - } - if (20 * Math.random() >= 17) - plague = true; - plague = false; - } - - private static String report() { - String answer = "\nHAMURABI: I BEG TO REPORT TO YOU,\n" + - "IN YEAR " + year + ", " + deaths + " PEOPLE STARVED, " + immigrants + " CAME TO THE CITY.\n"; - if (plague) { - population = population / 2; - answer += "A HORRIBLE PLAGUE STRUCK! HALF THE PEOPLE DIED.\n"; - } - answer += "POPULATION IS NOW " + population + ".\n" + - "THE CITY NOW OWNS " + acres + " ACRES.\n" + - "YOU HARVESTED " + yeild + " BUSHELS PER ACRE.\n" + - "RATS ATE " + eaten + " BUSHELS.\n" + - "YOU NOW HAVE " + stores + " BUSHELS IN STORE\n\n" + - "LAND IS TRADING AT " + landPrice + " BUSHELS PER ACRE."; - return answer; - } - - - private static void epicFail(int x) { - String reason = ""; - switch (x) { - case 0: reason = "HAMURABI: I CANNOT DO WHAT YOU WISH.\n" + - "GET YOURSELF ANOTHER STEWARD!!!!!"; break; - case 1: reason = "YOU STARVED " + deaths + " PEOPLE IN ONE YEAR!!!\n" + - FINK; break; - } - System.out.println(reason); - System.exit(0); - } - - private void finished() { - String answer = "IN YOUR 10-YEAR TERM OF OFFICE, " + percentDied + " PERCENT OF THE\n" + - "POPULATION STARVED PER YEAR ON AVERAGE, I.E., A TOTAL OF\n" + - totalDeaths + " PEOPLE DIED!!\n" + - "YOU STARTED WITH 10 ACRES PER PERSON AND ENDED WITH\n" + - acres / population + " ACRES PER PERSON\n\n"; - if (percentDied > 33 || acres / population < 7) - answer += FINK; - else if (percentDied > 10 || acres / population < 9) - answer += "YOUR HEAVY-HANDED PERFORMANCE SMACKS OF NERO AND IVAN IV.\n" + - "THE PEOPLE (REMAINING) FIND YOU AN UNPLEASANT RULER, AND,\n" + - "FRANKLY, HATE YOUR GUTS!"; - else if (percentDied > 3 || acres / population < 10) - answer += "YOUR PERFORMANCE COULD HAVE BEEN SOMEWHAT BETTER, BUT\n" + - "REALLY WASN'T TOO BAD AT ALL.\n" + - Math.random() * population * .8 + " PEOPLE WOULD" + - "DEARLY LIKE TO SEE YOU ASSASSINATED BUT WE ALL HAVE OUR" + - "TRIVIAL PROBLEMS"; - else - answer += "A FANTASTIC PERFORMANCE!!! CHARLEMANGE, DISRAELI, AND\n" + - "JEFFERSON COMBINED COULD NOT HAVE DONE BETTER!"; - answer += "\n\n\n\n\n\n\n\n\n\nSo long for now."; - System.out.println(answer); - } - - public static void main(String[] args) throws IOException { - HAMURABI a = new HAMURABI(); - System.out.println("\t\t\t\tHAMURABI\n\t CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n\n" + - "TRY YOUR HAND AT GOVERNING ANCIENT SUMERIA\nSUCCESSFULLY FOR A TEN-YEAR TERM OF OFFICE."); - while (year < 10) - a.newYear(); - a.finished(); - } -} \ No newline at end of file From 51a2a5be483a29f99cabdcd16fe19a89777fd1f3 Mon Sep 17 00:00:00 2001 From: Yingjie Yang <102939225+Tiffany678@users.noreply.github.com> Date: Sat, 12 Nov 2022 00:33:33 -0500 Subject: [PATCH 04/19] Finished the first method --- docs/matuszek/hamurabi.java | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/docs/matuszek/hamurabi.java b/docs/matuszek/hamurabi.java index 3ecf9c0..3e1a0f8 100644 --- a/docs/matuszek/hamurabi.java +++ b/docs/matuszek/hamurabi.java @@ -1,4 +1,4 @@ -package hammurabi; // package declaration +package Hammurabi; // package declaration import java.util.Random; // imports go here import java.util.Scanner; @@ -6,6 +6,19 @@ public class Hammurabi { // must save in a file named Hammurabi.java Random rand = new Random(); // this is an instance variable Scanner scanner = new Scanner(System.in); + int people; + int bushelsOfGrain; + int acres; + int landValue; + + public Hammurabi(int peo,int bus, int acr, int lan;){ + this.people=peo; + this.bushelsOfGrain=bus; + this.acres=acr; + this.landValue=lan; + } + + public static void main(String[] args) { // required in every Java program new Hammurabi().playGame(); } @@ -17,7 +30,14 @@ void playGame() { //other methods go here int askHowManyAcresToBuy(int price, int bushels){ - return 1; + System.out.println("How many acres do you wish to buy?"); + int in=scanner.nextInt(); + while(in*price>bushels || in <=0){ + System.out.println("Hammurabi: Thank again. You have only "+ bushels+" of grain. "); + System.out.println("Re-enter the numbers of acres you wish to buy"); + in=scanner.nextInt(); + } + return in; } //Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. From f305a4814fb851497c16513cc456d66d2246b2e9 Mon Sep 17 00:00:00 2001 From: Yingjie Yang <102939225+Tiffany678@users.noreply.github.com> Date: Sat, 12 Nov 2022 00:34:30 -0500 Subject: [PATCH 05/19] Rename hamurabi.java to Hammurabi.java --- docs/matuszek/{hamurabi.java => Hammurabi.java} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename docs/matuszek/{hamurabi.java => Hammurabi.java} (100%) diff --git a/docs/matuszek/hamurabi.java b/docs/matuszek/Hammurabi.java similarity index 100% rename from docs/matuszek/hamurabi.java rename to docs/matuszek/Hammurabi.java From 49b2998745aa954d24d04eb05d5afd345d96c04c Mon Sep 17 00:00:00 2001 From: Yingjie <52tiffany.yang@gmail.com> Date: Sat, 12 Nov 2022 09:45:50 -0500 Subject: [PATCH 06/19] Update --- .idea/misc.xml | 2 +- HammurabiTest.java | 125 -------- docs/matuszek/Hammurabi.java | 13 +- docs/matuszek/HammurabiTest.java | 14 +- target/classes/.gitignore | 23 ++ target/classes/.idea/.gitignore | 3 + target/classes/.idea/compiler.xml | 16 + target/classes/.idea/jarRepositories.xml | 20 ++ .../libraries/Maven__junit_junit_4_13_2.xml | 13 + .../Maven__org_hamcrest_hamcrest_core_1_3.xml | 13 + target/classes/.idea/misc.xml | 13 + target/classes/.idea/modules.xml | 8 + target/classes/.idea/vcs.xml | 6 + target/classes/Hamurabi.iml | 15 + target/classes/LICENSE | 21 ++ target/classes/README.md | 228 +++++++++++++ .../classes/docs/matuszek/06-hammurabi.html | 299 ++++++++++++++++++ target/classes/docs/matuszek/README..md | 6 + target/classes/pom.xml | 25 ++ target/classes/target/classes/.gitignore | 23 ++ .../classes/target/classes/.idea/.gitignore | 3 + .../classes/target/classes/.idea/compiler.xml | 16 + .../target/classes/.idea/jarRepositories.xml | 20 ++ .../libraries/Maven__junit_junit_4_13_2.xml | 13 + .../Maven__org_hamcrest_hamcrest_core_1_3.xml | 13 + target/classes/target/classes/.idea/misc.xml | 13 + .../classes/target/classes/.idea/modules.xml | 8 + target/classes/target/classes/.idea/vcs.xml | 6 + target/classes/target/classes/Hamurabi.iml | 15 + target/classes/target/classes/LICENSE | 21 ++ target/classes/target/classes/README.md | 228 +++++++++++++ .../classes/docs/matuszek/06-hammurabi.html | 299 ++++++++++++++++++ .../target/classes/docs/matuszek/README..md | 6 + target/classes/target/classes/pom.xml | 25 ++ .../target/classes/target/classes/.gitignore | 23 ++ .../target/classes/target/classes/LICENSE | 21 ++ .../target/classes/target/classes/README.md | 228 +++++++++++++ .../classes/docs/matuszek/06-hammurabi.html | 299 ++++++++++++++++++ .../target/classes/docs/matuszek/README..md | 6 + .../target/classes/target/classes/pom.xml | 25 ++ .../target/classes/target/classes/.gitignore | 23 ++ .../target/classes/target/classes/LICENSE | 21 ++ .../target/classes/target/classes/README.md | 228 +++++++++++++ .../classes/docs/matuszek/06-hammurabi.html | 299 ++++++++++++++++++ .../target/classes/docs/matuszek/README..md | 6 + .../target/classes/target/classes/pom.xml | 25 ++ .../target/classes/target/classes/.gitignore | 23 ++ .../target/classes/target/classes/LICENSE | 21 ++ .../target/classes/target/classes/README.md | 228 +++++++++++++ .../classes/docs/matuszek/06-hammurabi.html | 299 ++++++++++++++++++ .../target/classes/docs/matuszek/README..md | 6 + .../target/classes/target/classes/pom.xml | 25 ++ .../target/classes/target/classes/.gitignore | 23 ++ .../target/classes/target/classes/LICENSE | 21 ++ .../target/classes/target/classes/README.md | 228 +++++++++++++ .../classes/docs/matuszek/06-hammurabi.html | 299 ++++++++++++++++++ .../target/classes/docs/matuszek/README..md | 6 + .../target/classes/target/classes/pom.xml | 25 ++ 58 files changed, 3842 insertions(+), 138 deletions(-) delete mode 100644 HammurabiTest.java create mode 100644 target/classes/.gitignore create mode 100644 target/classes/.idea/.gitignore create mode 100644 target/classes/.idea/compiler.xml create mode 100644 target/classes/.idea/jarRepositories.xml create mode 100644 target/classes/.idea/libraries/Maven__junit_junit_4_13_2.xml create mode 100644 target/classes/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml create mode 100644 target/classes/.idea/misc.xml create mode 100644 target/classes/.idea/modules.xml create mode 100644 target/classes/.idea/vcs.xml create mode 100644 target/classes/Hamurabi.iml create mode 100644 target/classes/LICENSE create mode 100644 target/classes/README.md create mode 100644 target/classes/docs/matuszek/06-hammurabi.html create mode 100644 target/classes/docs/matuszek/README..md create mode 100644 target/classes/pom.xml create mode 100644 target/classes/target/classes/.gitignore create mode 100644 target/classes/target/classes/.idea/.gitignore create mode 100644 target/classes/target/classes/.idea/compiler.xml create mode 100644 target/classes/target/classes/.idea/jarRepositories.xml create mode 100644 target/classes/target/classes/.idea/libraries/Maven__junit_junit_4_13_2.xml create mode 100644 target/classes/target/classes/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml create mode 100644 target/classes/target/classes/.idea/misc.xml create mode 100644 target/classes/target/classes/.idea/modules.xml create mode 100644 target/classes/target/classes/.idea/vcs.xml create mode 100644 target/classes/target/classes/Hamurabi.iml create mode 100644 target/classes/target/classes/LICENSE create mode 100644 target/classes/target/classes/README.md create mode 100644 target/classes/target/classes/docs/matuszek/06-hammurabi.html create mode 100644 target/classes/target/classes/docs/matuszek/README..md create mode 100644 target/classes/target/classes/pom.xml create mode 100644 target/classes/target/classes/target/classes/.gitignore create mode 100644 target/classes/target/classes/target/classes/LICENSE create mode 100644 target/classes/target/classes/target/classes/README.md create mode 100644 target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html create mode 100644 target/classes/target/classes/target/classes/docs/matuszek/README..md create mode 100644 target/classes/target/classes/target/classes/pom.xml create mode 100644 target/classes/target/classes/target/classes/target/classes/.gitignore create mode 100644 target/classes/target/classes/target/classes/target/classes/LICENSE create mode 100644 target/classes/target/classes/target/classes/target/classes/README.md create mode 100644 target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html create mode 100644 target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md create mode 100644 target/classes/target/classes/target/classes/target/classes/pom.xml create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/README.md create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml diff --git a/.idea/misc.xml b/.idea/misc.xml index bcd41e5..213cea6 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -7,7 +7,7 @@ - + \ No newline at end of file diff --git a/HammurabiTest.java b/HammurabiTest.java deleted file mode 100644 index 5cf1cc9..0000000 --- a/HammurabiTest.java +++ /dev/null @@ -1,125 +0,0 @@ -package hammurabi; - -import static org.junit.Assert.*; - -import org.junit.Before; -import org.junit.Test; - -public class HammurabiTest { - - Hammurabi ham; - - boolean about(double expected, double actual) { - return actual > 0.90 * expected && actual < 1.10 * expected; - } - - @Before - public void setUp() throws Exception { - ham = new Hammurabi(); - } - - @Test - public final void testPlagueDeaths1() { - int number_of_plagues = 0; - for (int i = 0; i < 10000; i++) { - int deaths = ham.plagueDeaths(100); - if (deaths > 0) { - number_of_plagues += 1; - } - } - int percentPlagues = number_of_plagues / 100; - assertTrue("Number of plagues is about " + percentPlagues + ", not about 15%.", - about(1500, number_of_plagues)); - } - - @Test - public final void testPlagueDeaths2() { - int deaths = 0; - for (int i = 0; i < 10000; i++) { - deaths = ham.plagueDeaths(100); - if (deaths > 0) break; - } - assertEquals("In a plague, " + deaths + "% of your people die, not 50%.", - 50, deaths); - } - - @Test - public final void testStarvationDeaths() { - int deaths = ham.starvationDeaths(100, 1639); - assertEquals("Wrong number of starvations deaths.", 19, deaths); - deaths = ham.starvationDeaths(100, 2500); - if (deaths < 0) { - fail("You starved a negative number of people!"); - } - } - - @Test - public final void testUprising() { - assertTrue("Should have had an uprising!", ham.uprising(1000, 451)); - assertFalse("Should not have had an uprising!", ham.uprising(1000, 449)); - } - - @Test - public final void testImmigrants() { - int imm = ham.immigrants(10, 1200, 500); - assertEquals("Wrong number of immigrants.", 25, imm); - } - - @Test - public final void testHarvest() { - int[] yield = new int[7]; - for (int i = 0; i < 1000; i++) { - int harvest = ham.harvest(1); - assertTrue("Illegal harvest per acre: " + harvest, harvest > 0 && harvest <= 6); - yield[harvest] += 1; - } - for (int j = 1; j <= 6; j++) { - assertTrue("You never have a yield of " + j + " bushels per acre.", yield[j] > 0); - } - } - - @Test - public final void testGrainEatenByRats1() { - int infestations = 0; - for (int i = 0; i < 1000; i++) { - int eaten = ham.grainEatenByRats(100); - if (eaten > 0) { - infestations += 1; - } - } - int percentInfestations = infestations / 100; - assertTrue("Number of rat infestations is about " + percentInfestations + - ", not about 40%.", about(400, infestations)); - } - - @Test - public final void testGrainEatenByRats2() { - int percent = 0; - int[] counts = new int[31]; - for (int i = 0; i < 10000; i++) { - percent = ham.grainEatenByRats(100); - if (percent == 0) continue; - counts[percent] += 1; - assertTrue("Rats ate " + percent + "% of your grain, not 10% to 30%.", - percent >= 10 && percent <= 30); - } - for (int j = 11; j < 30; j++) { - assertTrue("Rats never ate " + j + "% of your grain.", counts[j] > 0); - } - } - - @Test - public final void testNewCostOfLand() { - int[] cost = new int[24]; - for (int i = 0; i < 1000; i++) { - int price = ham.newCostOfLand(); - assertTrue("Illegal cost of land: " + price, price >= 17 && price <= 23); - cost[price] += 1; - } - for (int j = 17; j <= 23; j++) { - assertTrue("You never have a land cost of " + j + " bushels per acre.", cost[j] > 0); - } - } - -} - diff --git a/docs/matuszek/Hammurabi.java b/docs/matuszek/Hammurabi.java index 3e1a0f8..2155b51 100644 --- a/docs/matuszek/Hammurabi.java +++ b/docs/matuszek/Hammurabi.java @@ -1,4 +1,4 @@ -package Hammurabi; // package declaration +package hammurabi.docs.matuszek;//package Hammurabi; import java.util.Random; // imports go here import java.util.Scanner; @@ -11,16 +11,19 @@ public class Hammurabi { // must save in a file named Hammurabi.java int acres; int landValue; - public Hammurabi(int peo,int bus, int acr, int lan;){ + public Hammurabi(int peo,int bus, int acr, int lan){ this.people=peo; this.bushelsOfGrain=bus; this.acres=acr; this.landValue=lan; } - +//* 100 people +//* 2800 bushels of grain in storage +//* 1000 acres of land +//* Land value is 19 bushels/acre public static void main(String[] args) { // required in every Java program - new Hammurabi().playGame(); + new Hammurabi(100,2800,1000,19).playGame(); } void playGame() { @@ -72,7 +75,7 @@ int starvationDeaths(int population, int bushelsFedToPeople){ // Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). boolean uprising(int population, int howManyPeopleStarved){ - return 1; + return true; } // Return true if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) diff --git a/docs/matuszek/HammurabiTest.java b/docs/matuszek/HammurabiTest.java index 5cf1cc9..1a41166 100644 --- a/docs/matuszek/HammurabiTest.java +++ b/docs/matuszek/HammurabiTest.java @@ -1,4 +1,4 @@ -package hammurabi; +package hammurabi.docs.matuszek; import static org.junit.Assert.*; @@ -6,16 +6,16 @@ import org.junit.Test; public class HammurabiTest { - + Hammurabi ham; - + boolean about(double expected, double actual) { return actual > 0.90 * expected && actual < 1.10 * expected; } @Before public void setUp() throws Exception { - ham = new Hammurabi(); + ham = new Hammurabi(100,2800,1000,19); } @Test @@ -42,7 +42,7 @@ public final void testPlagueDeaths2() { assertEquals("In a plague, " + deaths + "% of your people die, not 50%.", 50, deaths); } - + @Test public final void testStarvationDeaths() { int deaths = ham.starvationDeaths(100, 1639); @@ -69,7 +69,7 @@ public final void testImmigrants() { public final void testHarvest() { int[] yield = new int[7]; for (int i = 0; i < 1000; i++) { - int harvest = ham.harvest(1); + int harvest = ham.harvest(1,1); assertTrue("Illegal harvest per acre: " + harvest, harvest > 0 && harvest <= 6); yield[harvest] += 1; } @@ -88,7 +88,7 @@ public final void testGrainEatenByRats1() { } } int percentInfestations = infestations / 100; - assertTrue("Number of rat infestations is about " + percentInfestations + + assertTrue("Number of rat infestations is about " + percentInfestations + ", not about 40%.", about(400, infestations)); } diff --git a/target/classes/.gitignore b/target/classes/.gitignore new file mode 100644 index 0000000..a1c2a23 --- /dev/null +++ b/target/classes/.gitignore @@ -0,0 +1,23 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* diff --git a/target/classes/.idea/.gitignore b/target/classes/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/target/classes/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/target/classes/.idea/compiler.xml b/target/classes/.idea/compiler.xml new file mode 100644 index 0000000..639314b --- /dev/null +++ b/target/classes/.idea/compiler.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/target/classes/.idea/jarRepositories.xml b/target/classes/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/target/classes/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/target/classes/.idea/libraries/Maven__junit_junit_4_13_2.xml b/target/classes/.idea/libraries/Maven__junit_junit_4_13_2.xml new file mode 100644 index 0000000..606c352 --- /dev/null +++ b/target/classes/.idea/libraries/Maven__junit_junit_4_13_2.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/target/classes/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml b/target/classes/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml new file mode 100644 index 0000000..f58bbc1 --- /dev/null +++ b/target/classes/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/target/classes/.idea/misc.xml b/target/classes/.idea/misc.xml new file mode 100644 index 0000000..213cea6 --- /dev/null +++ b/target/classes/.idea/misc.xml @@ -0,0 +1,13 @@ + + + + + + + + + \ No newline at end of file diff --git a/target/classes/.idea/modules.xml b/target/classes/.idea/modules.xml new file mode 100644 index 0000000..16ae36c --- /dev/null +++ b/target/classes/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/target/classes/.idea/vcs.xml b/target/classes/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/target/classes/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/target/classes/Hamurabi.iml b/target/classes/Hamurabi.iml new file mode 100644 index 0000000..903044c --- /dev/null +++ b/target/classes/Hamurabi.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/target/classes/LICENSE b/target/classes/LICENSE new file mode 100644 index 0000000..22474e4 --- /dev/null +++ b/target/classes/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Zip Code Wilmington Core + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/target/classes/README.md b/target/classes/README.md new file mode 100644 index 0000000..e4672c9 --- /dev/null +++ b/target/classes/README.md @@ -0,0 +1,228 @@ +# hamurabi +an ancient (in more ways than one) computer game (text) + +## General idea of the lab + +*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. + +Here are the standard instructions for the game: + +> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** +> +> * **Each person needs at least 20 bushels of grain per year to survive** +> * **Each person can farm at most 10 acres of land** +> * **It takes 2 bushels of grain to farm an acre of land** +> * **The market price for land fluctuates yearly** +> +> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** + +### Maven + +There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. + +### Details + +Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): + +```java +package hammurabi; // package declaration +import java.util.Random; // imports go here +import java.util.Scanner; + +public class Hammurabi { // must save in a file named Hammurabi.java + Random rand = new Random(); // this is an instance variable + Scanner scanner = new Scanner(System.in); + + public static void main(String\[\] args) { // required in every Java program + new Hammurabi().playGame(); + } + + void playGame() { + // declare local variables here: grain, population, etc. + // statements go after the declations + } + + //other methods go here +} +``` + +### Playing the game + +Here is what you start the game with: + +* 100 people +* 2800 bushels of grain in storage +* 1000 acres of land +* Land value is 19 bushels/acre + + +Each year, print out a summary similar to the following: + + O great Hammurabi! + You are in year 1 of your ten year rule. + In the previous year 0 people starved to death. + In the previous year 5 people entered the kingdom. + The population is now 100. + We harvested 3000 bushels at 3 bushels per acre. + Rats destroyed 200 bushels, leaving 2800 bushels in storage. + The city owns 1000 acres of land. + Land is currently worth 19 bushels per acre. + +The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. + +Here's what your `playGame` method needs to do each year, for up to 10 years: + +> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: +> +> `int askHowManyAcresToBuy(int price, int bushels)` +> +> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. +> +> ` +> int askHowManyAcresToSell(int acresOwned)` +> +> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. +> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. +> +> ` +> int askHowMuchGrainToFeedPeople(int bushels)` +> +> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. +> +> ` +> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` +> +> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. +> +> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) +> +> Then the method needs to determine: +> +> 1. If there is a plague, and how many people die from it. +> 2. How many people starved. +> 3. How many people came to the city. +> 4. How good the harvest is. +> 5. If you have a problem with rats, and how much grain they eat. +> 6. How much land costs (for deciding what to do next). +> +> These can all be local variables of your `playGame` method. +> +> Use the following methods, **in this order,** to make the necessary calculations: +> +> `int plagueDeaths(int population)` +> +> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). +> +> ` +> int starvationDeaths(int population, int bushelsFedToPeople)` +> +> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). +> +> ` +> boolean uprising(int population, int howManyPeopleStarved)` +> +> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) +> +> ` +> int immigrants(int population, int acresOwned, int grainInStorage)` +> +> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. +> +> ` +> int harvest(int acres, int bushelsUsedAsSeed)` +> +> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. +> +> ` +> int grainEatenByRats(int bushels)` +> +> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). +> +> ` +> int newCostOfLand()` +> +> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) + +Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. + +When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. + +When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. + +Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. + +All the required arithmetic in this program should be **integer**. You do not need doubles. + +### Urgent! + +> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. + +### Things you need to know: + +#### Random numbers + +To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: + +> `static Random rand = new Random();` + +To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as + +> `myNewNumber = rand.nextInt(5); +> if (rand.nextInt(100) < 15) { ... }` + +To do something that happens `p` percent of the time, use + +> `if (rand.nextInt(100) < p) { _...do something..._ }` + +#### Getting input + +To get a number from the player, add this method to your program: + +```java + /** + * Prints the given message (which should ask the user for some integral + * quantity), and returns the number entered by the user. If the user's + * response isn't an integer, the question is repeated until the user + * does give a integer response. + * + * @param message The request to present to the user. + * @return The user's numeric response. + */ + int getNumber(String message) { + while (true) { + System.out.print(message); + try { + return scanner.nextInt(); + } + catch (InputMismatchException e) { + System.out.println("\"" + scanner.next() + "\" isn't a number!"); + } + } + } +``` + +Here is an example of how you can use this method: + +> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` + +### Structure of the solution + +* Project name: `Hammurabi` +* Package name: `hammurabi` +* Class names and method signatures: + * `class Hammurabi` + * `public static void main(String[] args)` + * Numerous other methods, as described above. + +The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. + +### Yo! Test it! + +You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! + +But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. + +### Credits + +Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) + diff --git a/target/classes/docs/matuszek/06-hammurabi.html b/target/classes/docs/matuszek/06-hammurabi.html new file mode 100644 index 0000000..78bbf24 --- /dev/null +++ b/target/classes/docs/matuszek/06-hammurabi.html @@ -0,0 +1,299 @@ + + + + + + + CIT591 Hammurabi + + + + + +

CIT 591 Assignment 3: + Hammurabi
+ Fall 2010, David Matuszek

+ +

Purpose of this assignment

+ +
    +
  • To get you started using Java.
  • +
+ +

General idea of the assignment

+ +

Hammurabi is a very old computer game. Your job is to bring it into the + 21st century by writing it in Java.

+ +

Here are the standard instructions for the game:

+ +
+

Congratulations, you are the newest ruler of + ancient Samaria, elected for a ten year term of office. Your duties are to + dispense food, direct farming, and buy and sell land as needed to support + your people. Watch out for rat infestiations and the plague! Grain is the + general currency, measured in bushels. The following will help you in your + decisions:

+ +
    +
  • Each person needs at least 20 bushels of + grain per year to survive
  • + +
  • Each person can farm at most 10 acres of + land
  • + +
  • It takes 2 bushels of grain to farm an acre + of land
  • + +
  • The market price for land fluctuates + yearly
  • +
+ +

Rule wisely and you will be showered with + appreciation at the end of your term. Rule poorly and you will be kicked + out of office!

+
+ +

Details

+ +

Define a single class named Hammurabi. Use the following skeleton (but leave out the // comments):

+
package hammurabi;               // package declaration
+
+import java.util.Random;         // imports go here
+import java.util.Scanner;
+
+/**
+ * The Hammurabi game.
+ * @author Your name goes here
+ * @author Your partner's name goes here
+ */
+public class Hammurabi {         // must save in a file named Hammurabi.java
+    Random rand = new Random();  // this is an instance variable
+    Scanner scanner = new Scanner(System.in);
+
+    public static void main(String[] args) { // required in every Java program
+        new Hammurabi().playGame();
+    }
+
+    void playGame() {
+        // declare local variables here: grain, population, etc.
+        // statements go after the declations
+    }
+
+    //other methods go here
+}
+

Playing the game

+

Here is what you start the game with: +

    +
  • 100 people
  • +
  • 2800 bushels of grain in storage
  • +
  • 1000 acres of land
  • +
  • Land value is 19 bushels/acre

    +
  • +
+

Each year, print out a summary similar to the following:

+
+O great Hammurabi!
+You are in year 1 of your ten year rule.
+In the previous year 0 people starved to death.
+In the previous year 5 people entered the kingdom.
+The population is now 100.
+We harvested 3000 bushels at 3 bushels per acre.
+Rats destroyed 200 bushels, leaving 2800 bushels in storage.
+The city owns 1000 acres of land.
+Land is currently worth 19 bushels per acre.
+
+ +

The above summary represents the initial state, at the beginning of + the first year--that is, when you first take office, and before you do any of + the computations below). So, for example, the previous year (under a + different ruler) must have started with 95 people; none starved, and 5 + entered the kingdom, so as you enter office you rule 100 people.

+ +

Here's what your playGame method needs to do each year, for up to 10 years:

+ +
+

Ask the player the following questions. These questions should be asked in this order. Do not give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below:

+
+
int askHowManyAcresToBuy(int price, int bushels)
+
Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase.
+

+ int askHowManyAcresToSell(int acresOwned)
+
Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have.
+ Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn.
+

+ int askHowMuchGrainToFeedPeople(int bushels)
+
Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You can feed them more than they need to survive.
+

+ int askHowManyAcresToPlant(int acresOwned, int population, int bushels)
+
Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year.
+
+

For each + question, do "sanity checking"; that is, test whether the answer is + possible (you have enough grain, you have enough people to do the planting + etc.), and keep asking until you get a possible value. (For example, + O Great Hammurabi, surely you jest! We have only 3415 bushels left!)

+ +

Then the method needs to determine:

+ +
    +
  1. If there is a plague, and how many people die from it.
  2. +
  3. How many people starved.
  4. +
  5. How many people came to the city.
  6. +
  7. How good the harvest is.
  8. +
  9. If you have a problem with rats, and how much grain they eat.
  10. +
  11. How much land costs (for deciding what to do next).
  12. +
+

These can all be local variables of your playGame method.

+

Use the following methods, in this order, to make the necessary calculations:

+
+
int plagueDeaths(int population)
+
Each year, there is a 15% chance of a horrible plague. When this + happens, half your people die. Return the number of plague deaths (possibly zero).
+

+ int starvationDeaths(int population, int bushelsFedToPeople)
+
Each person needs 20 bushels of grain to survive. If you feed them + more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero).
+

+ boolean uprising(int population, int howManyPeopleStarved)
+
Return true if more than + 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.)
+

+ int immigrants(int population, int acresOwned, int grainInStorage)
+
Nobody will come to the city if people are starving (so don't call this method). If everyone is + well fed, compute how many people come to the city as: (20 * number of acres you have + amount of grain you have in + storage) / (100 * population) + 1.
+

+ int harvest(int acres, int bushelsUsedAsSeed)
+
Choose a random integer between 1 and 6, inclusive. Each acre that was planted + with seed will yield this many bushels of grain. (Example: if you planted + 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested.
+

+ int grainEatenByRats(int bushels)
+
There is a 40% chance that you will have a rat infestation. When this + happens, rats will eat somewhere between 10% and 30% of your + grain. Return the amount of grain eaten by rats (possibly zero).
+

+ int newCostOfLand()
+
The price of land is random, and ranges from 17 to 23 bushels per + acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell + land.)
+
+
+

Do these computations, in this order, for each of ten years. Each + computation should be done in a separate method, and none of these methods + should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it.

+ +

When the computations are finished, call a method printSummary to print the + summary for the year. This method will take several parameters.

+ + +

When the game ends , use a method finalSummary to print out a final summary, and to tell the + player how good a job he/she did. I'll leave the details up to you, but the + usual evaluation is based on how many people starved, and how many acres per + person you end up with.

+

Your playGame method will be quite long, but very straightforward; it does very little but call other methods.

+

All the required arithmetic in this program should be integer. You + do not need doubles.

+ +

I suggest that you first get the simplest possible version of the program + running and tested out (that is, leave out things like rats, plagues, and + immigration), then add these things one at a time to a working + program, testing as you go.

+ +

Things you need to know:

+ +

Random numbers

+ +

To get a random number generator, you first need to import + java.util.Random (or java.util.*). Then, you can + create a random number generator with a statement such as:

+ +
+

static Random rand = new Random();

+
+ +

To get a new random number in the range 0..n-1, where + n is an int, call rand.nextInt(n). + To get a new random number in the range min..max, use + the expression rand.nextInt(max - min + 1) + min. You + can use the rand method in statements such as

+ +
+

myNewNumber = rand.nextInt(5);
+ if (rand.nextInt(100) < 15) { ... }

+
+ +

To do something that happens p percent of the time, use

+ +
+

if (rand.nextInt(100) < p) { ...do something... + }

+
+ +

Getting input

+

To get a number from the player, add this method to your program:

+
+/**
+ * Prints the given message (which should ask the user for some integral
+ * quantity), and returns the number entered by the user. If the user's
+ * response isn't an integer, the question is repeated until the user
+ * does give a integer response.
+ * 
+ * @param message The request to present to the user.
+ * @return The user's numeric response.
+ */
+ int getNumber(String message) {
+    while (true) {
+        System.out.print(message);
+        try {
+            return scanner.nextInt();
+        }
+        catch (InputMismatchException e) {
+            System.out.println("\"" + scanner.next() + "\" isn't a number!");
+        }
+    }
+}
+
+ +

Here is an example of how you can use this method:

+ +
+

sell = getNumber("O great Hammurabi, how many acres shall you sell?");

+
+ +

Structure of the assignment:

+ +
    +
  • Project name: Hammurabi
  • + +
  • Package name: hammurabi
  • + +
  • Class names and method signatures: + +
      +
    • + class Hammurabi + +
        +
      • public static void main(String[] args)
      • + +
      • Numerous other methods, as described above.
      • +
      +
    • +
    +
  • + +
+ +

The above are requirements. The methods that do calculations, not input/output, will be tested by my test methods, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument names are irrelevant). You may have additional methods if you wish.

+ +

Due date:

+ +

Thursday, October 21, before midnight. Turn in your zipped assignment via + Blackboard. Email submissions will incur the wrath of Hammurabi (and won't be graded).

+ + + diff --git a/target/classes/docs/matuszek/README..md b/target/classes/docs/matuszek/README..md new file mode 100644 index 0000000..796d85c --- /dev/null +++ b/target/classes/docs/matuszek/README..md @@ -0,0 +1,6 @@ +# Notes + +from the original Dave Matuszek course of 2010. + +https://www.cis.upenn.edu/~matuszek/cit591-2010/Assignments/06-hammurabi.html + diff --git a/target/classes/pom.xml b/target/classes/pom.xml new file mode 100644 index 0000000..d789654 --- /dev/null +++ b/target/classes/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + + io.zipcoder + MicroLabs-Loops + 1.0-SNAPSHOT + + + + + junit + junit + 4.13.2 + + + + + + 1.8 + 1.8 + + \ No newline at end of file diff --git a/target/classes/target/classes/.gitignore b/target/classes/target/classes/.gitignore new file mode 100644 index 0000000..a1c2a23 --- /dev/null +++ b/target/classes/target/classes/.gitignore @@ -0,0 +1,23 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* diff --git a/target/classes/target/classes/.idea/.gitignore b/target/classes/target/classes/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/target/classes/target/classes/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/target/classes/target/classes/.idea/compiler.xml b/target/classes/target/classes/.idea/compiler.xml new file mode 100644 index 0000000..639314b --- /dev/null +++ b/target/classes/target/classes/.idea/compiler.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/target/classes/target/classes/.idea/jarRepositories.xml b/target/classes/target/classes/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/target/classes/target/classes/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/target/classes/target/classes/.idea/libraries/Maven__junit_junit_4_13_2.xml b/target/classes/target/classes/.idea/libraries/Maven__junit_junit_4_13_2.xml new file mode 100644 index 0000000..606c352 --- /dev/null +++ b/target/classes/target/classes/.idea/libraries/Maven__junit_junit_4_13_2.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/target/classes/target/classes/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml b/target/classes/target/classes/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml new file mode 100644 index 0000000..f58bbc1 --- /dev/null +++ b/target/classes/target/classes/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/target/classes/target/classes/.idea/misc.xml b/target/classes/target/classes/.idea/misc.xml new file mode 100644 index 0000000..213cea6 --- /dev/null +++ b/target/classes/target/classes/.idea/misc.xml @@ -0,0 +1,13 @@ + + + + + + + + + \ No newline at end of file diff --git a/target/classes/target/classes/.idea/modules.xml b/target/classes/target/classes/.idea/modules.xml new file mode 100644 index 0000000..16ae36c --- /dev/null +++ b/target/classes/target/classes/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/target/classes/target/classes/.idea/vcs.xml b/target/classes/target/classes/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/target/classes/target/classes/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/target/classes/target/classes/Hamurabi.iml b/target/classes/target/classes/Hamurabi.iml new file mode 100644 index 0000000..903044c --- /dev/null +++ b/target/classes/target/classes/Hamurabi.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/target/classes/target/classes/LICENSE b/target/classes/target/classes/LICENSE new file mode 100644 index 0000000..22474e4 --- /dev/null +++ b/target/classes/target/classes/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Zip Code Wilmington Core + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/target/classes/target/classes/README.md b/target/classes/target/classes/README.md new file mode 100644 index 0000000..e4672c9 --- /dev/null +++ b/target/classes/target/classes/README.md @@ -0,0 +1,228 @@ +# hamurabi +an ancient (in more ways than one) computer game (text) + +## General idea of the lab + +*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. + +Here are the standard instructions for the game: + +> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** +> +> * **Each person needs at least 20 bushels of grain per year to survive** +> * **Each person can farm at most 10 acres of land** +> * **It takes 2 bushels of grain to farm an acre of land** +> * **The market price for land fluctuates yearly** +> +> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** + +### Maven + +There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. + +### Details + +Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): + +```java +package hammurabi; // package declaration +import java.util.Random; // imports go here +import java.util.Scanner; + +public class Hammurabi { // must save in a file named Hammurabi.java + Random rand = new Random(); // this is an instance variable + Scanner scanner = new Scanner(System.in); + + public static void main(String\[\] args) { // required in every Java program + new Hammurabi().playGame(); + } + + void playGame() { + // declare local variables here: grain, population, etc. + // statements go after the declations + } + + //other methods go here +} +``` + +### Playing the game + +Here is what you start the game with: + +* 100 people +* 2800 bushels of grain in storage +* 1000 acres of land +* Land value is 19 bushels/acre + + +Each year, print out a summary similar to the following: + + O great Hammurabi! + You are in year 1 of your ten year rule. + In the previous year 0 people starved to death. + In the previous year 5 people entered the kingdom. + The population is now 100. + We harvested 3000 bushels at 3 bushels per acre. + Rats destroyed 200 bushels, leaving 2800 bushels in storage. + The city owns 1000 acres of land. + Land is currently worth 19 bushels per acre. + +The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. + +Here's what your `playGame` method needs to do each year, for up to 10 years: + +> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: +> +> `int askHowManyAcresToBuy(int price, int bushels)` +> +> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. +> +> ` +> int askHowManyAcresToSell(int acresOwned)` +> +> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. +> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. +> +> ` +> int askHowMuchGrainToFeedPeople(int bushels)` +> +> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. +> +> ` +> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` +> +> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. +> +> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) +> +> Then the method needs to determine: +> +> 1. If there is a plague, and how many people die from it. +> 2. How many people starved. +> 3. How many people came to the city. +> 4. How good the harvest is. +> 5. If you have a problem with rats, and how much grain they eat. +> 6. How much land costs (for deciding what to do next). +> +> These can all be local variables of your `playGame` method. +> +> Use the following methods, **in this order,** to make the necessary calculations: +> +> `int plagueDeaths(int population)` +> +> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). +> +> ` +> int starvationDeaths(int population, int bushelsFedToPeople)` +> +> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). +> +> ` +> boolean uprising(int population, int howManyPeopleStarved)` +> +> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) +> +> ` +> int immigrants(int population, int acresOwned, int grainInStorage)` +> +> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. +> +> ` +> int harvest(int acres, int bushelsUsedAsSeed)` +> +> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. +> +> ` +> int grainEatenByRats(int bushels)` +> +> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). +> +> ` +> int newCostOfLand()` +> +> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) + +Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. + +When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. + +When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. + +Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. + +All the required arithmetic in this program should be **integer**. You do not need doubles. + +### Urgent! + +> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. + +### Things you need to know: + +#### Random numbers + +To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: + +> `static Random rand = new Random();` + +To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as + +> `myNewNumber = rand.nextInt(5); +> if (rand.nextInt(100) < 15) { ... }` + +To do something that happens `p` percent of the time, use + +> `if (rand.nextInt(100) < p) { _...do something..._ }` + +#### Getting input + +To get a number from the player, add this method to your program: + +```java + /** + * Prints the given message (which should ask the user for some integral + * quantity), and returns the number entered by the user. If the user's + * response isn't an integer, the question is repeated until the user + * does give a integer response. + * + * @param message The request to present to the user. + * @return The user's numeric response. + */ + int getNumber(String message) { + while (true) { + System.out.print(message); + try { + return scanner.nextInt(); + } + catch (InputMismatchException e) { + System.out.println("\"" + scanner.next() + "\" isn't a number!"); + } + } + } +``` + +Here is an example of how you can use this method: + +> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` + +### Structure of the solution + +* Project name: `Hammurabi` +* Package name: `hammurabi` +* Class names and method signatures: + * `class Hammurabi` + * `public static void main(String[] args)` + * Numerous other methods, as described above. + +The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. + +### Yo! Test it! + +You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! + +But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. + +### Credits + +Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) + diff --git a/target/classes/target/classes/docs/matuszek/06-hammurabi.html b/target/classes/target/classes/docs/matuszek/06-hammurabi.html new file mode 100644 index 0000000..78bbf24 --- /dev/null +++ b/target/classes/target/classes/docs/matuszek/06-hammurabi.html @@ -0,0 +1,299 @@ + + + + + + + CIT591 Hammurabi + + + + + +

CIT 591 Assignment 3: + Hammurabi
+ Fall 2010, David Matuszek

+ +

Purpose of this assignment

+ +
    +
  • To get you started using Java.
  • +
+ +

General idea of the assignment

+ +

Hammurabi is a very old computer game. Your job is to bring it into the + 21st century by writing it in Java.

+ +

Here are the standard instructions for the game:

+ +
+

Congratulations, you are the newest ruler of + ancient Samaria, elected for a ten year term of office. Your duties are to + dispense food, direct farming, and buy and sell land as needed to support + your people. Watch out for rat infestiations and the plague! Grain is the + general currency, measured in bushels. The following will help you in your + decisions:

+ +
    +
  • Each person needs at least 20 bushels of + grain per year to survive
  • + +
  • Each person can farm at most 10 acres of + land
  • + +
  • It takes 2 bushels of grain to farm an acre + of land
  • + +
  • The market price for land fluctuates + yearly
  • +
+ +

Rule wisely and you will be showered with + appreciation at the end of your term. Rule poorly and you will be kicked + out of office!

+
+ +

Details

+ +

Define a single class named Hammurabi. Use the following skeleton (but leave out the // comments):

+
package hammurabi;               // package declaration
+
+import java.util.Random;         // imports go here
+import java.util.Scanner;
+
+/**
+ * The Hammurabi game.
+ * @author Your name goes here
+ * @author Your partner's name goes here
+ */
+public class Hammurabi {         // must save in a file named Hammurabi.java
+    Random rand = new Random();  // this is an instance variable
+    Scanner scanner = new Scanner(System.in);
+
+    public static void main(String[] args) { // required in every Java program
+        new Hammurabi().playGame();
+    }
+
+    void playGame() {
+        // declare local variables here: grain, population, etc.
+        // statements go after the declations
+    }
+
+    //other methods go here
+}
+

Playing the game

+

Here is what you start the game with: +

    +
  • 100 people
  • +
  • 2800 bushels of grain in storage
  • +
  • 1000 acres of land
  • +
  • Land value is 19 bushels/acre

    +
  • +
+

Each year, print out a summary similar to the following:

+
+O great Hammurabi!
+You are in year 1 of your ten year rule.
+In the previous year 0 people starved to death.
+In the previous year 5 people entered the kingdom.
+The population is now 100.
+We harvested 3000 bushels at 3 bushels per acre.
+Rats destroyed 200 bushels, leaving 2800 bushels in storage.
+The city owns 1000 acres of land.
+Land is currently worth 19 bushels per acre.
+
+ +

The above summary represents the initial state, at the beginning of + the first year--that is, when you first take office, and before you do any of + the computations below). So, for example, the previous year (under a + different ruler) must have started with 95 people; none starved, and 5 + entered the kingdom, so as you enter office you rule 100 people.

+ +

Here's what your playGame method needs to do each year, for up to 10 years:

+ +
+

Ask the player the following questions. These questions should be asked in this order. Do not give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below:

+
+
int askHowManyAcresToBuy(int price, int bushels)
+
Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase.
+

+ int askHowManyAcresToSell(int acresOwned)
+
Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have.
+ Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn.
+

+ int askHowMuchGrainToFeedPeople(int bushels)
+
Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You can feed them more than they need to survive.
+

+ int askHowManyAcresToPlant(int acresOwned, int population, int bushels)
+
Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year.
+
+

For each + question, do "sanity checking"; that is, test whether the answer is + possible (you have enough grain, you have enough people to do the planting + etc.), and keep asking until you get a possible value. (For example, + O Great Hammurabi, surely you jest! We have only 3415 bushels left!)

+ +

Then the method needs to determine:

+ +
    +
  1. If there is a plague, and how many people die from it.
  2. +
  3. How many people starved.
  4. +
  5. How many people came to the city.
  6. +
  7. How good the harvest is.
  8. +
  9. If you have a problem with rats, and how much grain they eat.
  10. +
  11. How much land costs (for deciding what to do next).
  12. +
+

These can all be local variables of your playGame method.

+

Use the following methods, in this order, to make the necessary calculations:

+
+
int plagueDeaths(int population)
+
Each year, there is a 15% chance of a horrible plague. When this + happens, half your people die. Return the number of plague deaths (possibly zero).
+

+ int starvationDeaths(int population, int bushelsFedToPeople)
+
Each person needs 20 bushels of grain to survive. If you feed them + more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero).
+

+ boolean uprising(int population, int howManyPeopleStarved)
+
Return true if more than + 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.)
+

+ int immigrants(int population, int acresOwned, int grainInStorage)
+
Nobody will come to the city if people are starving (so don't call this method). If everyone is + well fed, compute how many people come to the city as: (20 * number of acres you have + amount of grain you have in + storage) / (100 * population) + 1.
+

+ int harvest(int acres, int bushelsUsedAsSeed)
+
Choose a random integer between 1 and 6, inclusive. Each acre that was planted + with seed will yield this many bushels of grain. (Example: if you planted + 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested.
+

+ int grainEatenByRats(int bushels)
+
There is a 40% chance that you will have a rat infestation. When this + happens, rats will eat somewhere between 10% and 30% of your + grain. Return the amount of grain eaten by rats (possibly zero).
+

+ int newCostOfLand()
+
The price of land is random, and ranges from 17 to 23 bushels per + acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell + land.)
+
+
+

Do these computations, in this order, for each of ten years. Each + computation should be done in a separate method, and none of these methods + should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it.

+ +

When the computations are finished, call a method printSummary to print the + summary for the year. This method will take several parameters.

+ + +

When the game ends , use a method finalSummary to print out a final summary, and to tell the + player how good a job he/she did. I'll leave the details up to you, but the + usual evaluation is based on how many people starved, and how many acres per + person you end up with.

+

Your playGame method will be quite long, but very straightforward; it does very little but call other methods.

+

All the required arithmetic in this program should be integer. You + do not need doubles.

+ +

I suggest that you first get the simplest possible version of the program + running and tested out (that is, leave out things like rats, plagues, and + immigration), then add these things one at a time to a working + program, testing as you go.

+ +

Things you need to know:

+ +

Random numbers

+ +

To get a random number generator, you first need to import + java.util.Random (or java.util.*). Then, you can + create a random number generator with a statement such as:

+ +
+

static Random rand = new Random();

+
+ +

To get a new random number in the range 0..n-1, where + n is an int, call rand.nextInt(n). + To get a new random number in the range min..max, use + the expression rand.nextInt(max - min + 1) + min. You + can use the rand method in statements such as

+ +
+

myNewNumber = rand.nextInt(5);
+ if (rand.nextInt(100) < 15) { ... }

+
+ +

To do something that happens p percent of the time, use

+ +
+

if (rand.nextInt(100) < p) { ...do something... + }

+
+ +

Getting input

+

To get a number from the player, add this method to your program:

+
+/**
+ * Prints the given message (which should ask the user for some integral
+ * quantity), and returns the number entered by the user. If the user's
+ * response isn't an integer, the question is repeated until the user
+ * does give a integer response.
+ * 
+ * @param message The request to present to the user.
+ * @return The user's numeric response.
+ */
+ int getNumber(String message) {
+    while (true) {
+        System.out.print(message);
+        try {
+            return scanner.nextInt();
+        }
+        catch (InputMismatchException e) {
+            System.out.println("\"" + scanner.next() + "\" isn't a number!");
+        }
+    }
+}
+
+ +

Here is an example of how you can use this method:

+ +
+

sell = getNumber("O great Hammurabi, how many acres shall you sell?");

+
+ +

Structure of the assignment:

+ +
    +
  • Project name: Hammurabi
  • + +
  • Package name: hammurabi
  • + +
  • Class names and method signatures: + +
      +
    • + class Hammurabi + +
        +
      • public static void main(String[] args)
      • + +
      • Numerous other methods, as described above.
      • +
      +
    • +
    +
  • + +
+ +

The above are requirements. The methods that do calculations, not input/output, will be tested by my test methods, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument names are irrelevant). You may have additional methods if you wish.

+ +

Due date:

+ +

Thursday, October 21, before midnight. Turn in your zipped assignment via + Blackboard. Email submissions will incur the wrath of Hammurabi (and won't be graded).

+ + + diff --git a/target/classes/target/classes/docs/matuszek/README..md b/target/classes/target/classes/docs/matuszek/README..md new file mode 100644 index 0000000..796d85c --- /dev/null +++ b/target/classes/target/classes/docs/matuszek/README..md @@ -0,0 +1,6 @@ +# Notes + +from the original Dave Matuszek course of 2010. + +https://www.cis.upenn.edu/~matuszek/cit591-2010/Assignments/06-hammurabi.html + diff --git a/target/classes/target/classes/pom.xml b/target/classes/target/classes/pom.xml new file mode 100644 index 0000000..d789654 --- /dev/null +++ b/target/classes/target/classes/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + + io.zipcoder + MicroLabs-Loops + 1.0-SNAPSHOT + + + + + junit + junit + 4.13.2 + + + + + + 1.8 + 1.8 + + \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/.gitignore b/target/classes/target/classes/target/classes/.gitignore new file mode 100644 index 0000000..a1c2a23 --- /dev/null +++ b/target/classes/target/classes/target/classes/.gitignore @@ -0,0 +1,23 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* diff --git a/target/classes/target/classes/target/classes/LICENSE b/target/classes/target/classes/target/classes/LICENSE new file mode 100644 index 0000000..22474e4 --- /dev/null +++ b/target/classes/target/classes/target/classes/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Zip Code Wilmington Core + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/target/classes/target/classes/target/classes/README.md b/target/classes/target/classes/target/classes/README.md new file mode 100644 index 0000000..e4672c9 --- /dev/null +++ b/target/classes/target/classes/target/classes/README.md @@ -0,0 +1,228 @@ +# hamurabi +an ancient (in more ways than one) computer game (text) + +## General idea of the lab + +*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. + +Here are the standard instructions for the game: + +> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** +> +> * **Each person needs at least 20 bushels of grain per year to survive** +> * **Each person can farm at most 10 acres of land** +> * **It takes 2 bushels of grain to farm an acre of land** +> * **The market price for land fluctuates yearly** +> +> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** + +### Maven + +There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. + +### Details + +Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): + +```java +package hammurabi; // package declaration +import java.util.Random; // imports go here +import java.util.Scanner; + +public class Hammurabi { // must save in a file named Hammurabi.java + Random rand = new Random(); // this is an instance variable + Scanner scanner = new Scanner(System.in); + + public static void main(String\[\] args) { // required in every Java program + new Hammurabi().playGame(); + } + + void playGame() { + // declare local variables here: grain, population, etc. + // statements go after the declations + } + + //other methods go here +} +``` + +### Playing the game + +Here is what you start the game with: + +* 100 people +* 2800 bushels of grain in storage +* 1000 acres of land +* Land value is 19 bushels/acre + + +Each year, print out a summary similar to the following: + + O great Hammurabi! + You are in year 1 of your ten year rule. + In the previous year 0 people starved to death. + In the previous year 5 people entered the kingdom. + The population is now 100. + We harvested 3000 bushels at 3 bushels per acre. + Rats destroyed 200 bushels, leaving 2800 bushels in storage. + The city owns 1000 acres of land. + Land is currently worth 19 bushels per acre. + +The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. + +Here's what your `playGame` method needs to do each year, for up to 10 years: + +> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: +> +> `int askHowManyAcresToBuy(int price, int bushels)` +> +> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. +> +> ` +> int askHowManyAcresToSell(int acresOwned)` +> +> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. +> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. +> +> ` +> int askHowMuchGrainToFeedPeople(int bushels)` +> +> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. +> +> ` +> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` +> +> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. +> +> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) +> +> Then the method needs to determine: +> +> 1. If there is a plague, and how many people die from it. +> 2. How many people starved. +> 3. How many people came to the city. +> 4. How good the harvest is. +> 5. If you have a problem with rats, and how much grain they eat. +> 6. How much land costs (for deciding what to do next). +> +> These can all be local variables of your `playGame` method. +> +> Use the following methods, **in this order,** to make the necessary calculations: +> +> `int plagueDeaths(int population)` +> +> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). +> +> ` +> int starvationDeaths(int population, int bushelsFedToPeople)` +> +> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). +> +> ` +> boolean uprising(int population, int howManyPeopleStarved)` +> +> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) +> +> ` +> int immigrants(int population, int acresOwned, int grainInStorage)` +> +> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. +> +> ` +> int harvest(int acres, int bushelsUsedAsSeed)` +> +> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. +> +> ` +> int grainEatenByRats(int bushels)` +> +> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). +> +> ` +> int newCostOfLand()` +> +> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) + +Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. + +When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. + +When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. + +Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. + +All the required arithmetic in this program should be **integer**. You do not need doubles. + +### Urgent! + +> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. + +### Things you need to know: + +#### Random numbers + +To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: + +> `static Random rand = new Random();` + +To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as + +> `myNewNumber = rand.nextInt(5); +> if (rand.nextInt(100) < 15) { ... }` + +To do something that happens `p` percent of the time, use + +> `if (rand.nextInt(100) < p) { _...do something..._ }` + +#### Getting input + +To get a number from the player, add this method to your program: + +```java + /** + * Prints the given message (which should ask the user for some integral + * quantity), and returns the number entered by the user. If the user's + * response isn't an integer, the question is repeated until the user + * does give a integer response. + * + * @param message The request to present to the user. + * @return The user's numeric response. + */ + int getNumber(String message) { + while (true) { + System.out.print(message); + try { + return scanner.nextInt(); + } + catch (InputMismatchException e) { + System.out.println("\"" + scanner.next() + "\" isn't a number!"); + } + } + } +``` + +Here is an example of how you can use this method: + +> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` + +### Structure of the solution + +* Project name: `Hammurabi` +* Package name: `hammurabi` +* Class names and method signatures: + * `class Hammurabi` + * `public static void main(String[] args)` + * Numerous other methods, as described above. + +The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. + +### Yo! Test it! + +You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! + +But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. + +### Credits + +Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) + diff --git a/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html b/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html new file mode 100644 index 0000000..78bbf24 --- /dev/null +++ b/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html @@ -0,0 +1,299 @@ + + + + + + + CIT591 Hammurabi + + + + + +

CIT 591 Assignment 3: + Hammurabi
+ Fall 2010, David Matuszek

+ +

Purpose of this assignment

+ +
    +
  • To get you started using Java.
  • +
+ +

General idea of the assignment

+ +

Hammurabi is a very old computer game. Your job is to bring it into the + 21st century by writing it in Java.

+ +

Here are the standard instructions for the game:

+ +
+

Congratulations, you are the newest ruler of + ancient Samaria, elected for a ten year term of office. Your duties are to + dispense food, direct farming, and buy and sell land as needed to support + your people. Watch out for rat infestiations and the plague! Grain is the + general currency, measured in bushels. The following will help you in your + decisions:

+ +
    +
  • Each person needs at least 20 bushels of + grain per year to survive
  • + +
  • Each person can farm at most 10 acres of + land
  • + +
  • It takes 2 bushels of grain to farm an acre + of land
  • + +
  • The market price for land fluctuates + yearly
  • +
+ +

Rule wisely and you will be showered with + appreciation at the end of your term. Rule poorly and you will be kicked + out of office!

+
+ +

Details

+ +

Define a single class named Hammurabi. Use the following skeleton (but leave out the // comments):

+
package hammurabi;               // package declaration
+
+import java.util.Random;         // imports go here
+import java.util.Scanner;
+
+/**
+ * The Hammurabi game.
+ * @author Your name goes here
+ * @author Your partner's name goes here
+ */
+public class Hammurabi {         // must save in a file named Hammurabi.java
+    Random rand = new Random();  // this is an instance variable
+    Scanner scanner = new Scanner(System.in);
+
+    public static void main(String[] args) { // required in every Java program
+        new Hammurabi().playGame();
+    }
+
+    void playGame() {
+        // declare local variables here: grain, population, etc.
+        // statements go after the declations
+    }
+
+    //other methods go here
+}
+

Playing the game

+

Here is what you start the game with: +

    +
  • 100 people
  • +
  • 2800 bushels of grain in storage
  • +
  • 1000 acres of land
  • +
  • Land value is 19 bushels/acre

    +
  • +
+

Each year, print out a summary similar to the following:

+
+O great Hammurabi!
+You are in year 1 of your ten year rule.
+In the previous year 0 people starved to death.
+In the previous year 5 people entered the kingdom.
+The population is now 100.
+We harvested 3000 bushels at 3 bushels per acre.
+Rats destroyed 200 bushels, leaving 2800 bushels in storage.
+The city owns 1000 acres of land.
+Land is currently worth 19 bushels per acre.
+
+ +

The above summary represents the initial state, at the beginning of + the first year--that is, when you first take office, and before you do any of + the computations below). So, for example, the previous year (under a + different ruler) must have started with 95 people; none starved, and 5 + entered the kingdom, so as you enter office you rule 100 people.

+ +

Here's what your playGame method needs to do each year, for up to 10 years:

+ +
+

Ask the player the following questions. These questions should be asked in this order. Do not give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below:

+
+
int askHowManyAcresToBuy(int price, int bushels)
+
Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase.
+

+ int askHowManyAcresToSell(int acresOwned)
+
Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have.
+ Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn.
+

+ int askHowMuchGrainToFeedPeople(int bushels)
+
Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You can feed them more than they need to survive.
+

+ int askHowManyAcresToPlant(int acresOwned, int population, int bushels)
+
Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year.
+
+

For each + question, do "sanity checking"; that is, test whether the answer is + possible (you have enough grain, you have enough people to do the planting + etc.), and keep asking until you get a possible value. (For example, + O Great Hammurabi, surely you jest! We have only 3415 bushels left!)

+ +

Then the method needs to determine:

+ +
    +
  1. If there is a plague, and how many people die from it.
  2. +
  3. How many people starved.
  4. +
  5. How many people came to the city.
  6. +
  7. How good the harvest is.
  8. +
  9. If you have a problem with rats, and how much grain they eat.
  10. +
  11. How much land costs (for deciding what to do next).
  12. +
+

These can all be local variables of your playGame method.

+

Use the following methods, in this order, to make the necessary calculations:

+
+
int plagueDeaths(int population)
+
Each year, there is a 15% chance of a horrible plague. When this + happens, half your people die. Return the number of plague deaths (possibly zero).
+

+ int starvationDeaths(int population, int bushelsFedToPeople)
+
Each person needs 20 bushels of grain to survive. If you feed them + more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero).
+

+ boolean uprising(int population, int howManyPeopleStarved)
+
Return true if more than + 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.)
+

+ int immigrants(int population, int acresOwned, int grainInStorage)
+
Nobody will come to the city if people are starving (so don't call this method). If everyone is + well fed, compute how many people come to the city as: (20 * number of acres you have + amount of grain you have in + storage) / (100 * population) + 1.
+

+ int harvest(int acres, int bushelsUsedAsSeed)
+
Choose a random integer between 1 and 6, inclusive. Each acre that was planted + with seed will yield this many bushels of grain. (Example: if you planted + 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested.
+

+ int grainEatenByRats(int bushels)
+
There is a 40% chance that you will have a rat infestation. When this + happens, rats will eat somewhere between 10% and 30% of your + grain. Return the amount of grain eaten by rats (possibly zero).
+

+ int newCostOfLand()
+
The price of land is random, and ranges from 17 to 23 bushels per + acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell + land.)
+
+
+

Do these computations, in this order, for each of ten years. Each + computation should be done in a separate method, and none of these methods + should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it.

+ +

When the computations are finished, call a method printSummary to print the + summary for the year. This method will take several parameters.

+ + +

When the game ends , use a method finalSummary to print out a final summary, and to tell the + player how good a job he/she did. I'll leave the details up to you, but the + usual evaluation is based on how many people starved, and how many acres per + person you end up with.

+

Your playGame method will be quite long, but very straightforward; it does very little but call other methods.

+

All the required arithmetic in this program should be integer. You + do not need doubles.

+ +

I suggest that you first get the simplest possible version of the program + running and tested out (that is, leave out things like rats, plagues, and + immigration), then add these things one at a time to a working + program, testing as you go.

+ +

Things you need to know:

+ +

Random numbers

+ +

To get a random number generator, you first need to import + java.util.Random (or java.util.*). Then, you can + create a random number generator with a statement such as:

+ +
+

static Random rand = new Random();

+
+ +

To get a new random number in the range 0..n-1, where + n is an int, call rand.nextInt(n). + To get a new random number in the range min..max, use + the expression rand.nextInt(max - min + 1) + min. You + can use the rand method in statements such as

+ +
+

myNewNumber = rand.nextInt(5);
+ if (rand.nextInt(100) < 15) { ... }

+
+ +

To do something that happens p percent of the time, use

+ +
+

if (rand.nextInt(100) < p) { ...do something... + }

+
+ +

Getting input

+

To get a number from the player, add this method to your program:

+
+/**
+ * Prints the given message (which should ask the user for some integral
+ * quantity), and returns the number entered by the user. If the user's
+ * response isn't an integer, the question is repeated until the user
+ * does give a integer response.
+ * 
+ * @param message The request to present to the user.
+ * @return The user's numeric response.
+ */
+ int getNumber(String message) {
+    while (true) {
+        System.out.print(message);
+        try {
+            return scanner.nextInt();
+        }
+        catch (InputMismatchException e) {
+            System.out.println("\"" + scanner.next() + "\" isn't a number!");
+        }
+    }
+}
+
+ +

Here is an example of how you can use this method:

+ +
+

sell = getNumber("O great Hammurabi, how many acres shall you sell?");

+
+ +

Structure of the assignment:

+ +
    +
  • Project name: Hammurabi
  • + +
  • Package name: hammurabi
  • + +
  • Class names and method signatures: + +
      +
    • + class Hammurabi + +
        +
      • public static void main(String[] args)
      • + +
      • Numerous other methods, as described above.
      • +
      +
    • +
    +
  • + +
+ +

The above are requirements. The methods that do calculations, not input/output, will be tested by my test methods, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument names are irrelevant). You may have additional methods if you wish.

+ +

Due date:

+ +

Thursday, October 21, before midnight. Turn in your zipped assignment via + Blackboard. Email submissions will incur the wrath of Hammurabi (and won't be graded).

+ + + diff --git a/target/classes/target/classes/target/classes/docs/matuszek/README..md b/target/classes/target/classes/target/classes/docs/matuszek/README..md new file mode 100644 index 0000000..796d85c --- /dev/null +++ b/target/classes/target/classes/target/classes/docs/matuszek/README..md @@ -0,0 +1,6 @@ +# Notes + +from the original Dave Matuszek course of 2010. + +https://www.cis.upenn.edu/~matuszek/cit591-2010/Assignments/06-hammurabi.html + diff --git a/target/classes/target/classes/target/classes/pom.xml b/target/classes/target/classes/target/classes/pom.xml new file mode 100644 index 0000000..d789654 --- /dev/null +++ b/target/classes/target/classes/target/classes/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + + io.zipcoder + MicroLabs-Loops + 1.0-SNAPSHOT + + + + + junit + junit + 4.13.2 + + + + + + 1.8 + 1.8 + + \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/target/classes/.gitignore b/target/classes/target/classes/target/classes/target/classes/.gitignore new file mode 100644 index 0000000..a1c2a23 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/.gitignore @@ -0,0 +1,23 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* diff --git a/target/classes/target/classes/target/classes/target/classes/LICENSE b/target/classes/target/classes/target/classes/target/classes/LICENSE new file mode 100644 index 0000000..22474e4 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Zip Code Wilmington Core + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/target/classes/target/classes/target/classes/target/classes/README.md b/target/classes/target/classes/target/classes/target/classes/README.md new file mode 100644 index 0000000..e4672c9 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/README.md @@ -0,0 +1,228 @@ +# hamurabi +an ancient (in more ways than one) computer game (text) + +## General idea of the lab + +*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. + +Here are the standard instructions for the game: + +> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** +> +> * **Each person needs at least 20 bushels of grain per year to survive** +> * **Each person can farm at most 10 acres of land** +> * **It takes 2 bushels of grain to farm an acre of land** +> * **The market price for land fluctuates yearly** +> +> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** + +### Maven + +There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. + +### Details + +Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): + +```java +package hammurabi; // package declaration +import java.util.Random; // imports go here +import java.util.Scanner; + +public class Hammurabi { // must save in a file named Hammurabi.java + Random rand = new Random(); // this is an instance variable + Scanner scanner = new Scanner(System.in); + + public static void main(String\[\] args) { // required in every Java program + new Hammurabi().playGame(); + } + + void playGame() { + // declare local variables here: grain, population, etc. + // statements go after the declations + } + + //other methods go here +} +``` + +### Playing the game + +Here is what you start the game with: + +* 100 people +* 2800 bushels of grain in storage +* 1000 acres of land +* Land value is 19 bushels/acre + + +Each year, print out a summary similar to the following: + + O great Hammurabi! + You are in year 1 of your ten year rule. + In the previous year 0 people starved to death. + In the previous year 5 people entered the kingdom. + The population is now 100. + We harvested 3000 bushels at 3 bushels per acre. + Rats destroyed 200 bushels, leaving 2800 bushels in storage. + The city owns 1000 acres of land. + Land is currently worth 19 bushels per acre. + +The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. + +Here's what your `playGame` method needs to do each year, for up to 10 years: + +> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: +> +> `int askHowManyAcresToBuy(int price, int bushels)` +> +> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. +> +> ` +> int askHowManyAcresToSell(int acresOwned)` +> +> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. +> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. +> +> ` +> int askHowMuchGrainToFeedPeople(int bushels)` +> +> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. +> +> ` +> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` +> +> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. +> +> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) +> +> Then the method needs to determine: +> +> 1. If there is a plague, and how many people die from it. +> 2. How many people starved. +> 3. How many people came to the city. +> 4. How good the harvest is. +> 5. If you have a problem with rats, and how much grain they eat. +> 6. How much land costs (for deciding what to do next). +> +> These can all be local variables of your `playGame` method. +> +> Use the following methods, **in this order,** to make the necessary calculations: +> +> `int plagueDeaths(int population)` +> +> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). +> +> ` +> int starvationDeaths(int population, int bushelsFedToPeople)` +> +> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). +> +> ` +> boolean uprising(int population, int howManyPeopleStarved)` +> +> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) +> +> ` +> int immigrants(int population, int acresOwned, int grainInStorage)` +> +> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. +> +> ` +> int harvest(int acres, int bushelsUsedAsSeed)` +> +> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. +> +> ` +> int grainEatenByRats(int bushels)` +> +> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). +> +> ` +> int newCostOfLand()` +> +> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) + +Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. + +When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. + +When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. + +Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. + +All the required arithmetic in this program should be **integer**. You do not need doubles. + +### Urgent! + +> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. + +### Things you need to know: + +#### Random numbers + +To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: + +> `static Random rand = new Random();` + +To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as + +> `myNewNumber = rand.nextInt(5); +> if (rand.nextInt(100) < 15) { ... }` + +To do something that happens `p` percent of the time, use + +> `if (rand.nextInt(100) < p) { _...do something..._ }` + +#### Getting input + +To get a number from the player, add this method to your program: + +```java + /** + * Prints the given message (which should ask the user for some integral + * quantity), and returns the number entered by the user. If the user's + * response isn't an integer, the question is repeated until the user + * does give a integer response. + * + * @param message The request to present to the user. + * @return The user's numeric response. + */ + int getNumber(String message) { + while (true) { + System.out.print(message); + try { + return scanner.nextInt(); + } + catch (InputMismatchException e) { + System.out.println("\"" + scanner.next() + "\" isn't a number!"); + } + } + } +``` + +Here is an example of how you can use this method: + +> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` + +### Structure of the solution + +* Project name: `Hammurabi` +* Package name: `hammurabi` +* Class names and method signatures: + * `class Hammurabi` + * `public static void main(String[] args)` + * Numerous other methods, as described above. + +The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. + +### Yo! Test it! + +You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! + +But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. + +### Credits + +Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) + diff --git a/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html b/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html new file mode 100644 index 0000000..78bbf24 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html @@ -0,0 +1,299 @@ + + + + + + + CIT591 Hammurabi + + + + + +

CIT 591 Assignment 3: + Hammurabi
+ Fall 2010, David Matuszek

+ +

Purpose of this assignment

+ +
    +
  • To get you started using Java.
  • +
+ +

General idea of the assignment

+ +

Hammurabi is a very old computer game. Your job is to bring it into the + 21st century by writing it in Java.

+ +

Here are the standard instructions for the game:

+ +
+

Congratulations, you are the newest ruler of + ancient Samaria, elected for a ten year term of office. Your duties are to + dispense food, direct farming, and buy and sell land as needed to support + your people. Watch out for rat infestiations and the plague! Grain is the + general currency, measured in bushels. The following will help you in your + decisions:

+ +
    +
  • Each person needs at least 20 bushels of + grain per year to survive
  • + +
  • Each person can farm at most 10 acres of + land
  • + +
  • It takes 2 bushels of grain to farm an acre + of land
  • + +
  • The market price for land fluctuates + yearly
  • +
+ +

Rule wisely and you will be showered with + appreciation at the end of your term. Rule poorly and you will be kicked + out of office!

+
+ +

Details

+ +

Define a single class named Hammurabi. Use the following skeleton (but leave out the // comments):

+
package hammurabi;               // package declaration
+
+import java.util.Random;         // imports go here
+import java.util.Scanner;
+
+/**
+ * The Hammurabi game.
+ * @author Your name goes here
+ * @author Your partner's name goes here
+ */
+public class Hammurabi {         // must save in a file named Hammurabi.java
+    Random rand = new Random();  // this is an instance variable
+    Scanner scanner = new Scanner(System.in);
+
+    public static void main(String[] args) { // required in every Java program
+        new Hammurabi().playGame();
+    }
+
+    void playGame() {
+        // declare local variables here: grain, population, etc.
+        // statements go after the declations
+    }
+
+    //other methods go here
+}
+

Playing the game

+

Here is what you start the game with: +

    +
  • 100 people
  • +
  • 2800 bushels of grain in storage
  • +
  • 1000 acres of land
  • +
  • Land value is 19 bushels/acre

    +
  • +
+

Each year, print out a summary similar to the following:

+
+O great Hammurabi!
+You are in year 1 of your ten year rule.
+In the previous year 0 people starved to death.
+In the previous year 5 people entered the kingdom.
+The population is now 100.
+We harvested 3000 bushels at 3 bushels per acre.
+Rats destroyed 200 bushels, leaving 2800 bushels in storage.
+The city owns 1000 acres of land.
+Land is currently worth 19 bushels per acre.
+
+ +

The above summary represents the initial state, at the beginning of + the first year--that is, when you first take office, and before you do any of + the computations below). So, for example, the previous year (under a + different ruler) must have started with 95 people; none starved, and 5 + entered the kingdom, so as you enter office you rule 100 people.

+ +

Here's what your playGame method needs to do each year, for up to 10 years:

+ +
+

Ask the player the following questions. These questions should be asked in this order. Do not give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below:

+
+
int askHowManyAcresToBuy(int price, int bushels)
+
Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase.
+

+ int askHowManyAcresToSell(int acresOwned)
+
Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have.
+ Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn.
+

+ int askHowMuchGrainToFeedPeople(int bushels)
+
Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You can feed them more than they need to survive.
+

+ int askHowManyAcresToPlant(int acresOwned, int population, int bushels)
+
Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year.
+
+

For each + question, do "sanity checking"; that is, test whether the answer is + possible (you have enough grain, you have enough people to do the planting + etc.), and keep asking until you get a possible value. (For example, + O Great Hammurabi, surely you jest! We have only 3415 bushels left!)

+ +

Then the method needs to determine:

+ +
    +
  1. If there is a plague, and how many people die from it.
  2. +
  3. How many people starved.
  4. +
  5. How many people came to the city.
  6. +
  7. How good the harvest is.
  8. +
  9. If you have a problem with rats, and how much grain they eat.
  10. +
  11. How much land costs (for deciding what to do next).
  12. +
+

These can all be local variables of your playGame method.

+

Use the following methods, in this order, to make the necessary calculations:

+
+
int plagueDeaths(int population)
+
Each year, there is a 15% chance of a horrible plague. When this + happens, half your people die. Return the number of plague deaths (possibly zero).
+

+ int starvationDeaths(int population, int bushelsFedToPeople)
+
Each person needs 20 bushels of grain to survive. If you feed them + more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero).
+

+ boolean uprising(int population, int howManyPeopleStarved)
+
Return true if more than + 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.)
+

+ int immigrants(int population, int acresOwned, int grainInStorage)
+
Nobody will come to the city if people are starving (so don't call this method). If everyone is + well fed, compute how many people come to the city as: (20 * number of acres you have + amount of grain you have in + storage) / (100 * population) + 1.
+

+ int harvest(int acres, int bushelsUsedAsSeed)
+
Choose a random integer between 1 and 6, inclusive. Each acre that was planted + with seed will yield this many bushels of grain. (Example: if you planted + 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested.
+

+ int grainEatenByRats(int bushels)
+
There is a 40% chance that you will have a rat infestation. When this + happens, rats will eat somewhere between 10% and 30% of your + grain. Return the amount of grain eaten by rats (possibly zero).
+

+ int newCostOfLand()
+
The price of land is random, and ranges from 17 to 23 bushels per + acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell + land.)
+
+
+

Do these computations, in this order, for each of ten years. Each + computation should be done in a separate method, and none of these methods + should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it.

+ +

When the computations are finished, call a method printSummary to print the + summary for the year. This method will take several parameters.

+ + +

When the game ends , use a method finalSummary to print out a final summary, and to tell the + player how good a job he/she did. I'll leave the details up to you, but the + usual evaluation is based on how many people starved, and how many acres per + person you end up with.

+

Your playGame method will be quite long, but very straightforward; it does very little but call other methods.

+

All the required arithmetic in this program should be integer. You + do not need doubles.

+ +

I suggest that you first get the simplest possible version of the program + running and tested out (that is, leave out things like rats, plagues, and + immigration), then add these things one at a time to a working + program, testing as you go.

+ +

Things you need to know:

+ +

Random numbers

+ +

To get a random number generator, you first need to import + java.util.Random (or java.util.*). Then, you can + create a random number generator with a statement such as:

+ +
+

static Random rand = new Random();

+
+ +

To get a new random number in the range 0..n-1, where + n is an int, call rand.nextInt(n). + To get a new random number in the range min..max, use + the expression rand.nextInt(max - min + 1) + min. You + can use the rand method in statements such as

+ +
+

myNewNumber = rand.nextInt(5);
+ if (rand.nextInt(100) < 15) { ... }

+
+ +

To do something that happens p percent of the time, use

+ +
+

if (rand.nextInt(100) < p) { ...do something... + }

+
+ +

Getting input

+

To get a number from the player, add this method to your program:

+
+/**
+ * Prints the given message (which should ask the user for some integral
+ * quantity), and returns the number entered by the user. If the user's
+ * response isn't an integer, the question is repeated until the user
+ * does give a integer response.
+ * 
+ * @param message The request to present to the user.
+ * @return The user's numeric response.
+ */
+ int getNumber(String message) {
+    while (true) {
+        System.out.print(message);
+        try {
+            return scanner.nextInt();
+        }
+        catch (InputMismatchException e) {
+            System.out.println("\"" + scanner.next() + "\" isn't a number!");
+        }
+    }
+}
+
+ +

Here is an example of how you can use this method:

+ +
+

sell = getNumber("O great Hammurabi, how many acres shall you sell?");

+
+ +

Structure of the assignment:

+ +
    +
  • Project name: Hammurabi
  • + +
  • Package name: hammurabi
  • + +
  • Class names and method signatures: + +
      +
    • + class Hammurabi + +
        +
      • public static void main(String[] args)
      • + +
      • Numerous other methods, as described above.
      • +
      +
    • +
    +
  • + +
+ +

The above are requirements. The methods that do calculations, not input/output, will be tested by my test methods, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument names are irrelevant). You may have additional methods if you wish.

+ +

Due date:

+ +

Thursday, October 21, before midnight. Turn in your zipped assignment via + Blackboard. Email submissions will incur the wrath of Hammurabi (and won't be graded).

+ + + diff --git a/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md b/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md new file mode 100644 index 0000000..796d85c --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md @@ -0,0 +1,6 @@ +# Notes + +from the original Dave Matuszek course of 2010. + +https://www.cis.upenn.edu/~matuszek/cit591-2010/Assignments/06-hammurabi.html + diff --git a/target/classes/target/classes/target/classes/target/classes/pom.xml b/target/classes/target/classes/target/classes/target/classes/pom.xml new file mode 100644 index 0000000..d789654 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + + io.zipcoder + MicroLabs-Loops + 1.0-SNAPSHOT + + + + + junit + junit + 4.13.2 + + + + + + 1.8 + 1.8 + + \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore b/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore new file mode 100644 index 0000000..a1c2a23 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore @@ -0,0 +1,23 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE b/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE new file mode 100644 index 0000000..22474e4 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Zip Code Wilmington Core + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/README.md b/target/classes/target/classes/target/classes/target/classes/target/classes/README.md new file mode 100644 index 0000000..e4672c9 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/README.md @@ -0,0 +1,228 @@ +# hamurabi +an ancient (in more ways than one) computer game (text) + +## General idea of the lab + +*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. + +Here are the standard instructions for the game: + +> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** +> +> * **Each person needs at least 20 bushels of grain per year to survive** +> * **Each person can farm at most 10 acres of land** +> * **It takes 2 bushels of grain to farm an acre of land** +> * **The market price for land fluctuates yearly** +> +> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** + +### Maven + +There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. + +### Details + +Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): + +```java +package hammurabi; // package declaration +import java.util.Random; // imports go here +import java.util.Scanner; + +public class Hammurabi { // must save in a file named Hammurabi.java + Random rand = new Random(); // this is an instance variable + Scanner scanner = new Scanner(System.in); + + public static void main(String\[\] args) { // required in every Java program + new Hammurabi().playGame(); + } + + void playGame() { + // declare local variables here: grain, population, etc. + // statements go after the declations + } + + //other methods go here +} +``` + +### Playing the game + +Here is what you start the game with: + +* 100 people +* 2800 bushels of grain in storage +* 1000 acres of land +* Land value is 19 bushels/acre + + +Each year, print out a summary similar to the following: + + O great Hammurabi! + You are in year 1 of your ten year rule. + In the previous year 0 people starved to death. + In the previous year 5 people entered the kingdom. + The population is now 100. + We harvested 3000 bushels at 3 bushels per acre. + Rats destroyed 200 bushels, leaving 2800 bushels in storage. + The city owns 1000 acres of land. + Land is currently worth 19 bushels per acre. + +The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. + +Here's what your `playGame` method needs to do each year, for up to 10 years: + +> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: +> +> `int askHowManyAcresToBuy(int price, int bushels)` +> +> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. +> +> ` +> int askHowManyAcresToSell(int acresOwned)` +> +> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. +> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. +> +> ` +> int askHowMuchGrainToFeedPeople(int bushels)` +> +> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. +> +> ` +> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` +> +> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. +> +> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) +> +> Then the method needs to determine: +> +> 1. If there is a plague, and how many people die from it. +> 2. How many people starved. +> 3. How many people came to the city. +> 4. How good the harvest is. +> 5. If you have a problem with rats, and how much grain they eat. +> 6. How much land costs (for deciding what to do next). +> +> These can all be local variables of your `playGame` method. +> +> Use the following methods, **in this order,** to make the necessary calculations: +> +> `int plagueDeaths(int population)` +> +> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). +> +> ` +> int starvationDeaths(int population, int bushelsFedToPeople)` +> +> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). +> +> ` +> boolean uprising(int population, int howManyPeopleStarved)` +> +> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) +> +> ` +> int immigrants(int population, int acresOwned, int grainInStorage)` +> +> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. +> +> ` +> int harvest(int acres, int bushelsUsedAsSeed)` +> +> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. +> +> ` +> int grainEatenByRats(int bushels)` +> +> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). +> +> ` +> int newCostOfLand()` +> +> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) + +Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. + +When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. + +When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. + +Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. + +All the required arithmetic in this program should be **integer**. You do not need doubles. + +### Urgent! + +> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. + +### Things you need to know: + +#### Random numbers + +To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: + +> `static Random rand = new Random();` + +To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as + +> `myNewNumber = rand.nextInt(5); +> if (rand.nextInt(100) < 15) { ... }` + +To do something that happens `p` percent of the time, use + +> `if (rand.nextInt(100) < p) { _...do something..._ }` + +#### Getting input + +To get a number from the player, add this method to your program: + +```java + /** + * Prints the given message (which should ask the user for some integral + * quantity), and returns the number entered by the user. If the user's + * response isn't an integer, the question is repeated until the user + * does give a integer response. + * + * @param message The request to present to the user. + * @return The user's numeric response. + */ + int getNumber(String message) { + while (true) { + System.out.print(message); + try { + return scanner.nextInt(); + } + catch (InputMismatchException e) { + System.out.println("\"" + scanner.next() + "\" isn't a number!"); + } + } + } +``` + +Here is an example of how you can use this method: + +> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` + +### Structure of the solution + +* Project name: `Hammurabi` +* Package name: `hammurabi` +* Class names and method signatures: + * `class Hammurabi` + * `public static void main(String[] args)` + * Numerous other methods, as described above. + +The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. + +### Yo! Test it! + +You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! + +But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. + +### Credits + +Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html b/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html new file mode 100644 index 0000000..78bbf24 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html @@ -0,0 +1,299 @@ + + + + + + + CIT591 Hammurabi + + + + + +

CIT 591 Assignment 3: + Hammurabi
+ Fall 2010, David Matuszek

+ +

Purpose of this assignment

+ +
    +
  • To get you started using Java.
  • +
+ +

General idea of the assignment

+ +

Hammurabi is a very old computer game. Your job is to bring it into the + 21st century by writing it in Java.

+ +

Here are the standard instructions for the game:

+ +
+

Congratulations, you are the newest ruler of + ancient Samaria, elected for a ten year term of office. Your duties are to + dispense food, direct farming, and buy and sell land as needed to support + your people. Watch out for rat infestiations and the plague! Grain is the + general currency, measured in bushels. The following will help you in your + decisions:

+ +
    +
  • Each person needs at least 20 bushels of + grain per year to survive
  • + +
  • Each person can farm at most 10 acres of + land
  • + +
  • It takes 2 bushels of grain to farm an acre + of land
  • + +
  • The market price for land fluctuates + yearly
  • +
+ +

Rule wisely and you will be showered with + appreciation at the end of your term. Rule poorly and you will be kicked + out of office!

+
+ +

Details

+ +

Define a single class named Hammurabi. Use the following skeleton (but leave out the // comments):

+
package hammurabi;               // package declaration
+
+import java.util.Random;         // imports go here
+import java.util.Scanner;
+
+/**
+ * The Hammurabi game.
+ * @author Your name goes here
+ * @author Your partner's name goes here
+ */
+public class Hammurabi {         // must save in a file named Hammurabi.java
+    Random rand = new Random();  // this is an instance variable
+    Scanner scanner = new Scanner(System.in);
+
+    public static void main(String[] args) { // required in every Java program
+        new Hammurabi().playGame();
+    }
+
+    void playGame() {
+        // declare local variables here: grain, population, etc.
+        // statements go after the declations
+    }
+
+    //other methods go here
+}
+

Playing the game

+

Here is what you start the game with: +

    +
  • 100 people
  • +
  • 2800 bushels of grain in storage
  • +
  • 1000 acres of land
  • +
  • Land value is 19 bushels/acre

    +
  • +
+

Each year, print out a summary similar to the following:

+
+O great Hammurabi!
+You are in year 1 of your ten year rule.
+In the previous year 0 people starved to death.
+In the previous year 5 people entered the kingdom.
+The population is now 100.
+We harvested 3000 bushels at 3 bushels per acre.
+Rats destroyed 200 bushels, leaving 2800 bushels in storage.
+The city owns 1000 acres of land.
+Land is currently worth 19 bushels per acre.
+
+ +

The above summary represents the initial state, at the beginning of + the first year--that is, when you first take office, and before you do any of + the computations below). So, for example, the previous year (under a + different ruler) must have started with 95 people; none starved, and 5 + entered the kingdom, so as you enter office you rule 100 people.

+ +

Here's what your playGame method needs to do each year, for up to 10 years:

+ +
+

Ask the player the following questions. These questions should be asked in this order. Do not give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below:

+
+
int askHowManyAcresToBuy(int price, int bushels)
+
Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase.
+

+ int askHowManyAcresToSell(int acresOwned)
+
Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have.
+ Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn.
+

+ int askHowMuchGrainToFeedPeople(int bushels)
+
Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You can feed them more than they need to survive.
+

+ int askHowManyAcresToPlant(int acresOwned, int population, int bushels)
+
Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year.
+
+

For each + question, do "sanity checking"; that is, test whether the answer is + possible (you have enough grain, you have enough people to do the planting + etc.), and keep asking until you get a possible value. (For example, + O Great Hammurabi, surely you jest! We have only 3415 bushels left!)

+ +

Then the method needs to determine:

+ +
    +
  1. If there is a plague, and how many people die from it.
  2. +
  3. How many people starved.
  4. +
  5. How many people came to the city.
  6. +
  7. How good the harvest is.
  8. +
  9. If you have a problem with rats, and how much grain they eat.
  10. +
  11. How much land costs (for deciding what to do next).
  12. +
+

These can all be local variables of your playGame method.

+

Use the following methods, in this order, to make the necessary calculations:

+
+
int plagueDeaths(int population)
+
Each year, there is a 15% chance of a horrible plague. When this + happens, half your people die. Return the number of plague deaths (possibly zero).
+

+ int starvationDeaths(int population, int bushelsFedToPeople)
+
Each person needs 20 bushels of grain to survive. If you feed them + more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero).
+

+ boolean uprising(int population, int howManyPeopleStarved)
+
Return true if more than + 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.)
+

+ int immigrants(int population, int acresOwned, int grainInStorage)
+
Nobody will come to the city if people are starving (so don't call this method). If everyone is + well fed, compute how many people come to the city as: (20 * number of acres you have + amount of grain you have in + storage) / (100 * population) + 1.
+

+ int harvest(int acres, int bushelsUsedAsSeed)
+
Choose a random integer between 1 and 6, inclusive. Each acre that was planted + with seed will yield this many bushels of grain. (Example: if you planted + 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested.
+

+ int grainEatenByRats(int bushels)
+
There is a 40% chance that you will have a rat infestation. When this + happens, rats will eat somewhere between 10% and 30% of your + grain. Return the amount of grain eaten by rats (possibly zero).
+

+ int newCostOfLand()
+
The price of land is random, and ranges from 17 to 23 bushels per + acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell + land.)
+
+
+

Do these computations, in this order, for each of ten years. Each + computation should be done in a separate method, and none of these methods + should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it.

+ +

When the computations are finished, call a method printSummary to print the + summary for the year. This method will take several parameters.

+ + +

When the game ends , use a method finalSummary to print out a final summary, and to tell the + player how good a job he/she did. I'll leave the details up to you, but the + usual evaluation is based on how many people starved, and how many acres per + person you end up with.

+

Your playGame method will be quite long, but very straightforward; it does very little but call other methods.

+

All the required arithmetic in this program should be integer. You + do not need doubles.

+ +

I suggest that you first get the simplest possible version of the program + running and tested out (that is, leave out things like rats, plagues, and + immigration), then add these things one at a time to a working + program, testing as you go.

+ +

Things you need to know:

+ +

Random numbers

+ +

To get a random number generator, you first need to import + java.util.Random (or java.util.*). Then, you can + create a random number generator with a statement such as:

+ +
+

static Random rand = new Random();

+
+ +

To get a new random number in the range 0..n-1, where + n is an int, call rand.nextInt(n). + To get a new random number in the range min..max, use + the expression rand.nextInt(max - min + 1) + min. You + can use the rand method in statements such as

+ +
+

myNewNumber = rand.nextInt(5);
+ if (rand.nextInt(100) < 15) { ... }

+
+ +

To do something that happens p percent of the time, use

+ +
+

if (rand.nextInt(100) < p) { ...do something... + }

+
+ +

Getting input

+

To get a number from the player, add this method to your program:

+
+/**
+ * Prints the given message (which should ask the user for some integral
+ * quantity), and returns the number entered by the user. If the user's
+ * response isn't an integer, the question is repeated until the user
+ * does give a integer response.
+ * 
+ * @param message The request to present to the user.
+ * @return The user's numeric response.
+ */
+ int getNumber(String message) {
+    while (true) {
+        System.out.print(message);
+        try {
+            return scanner.nextInt();
+        }
+        catch (InputMismatchException e) {
+            System.out.println("\"" + scanner.next() + "\" isn't a number!");
+        }
+    }
+}
+
+ +

Here is an example of how you can use this method:

+ +
+

sell = getNumber("O great Hammurabi, how many acres shall you sell?");

+
+ +

Structure of the assignment:

+ +
    +
  • Project name: Hammurabi
  • + +
  • Package name: hammurabi
  • + +
  • Class names and method signatures: + +
      +
    • + class Hammurabi + +
        +
      • public static void main(String[] args)
      • + +
      • Numerous other methods, as described above.
      • +
      +
    • +
    +
  • + +
+ +

The above are requirements. The methods that do calculations, not input/output, will be tested by my test methods, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument names are irrelevant). You may have additional methods if you wish.

+ +

Due date:

+ +

Thursday, October 21, before midnight. Turn in your zipped assignment via + Blackboard. Email submissions will incur the wrath of Hammurabi (and won't be graded).

+ + + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md b/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md new file mode 100644 index 0000000..796d85c --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md @@ -0,0 +1,6 @@ +# Notes + +from the original Dave Matuszek course of 2010. + +https://www.cis.upenn.edu/~matuszek/cit591-2010/Assignments/06-hammurabi.html + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml b/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml new file mode 100644 index 0000000..d789654 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + + io.zipcoder + MicroLabs-Loops + 1.0-SNAPSHOT + + + + + junit + junit + 4.13.2 + + + + + + 1.8 + 1.8 + + \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore new file mode 100644 index 0000000..a1c2a23 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore @@ -0,0 +1,23 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE new file mode 100644 index 0000000..22474e4 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Zip Code Wilmington Core + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md new file mode 100644 index 0000000..e4672c9 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md @@ -0,0 +1,228 @@ +# hamurabi +an ancient (in more ways than one) computer game (text) + +## General idea of the lab + +*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. + +Here are the standard instructions for the game: + +> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** +> +> * **Each person needs at least 20 bushels of grain per year to survive** +> * **Each person can farm at most 10 acres of land** +> * **It takes 2 bushels of grain to farm an acre of land** +> * **The market price for land fluctuates yearly** +> +> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** + +### Maven + +There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. + +### Details + +Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): + +```java +package hammurabi; // package declaration +import java.util.Random; // imports go here +import java.util.Scanner; + +public class Hammurabi { // must save in a file named Hammurabi.java + Random rand = new Random(); // this is an instance variable + Scanner scanner = new Scanner(System.in); + + public static void main(String\[\] args) { // required in every Java program + new Hammurabi().playGame(); + } + + void playGame() { + // declare local variables here: grain, population, etc. + // statements go after the declations + } + + //other methods go here +} +``` + +### Playing the game + +Here is what you start the game with: + +* 100 people +* 2800 bushels of grain in storage +* 1000 acres of land +* Land value is 19 bushels/acre + + +Each year, print out a summary similar to the following: + + O great Hammurabi! + You are in year 1 of your ten year rule. + In the previous year 0 people starved to death. + In the previous year 5 people entered the kingdom. + The population is now 100. + We harvested 3000 bushels at 3 bushels per acre. + Rats destroyed 200 bushels, leaving 2800 bushels in storage. + The city owns 1000 acres of land. + Land is currently worth 19 bushels per acre. + +The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. + +Here's what your `playGame` method needs to do each year, for up to 10 years: + +> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: +> +> `int askHowManyAcresToBuy(int price, int bushels)` +> +> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. +> +> ` +> int askHowManyAcresToSell(int acresOwned)` +> +> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. +> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. +> +> ` +> int askHowMuchGrainToFeedPeople(int bushels)` +> +> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. +> +> ` +> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` +> +> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. +> +> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) +> +> Then the method needs to determine: +> +> 1. If there is a plague, and how many people die from it. +> 2. How many people starved. +> 3. How many people came to the city. +> 4. How good the harvest is. +> 5. If you have a problem with rats, and how much grain they eat. +> 6. How much land costs (for deciding what to do next). +> +> These can all be local variables of your `playGame` method. +> +> Use the following methods, **in this order,** to make the necessary calculations: +> +> `int plagueDeaths(int population)` +> +> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). +> +> ` +> int starvationDeaths(int population, int bushelsFedToPeople)` +> +> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). +> +> ` +> boolean uprising(int population, int howManyPeopleStarved)` +> +> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) +> +> ` +> int immigrants(int population, int acresOwned, int grainInStorage)` +> +> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. +> +> ` +> int harvest(int acres, int bushelsUsedAsSeed)` +> +> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. +> +> ` +> int grainEatenByRats(int bushels)` +> +> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). +> +> ` +> int newCostOfLand()` +> +> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) + +Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. + +When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. + +When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. + +Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. + +All the required arithmetic in this program should be **integer**. You do not need doubles. + +### Urgent! + +> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. + +### Things you need to know: + +#### Random numbers + +To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: + +> `static Random rand = new Random();` + +To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as + +> `myNewNumber = rand.nextInt(5); +> if (rand.nextInt(100) < 15) { ... }` + +To do something that happens `p` percent of the time, use + +> `if (rand.nextInt(100) < p) { _...do something..._ }` + +#### Getting input + +To get a number from the player, add this method to your program: + +```java + /** + * Prints the given message (which should ask the user for some integral + * quantity), and returns the number entered by the user. If the user's + * response isn't an integer, the question is repeated until the user + * does give a integer response. + * + * @param message The request to present to the user. + * @return The user's numeric response. + */ + int getNumber(String message) { + while (true) { + System.out.print(message); + try { + return scanner.nextInt(); + } + catch (InputMismatchException e) { + System.out.println("\"" + scanner.next() + "\" isn't a number!"); + } + } + } +``` + +Here is an example of how you can use this method: + +> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` + +### Structure of the solution + +* Project name: `Hammurabi` +* Package name: `hammurabi` +* Class names and method signatures: + * `class Hammurabi` + * `public static void main(String[] args)` + * Numerous other methods, as described above. + +The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. + +### Yo! Test it! + +You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! + +But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. + +### Credits + +Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html new file mode 100644 index 0000000..78bbf24 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html @@ -0,0 +1,299 @@ + + + + + + + CIT591 Hammurabi + + + + + +

CIT 591 Assignment 3: + Hammurabi
+ Fall 2010, David Matuszek

+ +

Purpose of this assignment

+ +
    +
  • To get you started using Java.
  • +
+ +

General idea of the assignment

+ +

Hammurabi is a very old computer game. Your job is to bring it into the + 21st century by writing it in Java.

+ +

Here are the standard instructions for the game:

+ +
+

Congratulations, you are the newest ruler of + ancient Samaria, elected for a ten year term of office. Your duties are to + dispense food, direct farming, and buy and sell land as needed to support + your people. Watch out for rat infestiations and the plague! Grain is the + general currency, measured in bushels. The following will help you in your + decisions:

+ +
    +
  • Each person needs at least 20 bushels of + grain per year to survive
  • + +
  • Each person can farm at most 10 acres of + land
  • + +
  • It takes 2 bushels of grain to farm an acre + of land
  • + +
  • The market price for land fluctuates + yearly
  • +
+ +

Rule wisely and you will be showered with + appreciation at the end of your term. Rule poorly and you will be kicked + out of office!

+
+ +

Details

+ +

Define a single class named Hammurabi. Use the following skeleton (but leave out the // comments):

+
package hammurabi;               // package declaration
+
+import java.util.Random;         // imports go here
+import java.util.Scanner;
+
+/**
+ * The Hammurabi game.
+ * @author Your name goes here
+ * @author Your partner's name goes here
+ */
+public class Hammurabi {         // must save in a file named Hammurabi.java
+    Random rand = new Random();  // this is an instance variable
+    Scanner scanner = new Scanner(System.in);
+
+    public static void main(String[] args) { // required in every Java program
+        new Hammurabi().playGame();
+    }
+
+    void playGame() {
+        // declare local variables here: grain, population, etc.
+        // statements go after the declations
+    }
+
+    //other methods go here
+}
+

Playing the game

+

Here is what you start the game with: +

    +
  • 100 people
  • +
  • 2800 bushels of grain in storage
  • +
  • 1000 acres of land
  • +
  • Land value is 19 bushels/acre

    +
  • +
+

Each year, print out a summary similar to the following:

+
+O great Hammurabi!
+You are in year 1 of your ten year rule.
+In the previous year 0 people starved to death.
+In the previous year 5 people entered the kingdom.
+The population is now 100.
+We harvested 3000 bushels at 3 bushels per acre.
+Rats destroyed 200 bushels, leaving 2800 bushels in storage.
+The city owns 1000 acres of land.
+Land is currently worth 19 bushels per acre.
+
+ +

The above summary represents the initial state, at the beginning of + the first year--that is, when you first take office, and before you do any of + the computations below). So, for example, the previous year (under a + different ruler) must have started with 95 people; none starved, and 5 + entered the kingdom, so as you enter office you rule 100 people.

+ +

Here's what your playGame method needs to do each year, for up to 10 years:

+ +
+

Ask the player the following questions. These questions should be asked in this order. Do not give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below:

+
+
int askHowManyAcresToBuy(int price, int bushels)
+
Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase.
+

+ int askHowManyAcresToSell(int acresOwned)
+
Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have.
+ Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn.
+

+ int askHowMuchGrainToFeedPeople(int bushels)
+
Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You can feed them more than they need to survive.
+

+ int askHowManyAcresToPlant(int acresOwned, int population, int bushels)
+
Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year.
+
+

For each + question, do "sanity checking"; that is, test whether the answer is + possible (you have enough grain, you have enough people to do the planting + etc.), and keep asking until you get a possible value. (For example, + O Great Hammurabi, surely you jest! We have only 3415 bushels left!)

+ +

Then the method needs to determine:

+ +
    +
  1. If there is a plague, and how many people die from it.
  2. +
  3. How many people starved.
  4. +
  5. How many people came to the city.
  6. +
  7. How good the harvest is.
  8. +
  9. If you have a problem with rats, and how much grain they eat.
  10. +
  11. How much land costs (for deciding what to do next).
  12. +
+

These can all be local variables of your playGame method.

+

Use the following methods, in this order, to make the necessary calculations:

+
+
int plagueDeaths(int population)
+
Each year, there is a 15% chance of a horrible plague. When this + happens, half your people die. Return the number of plague deaths (possibly zero).
+

+ int starvationDeaths(int population, int bushelsFedToPeople)
+
Each person needs 20 bushels of grain to survive. If you feed them + more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero).
+

+ boolean uprising(int population, int howManyPeopleStarved)
+
Return true if more than + 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.)
+

+ int immigrants(int population, int acresOwned, int grainInStorage)
+
Nobody will come to the city if people are starving (so don't call this method). If everyone is + well fed, compute how many people come to the city as: (20 * number of acres you have + amount of grain you have in + storage) / (100 * population) + 1.
+

+ int harvest(int acres, int bushelsUsedAsSeed)
+
Choose a random integer between 1 and 6, inclusive. Each acre that was planted + with seed will yield this many bushels of grain. (Example: if you planted + 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested.
+

+ int grainEatenByRats(int bushels)
+
There is a 40% chance that you will have a rat infestation. When this + happens, rats will eat somewhere between 10% and 30% of your + grain. Return the amount of grain eaten by rats (possibly zero).
+

+ int newCostOfLand()
+
The price of land is random, and ranges from 17 to 23 bushels per + acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell + land.)
+
+
+

Do these computations, in this order, for each of ten years. Each + computation should be done in a separate method, and none of these methods + should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it.

+ +

When the computations are finished, call a method printSummary to print the + summary for the year. This method will take several parameters.

+ + +

When the game ends , use a method finalSummary to print out a final summary, and to tell the + player how good a job he/she did. I'll leave the details up to you, but the + usual evaluation is based on how many people starved, and how many acres per + person you end up with.

+

Your playGame method will be quite long, but very straightforward; it does very little but call other methods.

+

All the required arithmetic in this program should be integer. You + do not need doubles.

+ +

I suggest that you first get the simplest possible version of the program + running and tested out (that is, leave out things like rats, plagues, and + immigration), then add these things one at a time to a working + program, testing as you go.

+ +

Things you need to know:

+ +

Random numbers

+ +

To get a random number generator, you first need to import + java.util.Random (or java.util.*). Then, you can + create a random number generator with a statement such as:

+ +
+

static Random rand = new Random();

+
+ +

To get a new random number in the range 0..n-1, where + n is an int, call rand.nextInt(n). + To get a new random number in the range min..max, use + the expression rand.nextInt(max - min + 1) + min. You + can use the rand method in statements such as

+ +
+

myNewNumber = rand.nextInt(5);
+ if (rand.nextInt(100) < 15) { ... }

+
+ +

To do something that happens p percent of the time, use

+ +
+

if (rand.nextInt(100) < p) { ...do something... + }

+
+ +

Getting input

+

To get a number from the player, add this method to your program:

+
+/**
+ * Prints the given message (which should ask the user for some integral
+ * quantity), and returns the number entered by the user. If the user's
+ * response isn't an integer, the question is repeated until the user
+ * does give a integer response.
+ * 
+ * @param message The request to present to the user.
+ * @return The user's numeric response.
+ */
+ int getNumber(String message) {
+    while (true) {
+        System.out.print(message);
+        try {
+            return scanner.nextInt();
+        }
+        catch (InputMismatchException e) {
+            System.out.println("\"" + scanner.next() + "\" isn't a number!");
+        }
+    }
+}
+
+ +

Here is an example of how you can use this method:

+ +
+

sell = getNumber("O great Hammurabi, how many acres shall you sell?");

+
+ +

Structure of the assignment:

+ +
    +
  • Project name: Hammurabi
  • + +
  • Package name: hammurabi
  • + +
  • Class names and method signatures: + +
      +
    • + class Hammurabi + +
        +
      • public static void main(String[] args)
      • + +
      • Numerous other methods, as described above.
      • +
      +
    • +
    +
  • + +
+ +

The above are requirements. The methods that do calculations, not input/output, will be tested by my test methods, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument names are irrelevant). You may have additional methods if you wish.

+ +

Due date:

+ +

Thursday, October 21, before midnight. Turn in your zipped assignment via + Blackboard. Email submissions will incur the wrath of Hammurabi (and won't be graded).

+ + + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md new file mode 100644 index 0000000..796d85c --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md @@ -0,0 +1,6 @@ +# Notes + +from the original Dave Matuszek course of 2010. + +https://www.cis.upenn.edu/~matuszek/cit591-2010/Assignments/06-hammurabi.html + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml new file mode 100644 index 0000000..d789654 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + + io.zipcoder + MicroLabs-Loops + 1.0-SNAPSHOT + + + + + junit + junit + 4.13.2 + + + + + + 1.8 + 1.8 + + \ No newline at end of file From 8ad9f0541af24384f8faa6100b2052eac35311ad Mon Sep 17 00:00:00 2001 From: Hanquan Liu Date: Sat, 12 Nov 2022 11:11:38 -0500 Subject: [PATCH 07/19] newconstOfLand done --- .idea/misc.xml | 2 +- docs/matuszek/Hammurabi.java | 4 +++- target/classes/.idea/misc.xml | 2 +- .../classes/target/classes/.idea/.gitignore | 3 --- .../classes/target/classes/.idea/compiler.xml | 16 --------------- .../target/classes/.idea/jarRepositories.xml | 20 ------------------- .../libraries/Maven__junit_junit_4_13_2.xml | 13 ------------ .../Maven__org_hamcrest_hamcrest_core_1_3.xml | 13 ------------ target/classes/target/classes/.idea/misc.xml | 13 ------------ .../classes/target/classes/.idea/modules.xml | 8 -------- target/classes/target/classes/.idea/vcs.xml | 6 ------ target/classes/target/classes/Hamurabi.iml | 15 -------------- 12 files changed, 5 insertions(+), 110 deletions(-) delete mode 100644 target/classes/target/classes/.idea/.gitignore delete mode 100644 target/classes/target/classes/.idea/compiler.xml delete mode 100644 target/classes/target/classes/.idea/jarRepositories.xml delete mode 100644 target/classes/target/classes/.idea/libraries/Maven__junit_junit_4_13_2.xml delete mode 100644 target/classes/target/classes/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml delete mode 100644 target/classes/target/classes/.idea/misc.xml delete mode 100644 target/classes/target/classes/.idea/modules.xml delete mode 100644 target/classes/target/classes/.idea/vcs.xml delete mode 100644 target/classes/target/classes/Hamurabi.iml diff --git a/.idea/misc.xml b/.idea/misc.xml index 213cea6..bcd41e5 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -7,7 +7,7 @@
- + \ No newline at end of file diff --git a/docs/matuszek/Hammurabi.java b/docs/matuszek/Hammurabi.java index 2155b51..c764e07 100644 --- a/docs/matuszek/Hammurabi.java +++ b/docs/matuszek/Hammurabi.java @@ -99,7 +99,9 @@ int grainEatenByRats(int bushels){ //There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). int newCostOfLand(){ - return 1; + int min = 17, max = 23; + this.landValue = rand.nextInt(max - min) + min; + return this.landValue; } //The price of land is random, and diff --git a/target/classes/.idea/misc.xml b/target/classes/.idea/misc.xml index 213cea6..bcd41e5 100644 --- a/target/classes/.idea/misc.xml +++ b/target/classes/.idea/misc.xml @@ -7,7 +7,7 @@ - + \ No newline at end of file diff --git a/target/classes/target/classes/.idea/.gitignore b/target/classes/target/classes/.idea/.gitignore deleted file mode 100644 index 26d3352..0000000 --- a/target/classes/target/classes/.idea/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml diff --git a/target/classes/target/classes/.idea/compiler.xml b/target/classes/target/classes/.idea/compiler.xml deleted file mode 100644 index 639314b..0000000 --- a/target/classes/target/classes/.idea/compiler.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/target/classes/target/classes/.idea/jarRepositories.xml b/target/classes/target/classes/.idea/jarRepositories.xml deleted file mode 100644 index 712ab9d..0000000 --- a/target/classes/target/classes/.idea/jarRepositories.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/target/classes/target/classes/.idea/libraries/Maven__junit_junit_4_13_2.xml b/target/classes/target/classes/.idea/libraries/Maven__junit_junit_4_13_2.xml deleted file mode 100644 index 606c352..0000000 --- a/target/classes/target/classes/.idea/libraries/Maven__junit_junit_4_13_2.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/target/classes/target/classes/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml b/target/classes/target/classes/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml deleted file mode 100644 index f58bbc1..0000000 --- a/target/classes/target/classes/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/target/classes/target/classes/.idea/misc.xml b/target/classes/target/classes/.idea/misc.xml deleted file mode 100644 index 213cea6..0000000 --- a/target/classes/target/classes/.idea/misc.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/target/classes/target/classes/.idea/modules.xml b/target/classes/target/classes/.idea/modules.xml deleted file mode 100644 index 16ae36c..0000000 --- a/target/classes/target/classes/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/target/classes/target/classes/.idea/vcs.xml b/target/classes/target/classes/.idea/vcs.xml deleted file mode 100644 index 35eb1dd..0000000 --- a/target/classes/target/classes/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/target/classes/target/classes/Hamurabi.iml b/target/classes/target/classes/Hamurabi.iml deleted file mode 100644 index 903044c..0000000 --- a/target/classes/target/classes/Hamurabi.iml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file From e1c1e160c4a0c49903917a5f3555cb2eebf6616b Mon Sep 17 00:00:00 2001 From: Hanquan Liu Date: Sat, 12 Nov 2022 13:25:43 -0500 Subject: [PATCH 08/19] grainEatenByRats pass --- docs/matuszek/Hammurabi.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/docs/matuszek/Hammurabi.java b/docs/matuszek/Hammurabi.java index c764e07..f9e92c3 100644 --- a/docs/matuszek/Hammurabi.java +++ b/docs/matuszek/Hammurabi.java @@ -93,13 +93,21 @@ int harvest(int acres, int bushelsUsedAsSeed){ //Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. int grainEatenByRats(int bushels){ - return 1; + boolean ratInfestation = false; + int ratEaten = 0; + if(rand.nextFloat() * 100 <= 40){ + ratInfestation = true; + } + if(ratInfestation){ + ratEaten = bushels * (rand.nextInt(31 - 10 ) + 10) / 100; + } + return ratEaten; } //There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). int newCostOfLand(){ - int min = 17, max = 23; + int min = 17, max = 24; this.landValue = rand.nextInt(max - min) + min; return this.landValue; } From 8ec624f19f61107111137e8070f7c5b7ed9ab43d Mon Sep 17 00:00:00 2001 From: Hanquan Liu Date: Sat, 12 Nov 2022 13:38:27 -0500 Subject: [PATCH 09/19] harvest pass --- docs/matuszek/Hammurabi.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/matuszek/Hammurabi.java b/docs/matuszek/Hammurabi.java index f9e92c3..9cde711 100644 --- a/docs/matuszek/Hammurabi.java +++ b/docs/matuszek/Hammurabi.java @@ -87,7 +87,9 @@ int immigrants(int population, int acresOwned, int grainInStorage){ //Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: (20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1. int harvest(int acres, int bushelsUsedAsSeed){ - return 1; + int fertilizer = rand.nextInt(7 - 1) + 1; + + return bushelsUsedAsSeed * fertilizer * acres; } //Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. From f3c5447b3bf3f613ce22d30f2d0b253813bd3f39 Mon Sep 17 00:00:00 2001 From: Hanquan Liu Date: Sat, 12 Nov 2022 14:07:44 -0500 Subject: [PATCH 10/19] immigrants pass --- docs/matuszek/Hammurabi.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/docs/matuszek/Hammurabi.java b/docs/matuszek/Hammurabi.java index 9cde711..5d11bf9 100644 --- a/docs/matuszek/Hammurabi.java +++ b/docs/matuszek/Hammurabi.java @@ -10,6 +10,10 @@ public class Hammurabi { // must save in a file named Hammurabi.java int bushelsOfGrain; int acres; int landValue; + int harvest = 0; + int ratEaten = 0; + int starving = 0; + int immigrants = 0; public Hammurabi(int peo,int bus, int acr, int lan){ this.people=peo; @@ -81,15 +85,19 @@ boolean uprising(int population, int howManyPeopleStarved){ // Return true if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) int immigrants(int population, int acresOwned, int grainInStorage){ - return 1; + if(starving == 0){ + this.immigrants = (20 * acresOwned + grainInStorage) / (100 * population) + 1; + } + + return immigrants; } //Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: (20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1. int harvest(int acres, int bushelsUsedAsSeed){ int fertilizer = rand.nextInt(7 - 1) + 1; - - return bushelsUsedAsSeed * fertilizer * acres; + this.harvest = bushelsUsedAsSeed * fertilizer * acres; + return harvest; } //Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. @@ -103,7 +111,8 @@ int grainEatenByRats(int bushels){ if(ratInfestation){ ratEaten = bushels * (rand.nextInt(31 - 10 ) + 10) / 100; } - return ratEaten; + this.ratEaten = ratEaten; + return this.ratEaten; } //There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). From 6d2979c1d5886c126aeaeff7a492fb1b1affaa25 Mon Sep 17 00:00:00 2001 From: Hanquan Liu Date: Sat, 12 Nov 2022 14:43:24 -0500 Subject: [PATCH 11/19] uprising pass --- docs/matuszek/Hammurabi.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/docs/matuszek/Hammurabi.java b/docs/matuszek/Hammurabi.java index 5d11bf9..d4dd7c7 100644 --- a/docs/matuszek/Hammurabi.java +++ b/docs/matuszek/Hammurabi.java @@ -6,6 +6,7 @@ public class Hammurabi { // must save in a file named Hammurabi.java Random rand = new Random(); // this is an instance variable Scanner scanner = new Scanner(System.in); + boolean gameOver = false; int people; int bushelsOfGrain; int acres; @@ -15,6 +16,7 @@ public class Hammurabi { // must save in a file named Hammurabi.java int starving = 0; int immigrants = 0; + public Hammurabi(int peo,int bus, int acr, int lan){ this.people=peo; this.bushelsOfGrain=bus; @@ -79,7 +81,14 @@ int starvationDeaths(int population, int bushelsFedToPeople){ // Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). boolean uprising(int population, int howManyPeopleStarved){ - return true; + double starvingRate = (double) howManyPeopleStarved / population; + if(starvingRate > 0.450){ + this.gameOver = true; + } else if (starvingRate <= 0.450) { + this.gameOver = false; + } + + return this.gameOver; } // Return true if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) From 250be18fdae15fbcc8679452ffb77dee9812ffdd Mon Sep 17 00:00:00 2001 From: Yingjie <52tiffany.yang@gmail.com> Date: Sat, 12 Nov 2022 16:06:50 -0500 Subject: [PATCH 12/19] update on some methods --- docs/matuszek/Hammurabi.java | 93 ++++-- .../classes/target/classes/.idea/.gitignore | 3 + .../classes/target/classes/.idea/compiler.xml | 16 + .../target/classes/.idea/jarRepositories.xml | 20 ++ .../libraries/Maven__junit_junit_4_13_2.xml | 13 + .../Maven__org_hamcrest_hamcrest_core_1_3.xml | 13 + .../classes/target/classes/.idea/misc.xml | 13 + .../classes/target/classes/.idea/modules.xml | 8 + .../classes/target/classes/.idea/vcs.xml | 6 + .../classes/target/classes/Hamurabi.iml | 15 + .../target/classes/target/classes/.gitignore | 23 ++ .../target/classes/target/classes/LICENSE | 21 ++ .../target/classes/target/classes/README.md | 228 +++++++++++++ .../classes/docs/matuszek/06-hammurabi.html | 299 ++++++++++++++++++ .../target/classes/docs/matuszek/README..md | 6 + .../target/classes/target/classes/pom.xml | 25 ++ .../target/classes/target/classes/.gitignore | 23 ++ .../target/classes/target/classes/LICENSE | 21 ++ .../target/classes/target/classes/README.md | 228 +++++++++++++ .../classes/docs/matuszek/06-hammurabi.html | 299 ++++++++++++++++++ .../target/classes/docs/matuszek/README..md | 6 + .../target/classes/target/classes/pom.xml | 25 ++ .../target/classes/target/classes/.gitignore | 23 ++ .../target/classes/target/classes/LICENSE | 21 ++ .../target/classes/target/classes/README.md | 228 +++++++++++++ .../classes/docs/matuszek/06-hammurabi.html | 299 ++++++++++++++++++ .../target/classes/docs/matuszek/README..md | 6 + .../target/classes/target/classes/pom.xml | 25 ++ .../target/classes/target/classes/.gitignore | 23 ++ .../target/classes/target/classes/LICENSE | 21 ++ .../target/classes/target/classes/README.md | 228 +++++++++++++ .../classes/docs/matuszek/06-hammurabi.html | 299 ++++++++++++++++++ .../target/classes/docs/matuszek/README..md | 6 + .../target/classes/target/classes/pom.xml | 25 ++ .../target/classes/target/classes/.gitignore | 23 ++ .../target/classes/target/classes/LICENSE | 21 ++ .../target/classes/target/classes/README.md | 228 +++++++++++++ .../classes/docs/matuszek/06-hammurabi.html | 299 ++++++++++++++++++ .../target/classes/docs/matuszek/README..md | 6 + .../target/classes/target/classes/pom.xml | 25 ++ .../target/classes/target/classes/.gitignore | 23 ++ .../target/classes/target/classes/LICENSE | 21 ++ .../target/classes/target/classes/README.md | 228 +++++++++++++ .../classes/docs/matuszek/06-hammurabi.html | 299 ++++++++++++++++++ .../target/classes/docs/matuszek/README..md | 6 + .../target/classes/target/classes/pom.xml | 25 ++ .../target/classes/target/classes/.gitignore | 23 ++ .../target/classes/target/classes/LICENSE | 21 ++ .../target/classes/target/classes/README.md | 228 +++++++++++++ .../classes/docs/matuszek/06-hammurabi.html | 299 ++++++++++++++++++ .../target/classes/docs/matuszek/README..md | 6 + .../target/classes/target/classes/pom.xml | 25 ++ .../target/classes/target/classes/.gitignore | 23 ++ .../target/classes/target/classes/LICENSE | 21 ++ .../target/classes/target/classes/README.md | 228 +++++++++++++ .../classes/docs/matuszek/06-hammurabi.html | 299 ++++++++++++++++++ .../target/classes/docs/matuszek/README..md | 6 + .../target/classes/target/classes/pom.xml | 25 ++ .../target/classes/target/classes/.gitignore | 23 ++ .../target/classes/target/classes/LICENSE | 21 ++ .../target/classes/target/classes/README.md | 228 +++++++++++++ .../classes/docs/matuszek/06-hammurabi.html | 299 ++++++++++++++++++ .../target/classes/docs/matuszek/README..md | 6 + .../target/classes/target/classes/pom.xml | 25 ++ .../target/classes/target/classes/.gitignore | 23 ++ .../target/classes/target/classes/LICENSE | 21 ++ .../target/classes/target/classes/README.md | 228 +++++++++++++ .../classes/docs/matuszek/06-hammurabi.html | 299 ++++++++++++++++++ .../target/classes/docs/matuszek/README..md | 6 + .../target/classes/target/classes/pom.xml | 25 ++ .../target/classes/target/classes/.gitignore | 23 ++ .../target/classes/target/classes/LICENSE | 21 ++ .../target/classes/target/classes/README.md | 228 +++++++++++++ .../classes/docs/matuszek/06-hammurabi.html | 299 ++++++++++++++++++ .../target/classes/docs/matuszek/README..md | 6 + .../target/classes/target/classes/pom.xml | 25 ++ .../target/classes/target/classes/.gitignore | 23 ++ .../target/classes/target/classes/LICENSE | 21 ++ .../target/classes/target/classes/README.md | 228 +++++++++++++ .../classes/docs/matuszek/06-hammurabi.html | 299 ++++++++++++++++++ .../target/classes/docs/matuszek/README..md | 6 + .../target/classes/target/classes/pom.xml | 25 ++ .../target/classes/target/classes/.gitignore | 23 ++ .../target/classes/target/classes/LICENSE | 21 ++ .../target/classes/target/classes/README.md | 228 +++++++++++++ .../classes/docs/matuszek/06-hammurabi.html | 299 ++++++++++++++++++ .../target/classes/docs/matuszek/README..md | 6 + .../target/classes/target/classes/pom.xml | 25 ++ .../target/classes/target/classes/.gitignore | 23 ++ .../target/classes/target/classes/LICENSE | 21 ++ .../target/classes/target/classes/README.md | 228 +++++++++++++ .../classes/docs/matuszek/06-hammurabi.html | 299 ++++++++++++++++++ .../target/classes/docs/matuszek/README..md | 6 + .../target/classes/target/classes/pom.xml | 25 ++ .../target/classes/target/classes/.gitignore | 23 ++ .../target/classes/target/classes/LICENSE | 21 ++ .../target/classes/target/classes/README.md | 228 +++++++++++++ .../classes/docs/matuszek/06-hammurabi.html | 299 ++++++++++++++++++ .../target/classes/docs/matuszek/README..md | 6 + .../target/classes/target/classes/pom.xml | 25 ++ .../target/classes/target/classes/.gitignore | 23 ++ .../target/classes/target/classes/LICENSE | 21 ++ .../target/classes/target/classes/README.md | 228 +++++++++++++ .../classes/docs/matuszek/06-hammurabi.html | 299 ++++++++++++++++++ .../target/classes/docs/matuszek/README..md | 6 + .../target/classes/target/classes/pom.xml | 25 ++ .../target/classes/target/classes/.gitignore | 23 ++ .../target/classes/target/classes/LICENSE | 21 ++ .../target/classes/target/classes/README.md | 228 +++++++++++++ .../classes/docs/matuszek/06-hammurabi.html | 299 ++++++++++++++++++ .../target/classes/docs/matuszek/README..md | 6 + .../target/classes/target/classes/pom.xml | 25 ++ .../target/classes/target/classes/.gitignore | 23 ++ .../target/classes/target/classes/LICENSE | 21 ++ .../target/classes/target/classes/README.md | 228 +++++++++++++ .../classes/docs/matuszek/06-hammurabi.html | 299 ++++++++++++++++++ .../target/classes/docs/matuszek/README..md | 6 + .../target/classes/target/classes/pom.xml | 25 ++ 118 files changed, 11012 insertions(+), 24 deletions(-) create mode 100644 target/classes/target/classes/target/classes/.idea/.gitignore create mode 100644 target/classes/target/classes/target/classes/.idea/compiler.xml create mode 100644 target/classes/target/classes/target/classes/.idea/jarRepositories.xml create mode 100644 target/classes/target/classes/target/classes/.idea/libraries/Maven__junit_junit_4_13_2.xml create mode 100644 target/classes/target/classes/target/classes/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml create mode 100644 target/classes/target/classes/target/classes/.idea/misc.xml create mode 100644 target/classes/target/classes/target/classes/.idea/modules.xml create mode 100644 target/classes/target/classes/target/classes/.idea/vcs.xml create mode 100644 target/classes/target/classes/target/classes/Hamurabi.iml create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml diff --git a/docs/matuszek/Hammurabi.java b/docs/matuszek/Hammurabi.java index 2155b51..4a7aa1c 100644 --- a/docs/matuszek/Hammurabi.java +++ b/docs/matuszek/Hammurabi.java @@ -6,10 +6,10 @@ public class Hammurabi { // must save in a file named Hammurabi.java Random rand = new Random(); // this is an instance variable Scanner scanner = new Scanner(System.in); - int people; - int bushelsOfGrain; - int acres; - int landValue; + public int people; + public int bushelsOfGrain; + public int acres; + public int landValue; public Hammurabi(int peo,int bus, int acr, int lan){ this.people=peo; @@ -23,14 +23,17 @@ public Hammurabi(int peo,int bus, int acr, int lan){ //* Land value is 19 bushels/acre public static void main(String[] args) { // required in every Java program - new Hammurabi(100,2800,1000,19).playGame(); + // + Hammurabi h = new Hammurabi(100,2800,1000,19); } - void playGame() { // declare local variables here: grain, population, etc. // statements go after the declations + int people=100; + int bushelsOfGrain =2800; + int acres=1000; + int landValue=19; } - //other methods go here int askHowManyAcresToBuy(int price, int bushels){ System.out.println("How many acres do you wish to buy?"); @@ -42,55 +45,97 @@ int askHowManyAcresToBuy(int price, int bushels){ } return in; } - - //Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. + //Asks the player how many acres of land to buy, and returns that number. + // You must have enough grain to pay for your purchase. int askHowManyAcresToSell(int acresOwned){ - return 1; - } + System.out.println("How many acres do you wish to sell?"); + int in=scanner.nextInt(); + while(in>acresOwned){ + System.out.println("Hammurabi: Thank again. You have only "+ acresOwned+" of grain. "); + System.out.println("Re-enter the numbers of acres you wish to sell: "); + in=scanner.nextInt(); + } + return in; + } //Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. //Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. int askHowMuchGrainToFeedPeople(int bushels){ - return 1; + + System.out.println("How many bushels do you wish to feed your people?"); + int in=scanner.nextInt(); + while(in>bushels){ + System.out.println("Hammurabi: Think again. You have only "+ bushelsOfGrain+" of grain. "); + System.out.println("Re-enter the numbers of acres you wish to sell: "); + in=scanner.nextInt(); + } + return in; } - //Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You can feed them more than they need to survive. + //Ask the player how much grain to feed people, + // and returns that number. You can't feed them more grain than you have. + // You can feed them more than they need to survive. int askHowManyAcresToPlant(int acresOwned, int population, int bushels){ - return 1; + System.out.println("How many acres do you wish to plant with seed?"); + int in=scanner.nextInt(); + while(in>acresOwned || in>(bushels-population*20)){ + System.out.println("Hammurabi: Think again. You have only "+ bushelsOfGrain+" of grain. "); + System.out.println("Re-enter the numbers of acres you wish to plant with seed: "); + in=scanner.nextInt(); + } + bushels-=in; + return in; } - //Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. + //Ask the player how many acres to plant with grain, and returns that number. + // You must have enough acres, enough grain, and enough people to do the planting. + // Any grain left over goes into storage for next year. int plagueDeaths(int population){ - return 1; + + return population/2; } - // Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). + // Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. + // Return the number of plague deaths (possibly zero). int starvationDeaths(int population, int bushelsFedToPeople){ - return 1; + int numberOfStar=bushelsFedToPeople/20-population; + if(numberOfStar>=0) { + return 0; + }else return Math.abs(numberOfStar); } - - // Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). + // Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, + // but the grain is still gone. You don't get any benefit from having happy subjects. + // Return the number of deaths from starvation (possibly zero). boolean uprising(int population, int howManyPeopleStarved){ + return true; } // Return true if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) int immigrants(int population, int acresOwned, int grainInStorage){ - return 1; + if(starvationDeaths(population,grainInStorage)>0){ + return 0; + }else{ + return (20*acresOwned+grainInStorage)/(100*population)+1; + } } - //Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: (20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1. + //Nobody will come to the city if people are starving (so don't call this method). + // If everyone is well fed, compute how many people come to the city as: + // (20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1. int harvest(int acres, int bushelsUsedAsSeed){ - return 1; + int ran = rand.nextInt(6)+1; + return 1; } - //Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. + //Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. + // (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. int grainEatenByRats(int bushels){ return 1; diff --git a/target/classes/target/classes/target/classes/.idea/.gitignore b/target/classes/target/classes/target/classes/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/target/classes/target/classes/target/classes/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/target/classes/target/classes/target/classes/.idea/compiler.xml b/target/classes/target/classes/target/classes/.idea/compiler.xml new file mode 100644 index 0000000..639314b --- /dev/null +++ b/target/classes/target/classes/target/classes/.idea/compiler.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/.idea/jarRepositories.xml b/target/classes/target/classes/target/classes/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/target/classes/target/classes/target/classes/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/.idea/libraries/Maven__junit_junit_4_13_2.xml b/target/classes/target/classes/target/classes/.idea/libraries/Maven__junit_junit_4_13_2.xml new file mode 100644 index 0000000..606c352 --- /dev/null +++ b/target/classes/target/classes/target/classes/.idea/libraries/Maven__junit_junit_4_13_2.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml b/target/classes/target/classes/target/classes/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml new file mode 100644 index 0000000..f58bbc1 --- /dev/null +++ b/target/classes/target/classes/target/classes/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/.idea/misc.xml b/target/classes/target/classes/target/classes/.idea/misc.xml new file mode 100644 index 0000000..213cea6 --- /dev/null +++ b/target/classes/target/classes/target/classes/.idea/misc.xml @@ -0,0 +1,13 @@ + + + + + + + + + \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/.idea/modules.xml b/target/classes/target/classes/target/classes/.idea/modules.xml new file mode 100644 index 0000000..16ae36c --- /dev/null +++ b/target/classes/target/classes/target/classes/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/.idea/vcs.xml b/target/classes/target/classes/target/classes/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/target/classes/target/classes/target/classes/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/Hamurabi.iml b/target/classes/target/classes/target/classes/Hamurabi.iml new file mode 100644 index 0000000..903044c --- /dev/null +++ b/target/classes/target/classes/target/classes/Hamurabi.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore new file mode 100644 index 0000000..a1c2a23 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore @@ -0,0 +1,23 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE new file mode 100644 index 0000000..22474e4 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Zip Code Wilmington Core + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md new file mode 100644 index 0000000..e4672c9 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md @@ -0,0 +1,228 @@ +# hamurabi +an ancient (in more ways than one) computer game (text) + +## General idea of the lab + +*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. + +Here are the standard instructions for the game: + +> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** +> +> * **Each person needs at least 20 bushels of grain per year to survive** +> * **Each person can farm at most 10 acres of land** +> * **It takes 2 bushels of grain to farm an acre of land** +> * **The market price for land fluctuates yearly** +> +> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** + +### Maven + +There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. + +### Details + +Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): + +```java +package hammurabi; // package declaration +import java.util.Random; // imports go here +import java.util.Scanner; + +public class Hammurabi { // must save in a file named Hammurabi.java + Random rand = new Random(); // this is an instance variable + Scanner scanner = new Scanner(System.in); + + public static void main(String\[\] args) { // required in every Java program + new Hammurabi().playGame(); + } + + void playGame() { + // declare local variables here: grain, population, etc. + // statements go after the declations + } + + //other methods go here +} +``` + +### Playing the game + +Here is what you start the game with: + +* 100 people +* 2800 bushels of grain in storage +* 1000 acres of land +* Land value is 19 bushels/acre + + +Each year, print out a summary similar to the following: + + O great Hammurabi! + You are in year 1 of your ten year rule. + In the previous year 0 people starved to death. + In the previous year 5 people entered the kingdom. + The population is now 100. + We harvested 3000 bushels at 3 bushels per acre. + Rats destroyed 200 bushels, leaving 2800 bushels in storage. + The city owns 1000 acres of land. + Land is currently worth 19 bushels per acre. + +The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. + +Here's what your `playGame` method needs to do each year, for up to 10 years: + +> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: +> +> `int askHowManyAcresToBuy(int price, int bushels)` +> +> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. +> +> ` +> int askHowManyAcresToSell(int acresOwned)` +> +> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. +> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. +> +> ` +> int askHowMuchGrainToFeedPeople(int bushels)` +> +> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. +> +> ` +> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` +> +> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. +> +> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) +> +> Then the method needs to determine: +> +> 1. If there is a plague, and how many people die from it. +> 2. How many people starved. +> 3. How many people came to the city. +> 4. How good the harvest is. +> 5. If you have a problem with rats, and how much grain they eat. +> 6. How much land costs (for deciding what to do next). +> +> These can all be local variables of your `playGame` method. +> +> Use the following methods, **in this order,** to make the necessary calculations: +> +> `int plagueDeaths(int population)` +> +> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). +> +> ` +> int starvationDeaths(int population, int bushelsFedToPeople)` +> +> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). +> +> ` +> boolean uprising(int population, int howManyPeopleStarved)` +> +> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) +> +> ` +> int immigrants(int population, int acresOwned, int grainInStorage)` +> +> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. +> +> ` +> int harvest(int acres, int bushelsUsedAsSeed)` +> +> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. +> +> ` +> int grainEatenByRats(int bushels)` +> +> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). +> +> ` +> int newCostOfLand()` +> +> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) + +Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. + +When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. + +When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. + +Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. + +All the required arithmetic in this program should be **integer**. You do not need doubles. + +### Urgent! + +> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. + +### Things you need to know: + +#### Random numbers + +To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: + +> `static Random rand = new Random();` + +To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as + +> `myNewNumber = rand.nextInt(5); +> if (rand.nextInt(100) < 15) { ... }` + +To do something that happens `p` percent of the time, use + +> `if (rand.nextInt(100) < p) { _...do something..._ }` + +#### Getting input + +To get a number from the player, add this method to your program: + +```java + /** + * Prints the given message (which should ask the user for some integral + * quantity), and returns the number entered by the user. If the user's + * response isn't an integer, the question is repeated until the user + * does give a integer response. + * + * @param message The request to present to the user. + * @return The user's numeric response. + */ + int getNumber(String message) { + while (true) { + System.out.print(message); + try { + return scanner.nextInt(); + } + catch (InputMismatchException e) { + System.out.println("\"" + scanner.next() + "\" isn't a number!"); + } + } + } +``` + +Here is an example of how you can use this method: + +> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` + +### Structure of the solution + +* Project name: `Hammurabi` +* Package name: `hammurabi` +* Class names and method signatures: + * `class Hammurabi` + * `public static void main(String[] args)` + * Numerous other methods, as described above. + +The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. + +### Yo! Test it! + +You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! + +But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. + +### Credits + +Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html new file mode 100644 index 0000000..78bbf24 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html @@ -0,0 +1,299 @@ + + + + + + + CIT591 Hammurabi + + + + + +

CIT 591 Assignment 3: + Hammurabi
+ Fall 2010, David Matuszek

+ +

Purpose of this assignment

+ +
    +
  • To get you started using Java.
  • +
+ +

General idea of the assignment

+ +

Hammurabi is a very old computer game. Your job is to bring it into the + 21st century by writing it in Java.

+ +

Here are the standard instructions for the game:

+ +
+

Congratulations, you are the newest ruler of + ancient Samaria, elected for a ten year term of office. Your duties are to + dispense food, direct farming, and buy and sell land as needed to support + your people. Watch out for rat infestiations and the plague! Grain is the + general currency, measured in bushels. The following will help you in your + decisions:

+ +
    +
  • Each person needs at least 20 bushels of + grain per year to survive
  • + +
  • Each person can farm at most 10 acres of + land
  • + +
  • It takes 2 bushels of grain to farm an acre + of land
  • + +
  • The market price for land fluctuates + yearly
  • +
+ +

Rule wisely and you will be showered with + appreciation at the end of your term. Rule poorly and you will be kicked + out of office!

+
+ +

Details

+ +

Define a single class named Hammurabi. Use the following skeleton (but leave out the // comments):

+
package hammurabi;               // package declaration
+
+import java.util.Random;         // imports go here
+import java.util.Scanner;
+
+/**
+ * The Hammurabi game.
+ * @author Your name goes here
+ * @author Your partner's name goes here
+ */
+public class Hammurabi {         // must save in a file named Hammurabi.java
+    Random rand = new Random();  // this is an instance variable
+    Scanner scanner = new Scanner(System.in);
+
+    public static void main(String[] args) { // required in every Java program
+        new Hammurabi().playGame();
+    }
+
+    void playGame() {
+        // declare local variables here: grain, population, etc.
+        // statements go after the declations
+    }
+
+    //other methods go here
+}
+

Playing the game

+

Here is what you start the game with: +

    +
  • 100 people
  • +
  • 2800 bushels of grain in storage
  • +
  • 1000 acres of land
  • +
  • Land value is 19 bushels/acre

    +
  • +
+

Each year, print out a summary similar to the following:

+
+O great Hammurabi!
+You are in year 1 of your ten year rule.
+In the previous year 0 people starved to death.
+In the previous year 5 people entered the kingdom.
+The population is now 100.
+We harvested 3000 bushels at 3 bushels per acre.
+Rats destroyed 200 bushels, leaving 2800 bushels in storage.
+The city owns 1000 acres of land.
+Land is currently worth 19 bushels per acre.
+
+ +

The above summary represents the initial state, at the beginning of + the first year--that is, when you first take office, and before you do any of + the computations below). So, for example, the previous year (under a + different ruler) must have started with 95 people; none starved, and 5 + entered the kingdom, so as you enter office you rule 100 people.

+ +

Here's what your playGame method needs to do each year, for up to 10 years:

+ +
+

Ask the player the following questions. These questions should be asked in this order. Do not give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below:

+
+
int askHowManyAcresToBuy(int price, int bushels)
+
Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase.
+

+ int askHowManyAcresToSell(int acresOwned)
+
Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have.
+ Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn.
+

+ int askHowMuchGrainToFeedPeople(int bushels)
+
Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You can feed them more than they need to survive.
+

+ int askHowManyAcresToPlant(int acresOwned, int population, int bushels)
+
Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year.
+
+

For each + question, do "sanity checking"; that is, test whether the answer is + possible (you have enough grain, you have enough people to do the planting + etc.), and keep asking until you get a possible value. (For example, + O Great Hammurabi, surely you jest! We have only 3415 bushels left!)

+ +

Then the method needs to determine:

+ +
    +
  1. If there is a plague, and how many people die from it.
  2. +
  3. How many people starved.
  4. +
  5. How many people came to the city.
  6. +
  7. How good the harvest is.
  8. +
  9. If you have a problem with rats, and how much grain they eat.
  10. +
  11. How much land costs (for deciding what to do next).
  12. +
+

These can all be local variables of your playGame method.

+

Use the following methods, in this order, to make the necessary calculations:

+
+
int plagueDeaths(int population)
+
Each year, there is a 15% chance of a horrible plague. When this + happens, half your people die. Return the number of plague deaths (possibly zero).
+

+ int starvationDeaths(int population, int bushelsFedToPeople)
+
Each person needs 20 bushels of grain to survive. If you feed them + more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero).
+

+ boolean uprising(int population, int howManyPeopleStarved)
+
Return true if more than + 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.)
+

+ int immigrants(int population, int acresOwned, int grainInStorage)
+
Nobody will come to the city if people are starving (so don't call this method). If everyone is + well fed, compute how many people come to the city as: (20 * number of acres you have + amount of grain you have in + storage) / (100 * population) + 1.
+

+ int harvest(int acres, int bushelsUsedAsSeed)
+
Choose a random integer between 1 and 6, inclusive. Each acre that was planted + with seed will yield this many bushels of grain. (Example: if you planted + 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested.
+

+ int grainEatenByRats(int bushels)
+
There is a 40% chance that you will have a rat infestation. When this + happens, rats will eat somewhere between 10% and 30% of your + grain. Return the amount of grain eaten by rats (possibly zero).
+

+ int newCostOfLand()
+
The price of land is random, and ranges from 17 to 23 bushels per + acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell + land.)
+
+
+

Do these computations, in this order, for each of ten years. Each + computation should be done in a separate method, and none of these methods + should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it.

+ +

When the computations are finished, call a method printSummary to print the + summary for the year. This method will take several parameters.

+ + +

When the game ends , use a method finalSummary to print out a final summary, and to tell the + player how good a job he/she did. I'll leave the details up to you, but the + usual evaluation is based on how many people starved, and how many acres per + person you end up with.

+

Your playGame method will be quite long, but very straightforward; it does very little but call other methods.

+

All the required arithmetic in this program should be integer. You + do not need doubles.

+ +

I suggest that you first get the simplest possible version of the program + running and tested out (that is, leave out things like rats, plagues, and + immigration), then add these things one at a time to a working + program, testing as you go.

+ +

Things you need to know:

+ +

Random numbers

+ +

To get a random number generator, you first need to import + java.util.Random (or java.util.*). Then, you can + create a random number generator with a statement such as:

+ +
+

static Random rand = new Random();

+
+ +

To get a new random number in the range 0..n-1, where + n is an int, call rand.nextInt(n). + To get a new random number in the range min..max, use + the expression rand.nextInt(max - min + 1) + min. You + can use the rand method in statements such as

+ +
+

myNewNumber = rand.nextInt(5);
+ if (rand.nextInt(100) < 15) { ... }

+
+ +

To do something that happens p percent of the time, use

+ +
+

if (rand.nextInt(100) < p) { ...do something... + }

+
+ +

Getting input

+

To get a number from the player, add this method to your program:

+
+/**
+ * Prints the given message (which should ask the user for some integral
+ * quantity), and returns the number entered by the user. If the user's
+ * response isn't an integer, the question is repeated until the user
+ * does give a integer response.
+ * 
+ * @param message The request to present to the user.
+ * @return The user's numeric response.
+ */
+ int getNumber(String message) {
+    while (true) {
+        System.out.print(message);
+        try {
+            return scanner.nextInt();
+        }
+        catch (InputMismatchException e) {
+            System.out.println("\"" + scanner.next() + "\" isn't a number!");
+        }
+    }
+}
+
+ +

Here is an example of how you can use this method:

+ +
+

sell = getNumber("O great Hammurabi, how many acres shall you sell?");

+
+ +

Structure of the assignment:

+ +
    +
  • Project name: Hammurabi
  • + +
  • Package name: hammurabi
  • + +
  • Class names and method signatures: + +
      +
    • + class Hammurabi + +
        +
      • public static void main(String[] args)
      • + +
      • Numerous other methods, as described above.
      • +
      +
    • +
    +
  • + +
+ +

The above are requirements. The methods that do calculations, not input/output, will be tested by my test methods, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument names are irrelevant). You may have additional methods if you wish.

+ +

Due date:

+ +

Thursday, October 21, before midnight. Turn in your zipped assignment via + Blackboard. Email submissions will incur the wrath of Hammurabi (and won't be graded).

+ + + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md new file mode 100644 index 0000000..796d85c --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md @@ -0,0 +1,6 @@ +# Notes + +from the original Dave Matuszek course of 2010. + +https://www.cis.upenn.edu/~matuszek/cit591-2010/Assignments/06-hammurabi.html + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml new file mode 100644 index 0000000..d789654 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + + io.zipcoder + MicroLabs-Loops + 1.0-SNAPSHOT + + + + + junit + junit + 4.13.2 + + + + + + 1.8 + 1.8 + + \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore new file mode 100644 index 0000000..a1c2a23 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore @@ -0,0 +1,23 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE new file mode 100644 index 0000000..22474e4 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Zip Code Wilmington Core + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md new file mode 100644 index 0000000..e4672c9 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md @@ -0,0 +1,228 @@ +# hamurabi +an ancient (in more ways than one) computer game (text) + +## General idea of the lab + +*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. + +Here are the standard instructions for the game: + +> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** +> +> * **Each person needs at least 20 bushels of grain per year to survive** +> * **Each person can farm at most 10 acres of land** +> * **It takes 2 bushels of grain to farm an acre of land** +> * **The market price for land fluctuates yearly** +> +> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** + +### Maven + +There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. + +### Details + +Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): + +```java +package hammurabi; // package declaration +import java.util.Random; // imports go here +import java.util.Scanner; + +public class Hammurabi { // must save in a file named Hammurabi.java + Random rand = new Random(); // this is an instance variable + Scanner scanner = new Scanner(System.in); + + public static void main(String\[\] args) { // required in every Java program + new Hammurabi().playGame(); + } + + void playGame() { + // declare local variables here: grain, population, etc. + // statements go after the declations + } + + //other methods go here +} +``` + +### Playing the game + +Here is what you start the game with: + +* 100 people +* 2800 bushels of grain in storage +* 1000 acres of land +* Land value is 19 bushels/acre + + +Each year, print out a summary similar to the following: + + O great Hammurabi! + You are in year 1 of your ten year rule. + In the previous year 0 people starved to death. + In the previous year 5 people entered the kingdom. + The population is now 100. + We harvested 3000 bushels at 3 bushels per acre. + Rats destroyed 200 bushels, leaving 2800 bushels in storage. + The city owns 1000 acres of land. + Land is currently worth 19 bushels per acre. + +The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. + +Here's what your `playGame` method needs to do each year, for up to 10 years: + +> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: +> +> `int askHowManyAcresToBuy(int price, int bushels)` +> +> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. +> +> ` +> int askHowManyAcresToSell(int acresOwned)` +> +> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. +> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. +> +> ` +> int askHowMuchGrainToFeedPeople(int bushels)` +> +> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. +> +> ` +> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` +> +> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. +> +> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) +> +> Then the method needs to determine: +> +> 1. If there is a plague, and how many people die from it. +> 2. How many people starved. +> 3. How many people came to the city. +> 4. How good the harvest is. +> 5. If you have a problem with rats, and how much grain they eat. +> 6. How much land costs (for deciding what to do next). +> +> These can all be local variables of your `playGame` method. +> +> Use the following methods, **in this order,** to make the necessary calculations: +> +> `int plagueDeaths(int population)` +> +> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). +> +> ` +> int starvationDeaths(int population, int bushelsFedToPeople)` +> +> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). +> +> ` +> boolean uprising(int population, int howManyPeopleStarved)` +> +> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) +> +> ` +> int immigrants(int population, int acresOwned, int grainInStorage)` +> +> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. +> +> ` +> int harvest(int acres, int bushelsUsedAsSeed)` +> +> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. +> +> ` +> int grainEatenByRats(int bushels)` +> +> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). +> +> ` +> int newCostOfLand()` +> +> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) + +Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. + +When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. + +When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. + +Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. + +All the required arithmetic in this program should be **integer**. You do not need doubles. + +### Urgent! + +> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. + +### Things you need to know: + +#### Random numbers + +To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: + +> `static Random rand = new Random();` + +To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as + +> `myNewNumber = rand.nextInt(5); +> if (rand.nextInt(100) < 15) { ... }` + +To do something that happens `p` percent of the time, use + +> `if (rand.nextInt(100) < p) { _...do something..._ }` + +#### Getting input + +To get a number from the player, add this method to your program: + +```java + /** + * Prints the given message (which should ask the user for some integral + * quantity), and returns the number entered by the user. If the user's + * response isn't an integer, the question is repeated until the user + * does give a integer response. + * + * @param message The request to present to the user. + * @return The user's numeric response. + */ + int getNumber(String message) { + while (true) { + System.out.print(message); + try { + return scanner.nextInt(); + } + catch (InputMismatchException e) { + System.out.println("\"" + scanner.next() + "\" isn't a number!"); + } + } + } +``` + +Here is an example of how you can use this method: + +> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` + +### Structure of the solution + +* Project name: `Hammurabi` +* Package name: `hammurabi` +* Class names and method signatures: + * `class Hammurabi` + * `public static void main(String[] args)` + * Numerous other methods, as described above. + +The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. + +### Yo! Test it! + +You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! + +But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. + +### Credits + +Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html new file mode 100644 index 0000000..78bbf24 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html @@ -0,0 +1,299 @@ + + + + + + + CIT591 Hammurabi + + + + + +

CIT 591 Assignment 3: + Hammurabi
+ Fall 2010, David Matuszek

+ +

Purpose of this assignment

+ +
    +
  • To get you started using Java.
  • +
+ +

General idea of the assignment

+ +

Hammurabi is a very old computer game. Your job is to bring it into the + 21st century by writing it in Java.

+ +

Here are the standard instructions for the game:

+ +
+

Congratulations, you are the newest ruler of + ancient Samaria, elected for a ten year term of office. Your duties are to + dispense food, direct farming, and buy and sell land as needed to support + your people. Watch out for rat infestiations and the plague! Grain is the + general currency, measured in bushels. The following will help you in your + decisions:

+ +
    +
  • Each person needs at least 20 bushels of + grain per year to survive
  • + +
  • Each person can farm at most 10 acres of + land
  • + +
  • It takes 2 bushels of grain to farm an acre + of land
  • + +
  • The market price for land fluctuates + yearly
  • +
+ +

Rule wisely and you will be showered with + appreciation at the end of your term. Rule poorly and you will be kicked + out of office!

+
+ +

Details

+ +

Define a single class named Hammurabi. Use the following skeleton (but leave out the // comments):

+
package hammurabi;               // package declaration
+
+import java.util.Random;         // imports go here
+import java.util.Scanner;
+
+/**
+ * The Hammurabi game.
+ * @author Your name goes here
+ * @author Your partner's name goes here
+ */
+public class Hammurabi {         // must save in a file named Hammurabi.java
+    Random rand = new Random();  // this is an instance variable
+    Scanner scanner = new Scanner(System.in);
+
+    public static void main(String[] args) { // required in every Java program
+        new Hammurabi().playGame();
+    }
+
+    void playGame() {
+        // declare local variables here: grain, population, etc.
+        // statements go after the declations
+    }
+
+    //other methods go here
+}
+

Playing the game

+

Here is what you start the game with: +

    +
  • 100 people
  • +
  • 2800 bushels of grain in storage
  • +
  • 1000 acres of land
  • +
  • Land value is 19 bushels/acre

    +
  • +
+

Each year, print out a summary similar to the following:

+
+O great Hammurabi!
+You are in year 1 of your ten year rule.
+In the previous year 0 people starved to death.
+In the previous year 5 people entered the kingdom.
+The population is now 100.
+We harvested 3000 bushels at 3 bushels per acre.
+Rats destroyed 200 bushels, leaving 2800 bushels in storage.
+The city owns 1000 acres of land.
+Land is currently worth 19 bushels per acre.
+
+ +

The above summary represents the initial state, at the beginning of + the first year--that is, when you first take office, and before you do any of + the computations below). So, for example, the previous year (under a + different ruler) must have started with 95 people; none starved, and 5 + entered the kingdom, so as you enter office you rule 100 people.

+ +

Here's what your playGame method needs to do each year, for up to 10 years:

+ +
+

Ask the player the following questions. These questions should be asked in this order. Do not give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below:

+
+
int askHowManyAcresToBuy(int price, int bushels)
+
Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase.
+

+ int askHowManyAcresToSell(int acresOwned)
+
Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have.
+ Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn.
+

+ int askHowMuchGrainToFeedPeople(int bushels)
+
Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You can feed them more than they need to survive.
+

+ int askHowManyAcresToPlant(int acresOwned, int population, int bushels)
+
Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year.
+
+

For each + question, do "sanity checking"; that is, test whether the answer is + possible (you have enough grain, you have enough people to do the planting + etc.), and keep asking until you get a possible value. (For example, + O Great Hammurabi, surely you jest! We have only 3415 bushels left!)

+ +

Then the method needs to determine:

+ +
    +
  1. If there is a plague, and how many people die from it.
  2. +
  3. How many people starved.
  4. +
  5. How many people came to the city.
  6. +
  7. How good the harvest is.
  8. +
  9. If you have a problem with rats, and how much grain they eat.
  10. +
  11. How much land costs (for deciding what to do next).
  12. +
+

These can all be local variables of your playGame method.

+

Use the following methods, in this order, to make the necessary calculations:

+
+
int plagueDeaths(int population)
+
Each year, there is a 15% chance of a horrible plague. When this + happens, half your people die. Return the number of plague deaths (possibly zero).
+

+ int starvationDeaths(int population, int bushelsFedToPeople)
+
Each person needs 20 bushels of grain to survive. If you feed them + more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero).
+

+ boolean uprising(int population, int howManyPeopleStarved)
+
Return true if more than + 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.)
+

+ int immigrants(int population, int acresOwned, int grainInStorage)
+
Nobody will come to the city if people are starving (so don't call this method). If everyone is + well fed, compute how many people come to the city as: (20 * number of acres you have + amount of grain you have in + storage) / (100 * population) + 1.
+

+ int harvest(int acres, int bushelsUsedAsSeed)
+
Choose a random integer between 1 and 6, inclusive. Each acre that was planted + with seed will yield this many bushels of grain. (Example: if you planted + 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested.
+

+ int grainEatenByRats(int bushels)
+
There is a 40% chance that you will have a rat infestation. When this + happens, rats will eat somewhere between 10% and 30% of your + grain. Return the amount of grain eaten by rats (possibly zero).
+

+ int newCostOfLand()
+
The price of land is random, and ranges from 17 to 23 bushels per + acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell + land.)
+
+
+

Do these computations, in this order, for each of ten years. Each + computation should be done in a separate method, and none of these methods + should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it.

+ +

When the computations are finished, call a method printSummary to print the + summary for the year. This method will take several parameters.

+ + +

When the game ends , use a method finalSummary to print out a final summary, and to tell the + player how good a job he/she did. I'll leave the details up to you, but the + usual evaluation is based on how many people starved, and how many acres per + person you end up with.

+

Your playGame method will be quite long, but very straightforward; it does very little but call other methods.

+

All the required arithmetic in this program should be integer. You + do not need doubles.

+ +

I suggest that you first get the simplest possible version of the program + running and tested out (that is, leave out things like rats, plagues, and + immigration), then add these things one at a time to a working + program, testing as you go.

+ +

Things you need to know:

+ +

Random numbers

+ +

To get a random number generator, you first need to import + java.util.Random (or java.util.*). Then, you can + create a random number generator with a statement such as:

+ +
+

static Random rand = new Random();

+
+ +

To get a new random number in the range 0..n-1, where + n is an int, call rand.nextInt(n). + To get a new random number in the range min..max, use + the expression rand.nextInt(max - min + 1) + min. You + can use the rand method in statements such as

+ +
+

myNewNumber = rand.nextInt(5);
+ if (rand.nextInt(100) < 15) { ... }

+
+ +

To do something that happens p percent of the time, use

+ +
+

if (rand.nextInt(100) < p) { ...do something... + }

+
+ +

Getting input

+

To get a number from the player, add this method to your program:

+
+/**
+ * Prints the given message (which should ask the user for some integral
+ * quantity), and returns the number entered by the user. If the user's
+ * response isn't an integer, the question is repeated until the user
+ * does give a integer response.
+ * 
+ * @param message The request to present to the user.
+ * @return The user's numeric response.
+ */
+ int getNumber(String message) {
+    while (true) {
+        System.out.print(message);
+        try {
+            return scanner.nextInt();
+        }
+        catch (InputMismatchException e) {
+            System.out.println("\"" + scanner.next() + "\" isn't a number!");
+        }
+    }
+}
+
+ +

Here is an example of how you can use this method:

+ +
+

sell = getNumber("O great Hammurabi, how many acres shall you sell?");

+
+ +

Structure of the assignment:

+ +
    +
  • Project name: Hammurabi
  • + +
  • Package name: hammurabi
  • + +
  • Class names and method signatures: + +
      +
    • + class Hammurabi + +
        +
      • public static void main(String[] args)
      • + +
      • Numerous other methods, as described above.
      • +
      +
    • +
    +
  • + +
+ +

The above are requirements. The methods that do calculations, not input/output, will be tested by my test methods, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument names are irrelevant). You may have additional methods if you wish.

+ +

Due date:

+ +

Thursday, October 21, before midnight. Turn in your zipped assignment via + Blackboard. Email submissions will incur the wrath of Hammurabi (and won't be graded).

+ + + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md new file mode 100644 index 0000000..796d85c --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md @@ -0,0 +1,6 @@ +# Notes + +from the original Dave Matuszek course of 2010. + +https://www.cis.upenn.edu/~matuszek/cit591-2010/Assignments/06-hammurabi.html + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml new file mode 100644 index 0000000..d789654 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + + io.zipcoder + MicroLabs-Loops + 1.0-SNAPSHOT + + + + + junit + junit + 4.13.2 + + + + + + 1.8 + 1.8 + + \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore new file mode 100644 index 0000000..a1c2a23 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore @@ -0,0 +1,23 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE new file mode 100644 index 0000000..22474e4 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Zip Code Wilmington Core + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md new file mode 100644 index 0000000..e4672c9 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md @@ -0,0 +1,228 @@ +# hamurabi +an ancient (in more ways than one) computer game (text) + +## General idea of the lab + +*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. + +Here are the standard instructions for the game: + +> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** +> +> * **Each person needs at least 20 bushels of grain per year to survive** +> * **Each person can farm at most 10 acres of land** +> * **It takes 2 bushels of grain to farm an acre of land** +> * **The market price for land fluctuates yearly** +> +> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** + +### Maven + +There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. + +### Details + +Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): + +```java +package hammurabi; // package declaration +import java.util.Random; // imports go here +import java.util.Scanner; + +public class Hammurabi { // must save in a file named Hammurabi.java + Random rand = new Random(); // this is an instance variable + Scanner scanner = new Scanner(System.in); + + public static void main(String\[\] args) { // required in every Java program + new Hammurabi().playGame(); + } + + void playGame() { + // declare local variables here: grain, population, etc. + // statements go after the declations + } + + //other methods go here +} +``` + +### Playing the game + +Here is what you start the game with: + +* 100 people +* 2800 bushels of grain in storage +* 1000 acres of land +* Land value is 19 bushels/acre + + +Each year, print out a summary similar to the following: + + O great Hammurabi! + You are in year 1 of your ten year rule. + In the previous year 0 people starved to death. + In the previous year 5 people entered the kingdom. + The population is now 100. + We harvested 3000 bushels at 3 bushels per acre. + Rats destroyed 200 bushels, leaving 2800 bushels in storage. + The city owns 1000 acres of land. + Land is currently worth 19 bushels per acre. + +The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. + +Here's what your `playGame` method needs to do each year, for up to 10 years: + +> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: +> +> `int askHowManyAcresToBuy(int price, int bushels)` +> +> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. +> +> ` +> int askHowManyAcresToSell(int acresOwned)` +> +> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. +> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. +> +> ` +> int askHowMuchGrainToFeedPeople(int bushels)` +> +> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. +> +> ` +> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` +> +> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. +> +> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) +> +> Then the method needs to determine: +> +> 1. If there is a plague, and how many people die from it. +> 2. How many people starved. +> 3. How many people came to the city. +> 4. How good the harvest is. +> 5. If you have a problem with rats, and how much grain they eat. +> 6. How much land costs (for deciding what to do next). +> +> These can all be local variables of your `playGame` method. +> +> Use the following methods, **in this order,** to make the necessary calculations: +> +> `int plagueDeaths(int population)` +> +> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). +> +> ` +> int starvationDeaths(int population, int bushelsFedToPeople)` +> +> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). +> +> ` +> boolean uprising(int population, int howManyPeopleStarved)` +> +> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) +> +> ` +> int immigrants(int population, int acresOwned, int grainInStorage)` +> +> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. +> +> ` +> int harvest(int acres, int bushelsUsedAsSeed)` +> +> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. +> +> ` +> int grainEatenByRats(int bushels)` +> +> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). +> +> ` +> int newCostOfLand()` +> +> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) + +Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. + +When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. + +When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. + +Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. + +All the required arithmetic in this program should be **integer**. You do not need doubles. + +### Urgent! + +> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. + +### Things you need to know: + +#### Random numbers + +To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: + +> `static Random rand = new Random();` + +To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as + +> `myNewNumber = rand.nextInt(5); +> if (rand.nextInt(100) < 15) { ... }` + +To do something that happens `p` percent of the time, use + +> `if (rand.nextInt(100) < p) { _...do something..._ }` + +#### Getting input + +To get a number from the player, add this method to your program: + +```java + /** + * Prints the given message (which should ask the user for some integral + * quantity), and returns the number entered by the user. If the user's + * response isn't an integer, the question is repeated until the user + * does give a integer response. + * + * @param message The request to present to the user. + * @return The user's numeric response. + */ + int getNumber(String message) { + while (true) { + System.out.print(message); + try { + return scanner.nextInt(); + } + catch (InputMismatchException e) { + System.out.println("\"" + scanner.next() + "\" isn't a number!"); + } + } + } +``` + +Here is an example of how you can use this method: + +> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` + +### Structure of the solution + +* Project name: `Hammurabi` +* Package name: `hammurabi` +* Class names and method signatures: + * `class Hammurabi` + * `public static void main(String[] args)` + * Numerous other methods, as described above. + +The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. + +### Yo! Test it! + +You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! + +But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. + +### Credits + +Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html new file mode 100644 index 0000000..78bbf24 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html @@ -0,0 +1,299 @@ + + + + + + + CIT591 Hammurabi + + + + + +

CIT 591 Assignment 3: + Hammurabi
+ Fall 2010, David Matuszek

+ +

Purpose of this assignment

+ +
    +
  • To get you started using Java.
  • +
+ +

General idea of the assignment

+ +

Hammurabi is a very old computer game. Your job is to bring it into the + 21st century by writing it in Java.

+ +

Here are the standard instructions for the game:

+ +
+

Congratulations, you are the newest ruler of + ancient Samaria, elected for a ten year term of office. Your duties are to + dispense food, direct farming, and buy and sell land as needed to support + your people. Watch out for rat infestiations and the plague! Grain is the + general currency, measured in bushels. The following will help you in your + decisions:

+ +
    +
  • Each person needs at least 20 bushels of + grain per year to survive
  • + +
  • Each person can farm at most 10 acres of + land
  • + +
  • It takes 2 bushels of grain to farm an acre + of land
  • + +
  • The market price for land fluctuates + yearly
  • +
+ +

Rule wisely and you will be showered with + appreciation at the end of your term. Rule poorly and you will be kicked + out of office!

+
+ +

Details

+ +

Define a single class named Hammurabi. Use the following skeleton (but leave out the // comments):

+
package hammurabi;               // package declaration
+
+import java.util.Random;         // imports go here
+import java.util.Scanner;
+
+/**
+ * The Hammurabi game.
+ * @author Your name goes here
+ * @author Your partner's name goes here
+ */
+public class Hammurabi {         // must save in a file named Hammurabi.java
+    Random rand = new Random();  // this is an instance variable
+    Scanner scanner = new Scanner(System.in);
+
+    public static void main(String[] args) { // required in every Java program
+        new Hammurabi().playGame();
+    }
+
+    void playGame() {
+        // declare local variables here: grain, population, etc.
+        // statements go after the declations
+    }
+
+    //other methods go here
+}
+

Playing the game

+

Here is what you start the game with: +

    +
  • 100 people
  • +
  • 2800 bushels of grain in storage
  • +
  • 1000 acres of land
  • +
  • Land value is 19 bushels/acre

    +
  • +
+

Each year, print out a summary similar to the following:

+
+O great Hammurabi!
+You are in year 1 of your ten year rule.
+In the previous year 0 people starved to death.
+In the previous year 5 people entered the kingdom.
+The population is now 100.
+We harvested 3000 bushels at 3 bushels per acre.
+Rats destroyed 200 bushels, leaving 2800 bushels in storage.
+The city owns 1000 acres of land.
+Land is currently worth 19 bushels per acre.
+
+ +

The above summary represents the initial state, at the beginning of + the first year--that is, when you first take office, and before you do any of + the computations below). So, for example, the previous year (under a + different ruler) must have started with 95 people; none starved, and 5 + entered the kingdom, so as you enter office you rule 100 people.

+ +

Here's what your playGame method needs to do each year, for up to 10 years:

+ +
+

Ask the player the following questions. These questions should be asked in this order. Do not give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below:

+
+
int askHowManyAcresToBuy(int price, int bushels)
+
Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase.
+

+ int askHowManyAcresToSell(int acresOwned)
+
Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have.
+ Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn.
+

+ int askHowMuchGrainToFeedPeople(int bushels)
+
Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You can feed them more than they need to survive.
+

+ int askHowManyAcresToPlant(int acresOwned, int population, int bushels)
+
Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year.
+
+

For each + question, do "sanity checking"; that is, test whether the answer is + possible (you have enough grain, you have enough people to do the planting + etc.), and keep asking until you get a possible value. (For example, + O Great Hammurabi, surely you jest! We have only 3415 bushels left!)

+ +

Then the method needs to determine:

+ +
    +
  1. If there is a plague, and how many people die from it.
  2. +
  3. How many people starved.
  4. +
  5. How many people came to the city.
  6. +
  7. How good the harvest is.
  8. +
  9. If you have a problem with rats, and how much grain they eat.
  10. +
  11. How much land costs (for deciding what to do next).
  12. +
+

These can all be local variables of your playGame method.

+

Use the following methods, in this order, to make the necessary calculations:

+
+
int plagueDeaths(int population)
+
Each year, there is a 15% chance of a horrible plague. When this + happens, half your people die. Return the number of plague deaths (possibly zero).
+

+ int starvationDeaths(int population, int bushelsFedToPeople)
+
Each person needs 20 bushels of grain to survive. If you feed them + more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero).
+

+ boolean uprising(int population, int howManyPeopleStarved)
+
Return true if more than + 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.)
+

+ int immigrants(int population, int acresOwned, int grainInStorage)
+
Nobody will come to the city if people are starving (so don't call this method). If everyone is + well fed, compute how many people come to the city as: (20 * number of acres you have + amount of grain you have in + storage) / (100 * population) + 1.
+

+ int harvest(int acres, int bushelsUsedAsSeed)
+
Choose a random integer between 1 and 6, inclusive. Each acre that was planted + with seed will yield this many bushels of grain. (Example: if you planted + 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested.
+

+ int grainEatenByRats(int bushels)
+
There is a 40% chance that you will have a rat infestation. When this + happens, rats will eat somewhere between 10% and 30% of your + grain. Return the amount of grain eaten by rats (possibly zero).
+

+ int newCostOfLand()
+
The price of land is random, and ranges from 17 to 23 bushels per + acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell + land.)
+
+
+

Do these computations, in this order, for each of ten years. Each + computation should be done in a separate method, and none of these methods + should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it.

+ +

When the computations are finished, call a method printSummary to print the + summary for the year. This method will take several parameters.

+ + +

When the game ends , use a method finalSummary to print out a final summary, and to tell the + player how good a job he/she did. I'll leave the details up to you, but the + usual evaluation is based on how many people starved, and how many acres per + person you end up with.

+

Your playGame method will be quite long, but very straightforward; it does very little but call other methods.

+

All the required arithmetic in this program should be integer. You + do not need doubles.

+ +

I suggest that you first get the simplest possible version of the program + running and tested out (that is, leave out things like rats, plagues, and + immigration), then add these things one at a time to a working + program, testing as you go.

+ +

Things you need to know:

+ +

Random numbers

+ +

To get a random number generator, you first need to import + java.util.Random (or java.util.*). Then, you can + create a random number generator with a statement such as:

+ +
+

static Random rand = new Random();

+
+ +

To get a new random number in the range 0..n-1, where + n is an int, call rand.nextInt(n). + To get a new random number in the range min..max, use + the expression rand.nextInt(max - min + 1) + min. You + can use the rand method in statements such as

+ +
+

myNewNumber = rand.nextInt(5);
+ if (rand.nextInt(100) < 15) { ... }

+
+ +

To do something that happens p percent of the time, use

+ +
+

if (rand.nextInt(100) < p) { ...do something... + }

+
+ +

Getting input

+

To get a number from the player, add this method to your program:

+
+/**
+ * Prints the given message (which should ask the user for some integral
+ * quantity), and returns the number entered by the user. If the user's
+ * response isn't an integer, the question is repeated until the user
+ * does give a integer response.
+ * 
+ * @param message The request to present to the user.
+ * @return The user's numeric response.
+ */
+ int getNumber(String message) {
+    while (true) {
+        System.out.print(message);
+        try {
+            return scanner.nextInt();
+        }
+        catch (InputMismatchException e) {
+            System.out.println("\"" + scanner.next() + "\" isn't a number!");
+        }
+    }
+}
+
+ +

Here is an example of how you can use this method:

+ +
+

sell = getNumber("O great Hammurabi, how many acres shall you sell?");

+
+ +

Structure of the assignment:

+ +
    +
  • Project name: Hammurabi
  • + +
  • Package name: hammurabi
  • + +
  • Class names and method signatures: + +
      +
    • + class Hammurabi + +
        +
      • public static void main(String[] args)
      • + +
      • Numerous other methods, as described above.
      • +
      +
    • +
    +
  • + +
+ +

The above are requirements. The methods that do calculations, not input/output, will be tested by my test methods, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument names are irrelevant). You may have additional methods if you wish.

+ +

Due date:

+ +

Thursday, October 21, before midnight. Turn in your zipped assignment via + Blackboard. Email submissions will incur the wrath of Hammurabi (and won't be graded).

+ + + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md new file mode 100644 index 0000000..796d85c --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md @@ -0,0 +1,6 @@ +# Notes + +from the original Dave Matuszek course of 2010. + +https://www.cis.upenn.edu/~matuszek/cit591-2010/Assignments/06-hammurabi.html + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml new file mode 100644 index 0000000..d789654 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + + io.zipcoder + MicroLabs-Loops + 1.0-SNAPSHOT + + + + + junit + junit + 4.13.2 + + + + + + 1.8 + 1.8 + + \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore new file mode 100644 index 0000000..a1c2a23 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore @@ -0,0 +1,23 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE new file mode 100644 index 0000000..22474e4 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Zip Code Wilmington Core + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md new file mode 100644 index 0000000..e4672c9 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md @@ -0,0 +1,228 @@ +# hamurabi +an ancient (in more ways than one) computer game (text) + +## General idea of the lab + +*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. + +Here are the standard instructions for the game: + +> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** +> +> * **Each person needs at least 20 bushels of grain per year to survive** +> * **Each person can farm at most 10 acres of land** +> * **It takes 2 bushels of grain to farm an acre of land** +> * **The market price for land fluctuates yearly** +> +> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** + +### Maven + +There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. + +### Details + +Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): + +```java +package hammurabi; // package declaration +import java.util.Random; // imports go here +import java.util.Scanner; + +public class Hammurabi { // must save in a file named Hammurabi.java + Random rand = new Random(); // this is an instance variable + Scanner scanner = new Scanner(System.in); + + public static void main(String\[\] args) { // required in every Java program + new Hammurabi().playGame(); + } + + void playGame() { + // declare local variables here: grain, population, etc. + // statements go after the declations + } + + //other methods go here +} +``` + +### Playing the game + +Here is what you start the game with: + +* 100 people +* 2800 bushels of grain in storage +* 1000 acres of land +* Land value is 19 bushels/acre + + +Each year, print out a summary similar to the following: + + O great Hammurabi! + You are in year 1 of your ten year rule. + In the previous year 0 people starved to death. + In the previous year 5 people entered the kingdom. + The population is now 100. + We harvested 3000 bushels at 3 bushels per acre. + Rats destroyed 200 bushels, leaving 2800 bushels in storage. + The city owns 1000 acres of land. + Land is currently worth 19 bushels per acre. + +The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. + +Here's what your `playGame` method needs to do each year, for up to 10 years: + +> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: +> +> `int askHowManyAcresToBuy(int price, int bushels)` +> +> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. +> +> ` +> int askHowManyAcresToSell(int acresOwned)` +> +> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. +> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. +> +> ` +> int askHowMuchGrainToFeedPeople(int bushels)` +> +> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. +> +> ` +> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` +> +> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. +> +> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) +> +> Then the method needs to determine: +> +> 1. If there is a plague, and how many people die from it. +> 2. How many people starved. +> 3. How many people came to the city. +> 4. How good the harvest is. +> 5. If you have a problem with rats, and how much grain they eat. +> 6. How much land costs (for deciding what to do next). +> +> These can all be local variables of your `playGame` method. +> +> Use the following methods, **in this order,** to make the necessary calculations: +> +> `int plagueDeaths(int population)` +> +> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). +> +> ` +> int starvationDeaths(int population, int bushelsFedToPeople)` +> +> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). +> +> ` +> boolean uprising(int population, int howManyPeopleStarved)` +> +> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) +> +> ` +> int immigrants(int population, int acresOwned, int grainInStorage)` +> +> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. +> +> ` +> int harvest(int acres, int bushelsUsedAsSeed)` +> +> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. +> +> ` +> int grainEatenByRats(int bushels)` +> +> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). +> +> ` +> int newCostOfLand()` +> +> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) + +Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. + +When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. + +When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. + +Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. + +All the required arithmetic in this program should be **integer**. You do not need doubles. + +### Urgent! + +> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. + +### Things you need to know: + +#### Random numbers + +To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: + +> `static Random rand = new Random();` + +To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as + +> `myNewNumber = rand.nextInt(5); +> if (rand.nextInt(100) < 15) { ... }` + +To do something that happens `p` percent of the time, use + +> `if (rand.nextInt(100) < p) { _...do something..._ }` + +#### Getting input + +To get a number from the player, add this method to your program: + +```java + /** + * Prints the given message (which should ask the user for some integral + * quantity), and returns the number entered by the user. If the user's + * response isn't an integer, the question is repeated until the user + * does give a integer response. + * + * @param message The request to present to the user. + * @return The user's numeric response. + */ + int getNumber(String message) { + while (true) { + System.out.print(message); + try { + return scanner.nextInt(); + } + catch (InputMismatchException e) { + System.out.println("\"" + scanner.next() + "\" isn't a number!"); + } + } + } +``` + +Here is an example of how you can use this method: + +> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` + +### Structure of the solution + +* Project name: `Hammurabi` +* Package name: `hammurabi` +* Class names and method signatures: + * `class Hammurabi` + * `public static void main(String[] args)` + * Numerous other methods, as described above. + +The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. + +### Yo! Test it! + +You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! + +But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. + +### Credits + +Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html new file mode 100644 index 0000000..78bbf24 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html @@ -0,0 +1,299 @@ + + + + + + + CIT591 Hammurabi + + + + + +

CIT 591 Assignment 3: + Hammurabi
+ Fall 2010, David Matuszek

+ +

Purpose of this assignment

+ +
    +
  • To get you started using Java.
  • +
+ +

General idea of the assignment

+ +

Hammurabi is a very old computer game. Your job is to bring it into the + 21st century by writing it in Java.

+ +

Here are the standard instructions for the game:

+ +
+

Congratulations, you are the newest ruler of + ancient Samaria, elected for a ten year term of office. Your duties are to + dispense food, direct farming, and buy and sell land as needed to support + your people. Watch out for rat infestiations and the plague! Grain is the + general currency, measured in bushels. The following will help you in your + decisions:

+ +
    +
  • Each person needs at least 20 bushels of + grain per year to survive
  • + +
  • Each person can farm at most 10 acres of + land
  • + +
  • It takes 2 bushels of grain to farm an acre + of land
  • + +
  • The market price for land fluctuates + yearly
  • +
+ +

Rule wisely and you will be showered with + appreciation at the end of your term. Rule poorly and you will be kicked + out of office!

+
+ +

Details

+ +

Define a single class named Hammurabi. Use the following skeleton (but leave out the // comments):

+
package hammurabi;               // package declaration
+
+import java.util.Random;         // imports go here
+import java.util.Scanner;
+
+/**
+ * The Hammurabi game.
+ * @author Your name goes here
+ * @author Your partner's name goes here
+ */
+public class Hammurabi {         // must save in a file named Hammurabi.java
+    Random rand = new Random();  // this is an instance variable
+    Scanner scanner = new Scanner(System.in);
+
+    public static void main(String[] args) { // required in every Java program
+        new Hammurabi().playGame();
+    }
+
+    void playGame() {
+        // declare local variables here: grain, population, etc.
+        // statements go after the declations
+    }
+
+    //other methods go here
+}
+

Playing the game

+

Here is what you start the game with: +

    +
  • 100 people
  • +
  • 2800 bushels of grain in storage
  • +
  • 1000 acres of land
  • +
  • Land value is 19 bushels/acre

    +
  • +
+

Each year, print out a summary similar to the following:

+
+O great Hammurabi!
+You are in year 1 of your ten year rule.
+In the previous year 0 people starved to death.
+In the previous year 5 people entered the kingdom.
+The population is now 100.
+We harvested 3000 bushels at 3 bushels per acre.
+Rats destroyed 200 bushels, leaving 2800 bushels in storage.
+The city owns 1000 acres of land.
+Land is currently worth 19 bushels per acre.
+
+ +

The above summary represents the initial state, at the beginning of + the first year--that is, when you first take office, and before you do any of + the computations below). So, for example, the previous year (under a + different ruler) must have started with 95 people; none starved, and 5 + entered the kingdom, so as you enter office you rule 100 people.

+ +

Here's what your playGame method needs to do each year, for up to 10 years:

+ +
+

Ask the player the following questions. These questions should be asked in this order. Do not give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below:

+
+
int askHowManyAcresToBuy(int price, int bushels)
+
Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase.
+

+ int askHowManyAcresToSell(int acresOwned)
+
Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have.
+ Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn.
+

+ int askHowMuchGrainToFeedPeople(int bushels)
+
Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You can feed them more than they need to survive.
+

+ int askHowManyAcresToPlant(int acresOwned, int population, int bushels)
+
Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year.
+
+

For each + question, do "sanity checking"; that is, test whether the answer is + possible (you have enough grain, you have enough people to do the planting + etc.), and keep asking until you get a possible value. (For example, + O Great Hammurabi, surely you jest! We have only 3415 bushels left!)

+ +

Then the method needs to determine:

+ +
    +
  1. If there is a plague, and how many people die from it.
  2. +
  3. How many people starved.
  4. +
  5. How many people came to the city.
  6. +
  7. How good the harvest is.
  8. +
  9. If you have a problem with rats, and how much grain they eat.
  10. +
  11. How much land costs (for deciding what to do next).
  12. +
+

These can all be local variables of your playGame method.

+

Use the following methods, in this order, to make the necessary calculations:

+
+
int plagueDeaths(int population)
+
Each year, there is a 15% chance of a horrible plague. When this + happens, half your people die. Return the number of plague deaths (possibly zero).
+

+ int starvationDeaths(int population, int bushelsFedToPeople)
+
Each person needs 20 bushels of grain to survive. If you feed them + more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero).
+

+ boolean uprising(int population, int howManyPeopleStarved)
+
Return true if more than + 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.)
+

+ int immigrants(int population, int acresOwned, int grainInStorage)
+
Nobody will come to the city if people are starving (so don't call this method). If everyone is + well fed, compute how many people come to the city as: (20 * number of acres you have + amount of grain you have in + storage) / (100 * population) + 1.
+

+ int harvest(int acres, int bushelsUsedAsSeed)
+
Choose a random integer between 1 and 6, inclusive. Each acre that was planted + with seed will yield this many bushels of grain. (Example: if you planted + 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested.
+

+ int grainEatenByRats(int bushels)
+
There is a 40% chance that you will have a rat infestation. When this + happens, rats will eat somewhere between 10% and 30% of your + grain. Return the amount of grain eaten by rats (possibly zero).
+

+ int newCostOfLand()
+
The price of land is random, and ranges from 17 to 23 bushels per + acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell + land.)
+
+
+

Do these computations, in this order, for each of ten years. Each + computation should be done in a separate method, and none of these methods + should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it.

+ +

When the computations are finished, call a method printSummary to print the + summary for the year. This method will take several parameters.

+ + +

When the game ends , use a method finalSummary to print out a final summary, and to tell the + player how good a job he/she did. I'll leave the details up to you, but the + usual evaluation is based on how many people starved, and how many acres per + person you end up with.

+

Your playGame method will be quite long, but very straightforward; it does very little but call other methods.

+

All the required arithmetic in this program should be integer. You + do not need doubles.

+ +

I suggest that you first get the simplest possible version of the program + running and tested out (that is, leave out things like rats, plagues, and + immigration), then add these things one at a time to a working + program, testing as you go.

+ +

Things you need to know:

+ +

Random numbers

+ +

To get a random number generator, you first need to import + java.util.Random (or java.util.*). Then, you can + create a random number generator with a statement such as:

+ +
+

static Random rand = new Random();

+
+ +

To get a new random number in the range 0..n-1, where + n is an int, call rand.nextInt(n). + To get a new random number in the range min..max, use + the expression rand.nextInt(max - min + 1) + min. You + can use the rand method in statements such as

+ +
+

myNewNumber = rand.nextInt(5);
+ if (rand.nextInt(100) < 15) { ... }

+
+ +

To do something that happens p percent of the time, use

+ +
+

if (rand.nextInt(100) < p) { ...do something... + }

+
+ +

Getting input

+

To get a number from the player, add this method to your program:

+
+/**
+ * Prints the given message (which should ask the user for some integral
+ * quantity), and returns the number entered by the user. If the user's
+ * response isn't an integer, the question is repeated until the user
+ * does give a integer response.
+ * 
+ * @param message The request to present to the user.
+ * @return The user's numeric response.
+ */
+ int getNumber(String message) {
+    while (true) {
+        System.out.print(message);
+        try {
+            return scanner.nextInt();
+        }
+        catch (InputMismatchException e) {
+            System.out.println("\"" + scanner.next() + "\" isn't a number!");
+        }
+    }
+}
+
+ +

Here is an example of how you can use this method:

+ +
+

sell = getNumber("O great Hammurabi, how many acres shall you sell?");

+
+ +

Structure of the assignment:

+ +
    +
  • Project name: Hammurabi
  • + +
  • Package name: hammurabi
  • + +
  • Class names and method signatures: + +
      +
    • + class Hammurabi + +
        +
      • public static void main(String[] args)
      • + +
      • Numerous other methods, as described above.
      • +
      +
    • +
    +
  • + +
+ +

The above are requirements. The methods that do calculations, not input/output, will be tested by my test methods, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument names are irrelevant). You may have additional methods if you wish.

+ +

Due date:

+ +

Thursday, October 21, before midnight. Turn in your zipped assignment via + Blackboard. Email submissions will incur the wrath of Hammurabi (and won't be graded).

+ + + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md new file mode 100644 index 0000000..796d85c --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md @@ -0,0 +1,6 @@ +# Notes + +from the original Dave Matuszek course of 2010. + +https://www.cis.upenn.edu/~matuszek/cit591-2010/Assignments/06-hammurabi.html + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml new file mode 100644 index 0000000..d789654 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + + io.zipcoder + MicroLabs-Loops + 1.0-SNAPSHOT + + + + + junit + junit + 4.13.2 + + + + + + 1.8 + 1.8 + + \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore new file mode 100644 index 0000000..a1c2a23 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore @@ -0,0 +1,23 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE new file mode 100644 index 0000000..22474e4 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Zip Code Wilmington Core + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md new file mode 100644 index 0000000..e4672c9 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md @@ -0,0 +1,228 @@ +# hamurabi +an ancient (in more ways than one) computer game (text) + +## General idea of the lab + +*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. + +Here are the standard instructions for the game: + +> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** +> +> * **Each person needs at least 20 bushels of grain per year to survive** +> * **Each person can farm at most 10 acres of land** +> * **It takes 2 bushels of grain to farm an acre of land** +> * **The market price for land fluctuates yearly** +> +> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** + +### Maven + +There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. + +### Details + +Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): + +```java +package hammurabi; // package declaration +import java.util.Random; // imports go here +import java.util.Scanner; + +public class Hammurabi { // must save in a file named Hammurabi.java + Random rand = new Random(); // this is an instance variable + Scanner scanner = new Scanner(System.in); + + public static void main(String\[\] args) { // required in every Java program + new Hammurabi().playGame(); + } + + void playGame() { + // declare local variables here: grain, population, etc. + // statements go after the declations + } + + //other methods go here +} +``` + +### Playing the game + +Here is what you start the game with: + +* 100 people +* 2800 bushels of grain in storage +* 1000 acres of land +* Land value is 19 bushels/acre + + +Each year, print out a summary similar to the following: + + O great Hammurabi! + You are in year 1 of your ten year rule. + In the previous year 0 people starved to death. + In the previous year 5 people entered the kingdom. + The population is now 100. + We harvested 3000 bushels at 3 bushels per acre. + Rats destroyed 200 bushels, leaving 2800 bushels in storage. + The city owns 1000 acres of land. + Land is currently worth 19 bushels per acre. + +The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. + +Here's what your `playGame` method needs to do each year, for up to 10 years: + +> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: +> +> `int askHowManyAcresToBuy(int price, int bushels)` +> +> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. +> +> ` +> int askHowManyAcresToSell(int acresOwned)` +> +> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. +> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. +> +> ` +> int askHowMuchGrainToFeedPeople(int bushels)` +> +> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. +> +> ` +> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` +> +> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. +> +> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) +> +> Then the method needs to determine: +> +> 1. If there is a plague, and how many people die from it. +> 2. How many people starved. +> 3. How many people came to the city. +> 4. How good the harvest is. +> 5. If you have a problem with rats, and how much grain they eat. +> 6. How much land costs (for deciding what to do next). +> +> These can all be local variables of your `playGame` method. +> +> Use the following methods, **in this order,** to make the necessary calculations: +> +> `int plagueDeaths(int population)` +> +> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). +> +> ` +> int starvationDeaths(int population, int bushelsFedToPeople)` +> +> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). +> +> ` +> boolean uprising(int population, int howManyPeopleStarved)` +> +> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) +> +> ` +> int immigrants(int population, int acresOwned, int grainInStorage)` +> +> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. +> +> ` +> int harvest(int acres, int bushelsUsedAsSeed)` +> +> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. +> +> ` +> int grainEatenByRats(int bushels)` +> +> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). +> +> ` +> int newCostOfLand()` +> +> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) + +Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. + +When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. + +When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. + +Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. + +All the required arithmetic in this program should be **integer**. You do not need doubles. + +### Urgent! + +> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. + +### Things you need to know: + +#### Random numbers + +To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: + +> `static Random rand = new Random();` + +To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as + +> `myNewNumber = rand.nextInt(5); +> if (rand.nextInt(100) < 15) { ... }` + +To do something that happens `p` percent of the time, use + +> `if (rand.nextInt(100) < p) { _...do something..._ }` + +#### Getting input + +To get a number from the player, add this method to your program: + +```java + /** + * Prints the given message (which should ask the user for some integral + * quantity), and returns the number entered by the user. If the user's + * response isn't an integer, the question is repeated until the user + * does give a integer response. + * + * @param message The request to present to the user. + * @return The user's numeric response. + */ + int getNumber(String message) { + while (true) { + System.out.print(message); + try { + return scanner.nextInt(); + } + catch (InputMismatchException e) { + System.out.println("\"" + scanner.next() + "\" isn't a number!"); + } + } + } +``` + +Here is an example of how you can use this method: + +> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` + +### Structure of the solution + +* Project name: `Hammurabi` +* Package name: `hammurabi` +* Class names and method signatures: + * `class Hammurabi` + * `public static void main(String[] args)` + * Numerous other methods, as described above. + +The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. + +### Yo! Test it! + +You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! + +But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. + +### Credits + +Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html new file mode 100644 index 0000000..78bbf24 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html @@ -0,0 +1,299 @@ + + + + + + + CIT591 Hammurabi + + + + + +

CIT 591 Assignment 3: + Hammurabi
+ Fall 2010, David Matuszek

+ +

Purpose of this assignment

+ +
    +
  • To get you started using Java.
  • +
+ +

General idea of the assignment

+ +

Hammurabi is a very old computer game. Your job is to bring it into the + 21st century by writing it in Java.

+ +

Here are the standard instructions for the game:

+ +
+

Congratulations, you are the newest ruler of + ancient Samaria, elected for a ten year term of office. Your duties are to + dispense food, direct farming, and buy and sell land as needed to support + your people. Watch out for rat infestiations and the plague! Grain is the + general currency, measured in bushels. The following will help you in your + decisions:

+ +
    +
  • Each person needs at least 20 bushels of + grain per year to survive
  • + +
  • Each person can farm at most 10 acres of + land
  • + +
  • It takes 2 bushels of grain to farm an acre + of land
  • + +
  • The market price for land fluctuates + yearly
  • +
+ +

Rule wisely and you will be showered with + appreciation at the end of your term. Rule poorly and you will be kicked + out of office!

+
+ +

Details

+ +

Define a single class named Hammurabi. Use the following skeleton (but leave out the // comments):

+
package hammurabi;               // package declaration
+
+import java.util.Random;         // imports go here
+import java.util.Scanner;
+
+/**
+ * The Hammurabi game.
+ * @author Your name goes here
+ * @author Your partner's name goes here
+ */
+public class Hammurabi {         // must save in a file named Hammurabi.java
+    Random rand = new Random();  // this is an instance variable
+    Scanner scanner = new Scanner(System.in);
+
+    public static void main(String[] args) { // required in every Java program
+        new Hammurabi().playGame();
+    }
+
+    void playGame() {
+        // declare local variables here: grain, population, etc.
+        // statements go after the declations
+    }
+
+    //other methods go here
+}
+

Playing the game

+

Here is what you start the game with: +

    +
  • 100 people
  • +
  • 2800 bushels of grain in storage
  • +
  • 1000 acres of land
  • +
  • Land value is 19 bushels/acre

    +
  • +
+

Each year, print out a summary similar to the following:

+
+O great Hammurabi!
+You are in year 1 of your ten year rule.
+In the previous year 0 people starved to death.
+In the previous year 5 people entered the kingdom.
+The population is now 100.
+We harvested 3000 bushels at 3 bushels per acre.
+Rats destroyed 200 bushels, leaving 2800 bushels in storage.
+The city owns 1000 acres of land.
+Land is currently worth 19 bushels per acre.
+
+ +

The above summary represents the initial state, at the beginning of + the first year--that is, when you first take office, and before you do any of + the computations below). So, for example, the previous year (under a + different ruler) must have started with 95 people; none starved, and 5 + entered the kingdom, so as you enter office you rule 100 people.

+ +

Here's what your playGame method needs to do each year, for up to 10 years:

+ +
+

Ask the player the following questions. These questions should be asked in this order. Do not give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below:

+
+
int askHowManyAcresToBuy(int price, int bushels)
+
Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase.
+

+ int askHowManyAcresToSell(int acresOwned)
+
Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have.
+ Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn.
+

+ int askHowMuchGrainToFeedPeople(int bushels)
+
Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You can feed them more than they need to survive.
+

+ int askHowManyAcresToPlant(int acresOwned, int population, int bushels)
+
Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year.
+
+

For each + question, do "sanity checking"; that is, test whether the answer is + possible (you have enough grain, you have enough people to do the planting + etc.), and keep asking until you get a possible value. (For example, + O Great Hammurabi, surely you jest! We have only 3415 bushels left!)

+ +

Then the method needs to determine:

+ +
    +
  1. If there is a plague, and how many people die from it.
  2. +
  3. How many people starved.
  4. +
  5. How many people came to the city.
  6. +
  7. How good the harvest is.
  8. +
  9. If you have a problem with rats, and how much grain they eat.
  10. +
  11. How much land costs (for deciding what to do next).
  12. +
+

These can all be local variables of your playGame method.

+

Use the following methods, in this order, to make the necessary calculations:

+
+
int plagueDeaths(int population)
+
Each year, there is a 15% chance of a horrible plague. When this + happens, half your people die. Return the number of plague deaths (possibly zero).
+

+ int starvationDeaths(int population, int bushelsFedToPeople)
+
Each person needs 20 bushels of grain to survive. If you feed them + more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero).
+

+ boolean uprising(int population, int howManyPeopleStarved)
+
Return true if more than + 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.)
+

+ int immigrants(int population, int acresOwned, int grainInStorage)
+
Nobody will come to the city if people are starving (so don't call this method). If everyone is + well fed, compute how many people come to the city as: (20 * number of acres you have + amount of grain you have in + storage) / (100 * population) + 1.
+

+ int harvest(int acres, int bushelsUsedAsSeed)
+
Choose a random integer between 1 and 6, inclusive. Each acre that was planted + with seed will yield this many bushels of grain. (Example: if you planted + 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested.
+

+ int grainEatenByRats(int bushels)
+
There is a 40% chance that you will have a rat infestation. When this + happens, rats will eat somewhere between 10% and 30% of your + grain. Return the amount of grain eaten by rats (possibly zero).
+

+ int newCostOfLand()
+
The price of land is random, and ranges from 17 to 23 bushels per + acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell + land.)
+
+
+

Do these computations, in this order, for each of ten years. Each + computation should be done in a separate method, and none of these methods + should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it.

+ +

When the computations are finished, call a method printSummary to print the + summary for the year. This method will take several parameters.

+ + +

When the game ends , use a method finalSummary to print out a final summary, and to tell the + player how good a job he/she did. I'll leave the details up to you, but the + usual evaluation is based on how many people starved, and how many acres per + person you end up with.

+

Your playGame method will be quite long, but very straightforward; it does very little but call other methods.

+

All the required arithmetic in this program should be integer. You + do not need doubles.

+ +

I suggest that you first get the simplest possible version of the program + running and tested out (that is, leave out things like rats, plagues, and + immigration), then add these things one at a time to a working + program, testing as you go.

+ +

Things you need to know:

+ +

Random numbers

+ +

To get a random number generator, you first need to import + java.util.Random (or java.util.*). Then, you can + create a random number generator with a statement such as:

+ +
+

static Random rand = new Random();

+
+ +

To get a new random number in the range 0..n-1, where + n is an int, call rand.nextInt(n). + To get a new random number in the range min..max, use + the expression rand.nextInt(max - min + 1) + min. You + can use the rand method in statements such as

+ +
+

myNewNumber = rand.nextInt(5);
+ if (rand.nextInt(100) < 15) { ... }

+
+ +

To do something that happens p percent of the time, use

+ +
+

if (rand.nextInt(100) < p) { ...do something... + }

+
+ +

Getting input

+

To get a number from the player, add this method to your program:

+
+/**
+ * Prints the given message (which should ask the user for some integral
+ * quantity), and returns the number entered by the user. If the user's
+ * response isn't an integer, the question is repeated until the user
+ * does give a integer response.
+ * 
+ * @param message The request to present to the user.
+ * @return The user's numeric response.
+ */
+ int getNumber(String message) {
+    while (true) {
+        System.out.print(message);
+        try {
+            return scanner.nextInt();
+        }
+        catch (InputMismatchException e) {
+            System.out.println("\"" + scanner.next() + "\" isn't a number!");
+        }
+    }
+}
+
+ +

Here is an example of how you can use this method:

+ +
+

sell = getNumber("O great Hammurabi, how many acres shall you sell?");

+
+ +

Structure of the assignment:

+ +
    +
  • Project name: Hammurabi
  • + +
  • Package name: hammurabi
  • + +
  • Class names and method signatures: + +
      +
    • + class Hammurabi + +
        +
      • public static void main(String[] args)
      • + +
      • Numerous other methods, as described above.
      • +
      +
    • +
    +
  • + +
+ +

The above are requirements. The methods that do calculations, not input/output, will be tested by my test methods, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument names are irrelevant). You may have additional methods if you wish.

+ +

Due date:

+ +

Thursday, October 21, before midnight. Turn in your zipped assignment via + Blackboard. Email submissions will incur the wrath of Hammurabi (and won't be graded).

+ + + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md new file mode 100644 index 0000000..796d85c --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md @@ -0,0 +1,6 @@ +# Notes + +from the original Dave Matuszek course of 2010. + +https://www.cis.upenn.edu/~matuszek/cit591-2010/Assignments/06-hammurabi.html + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml new file mode 100644 index 0000000..d789654 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + + io.zipcoder + MicroLabs-Loops + 1.0-SNAPSHOT + + + + + junit + junit + 4.13.2 + + + + + + 1.8 + 1.8 + + \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore new file mode 100644 index 0000000..a1c2a23 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore @@ -0,0 +1,23 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE new file mode 100644 index 0000000..22474e4 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Zip Code Wilmington Core + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md new file mode 100644 index 0000000..e4672c9 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md @@ -0,0 +1,228 @@ +# hamurabi +an ancient (in more ways than one) computer game (text) + +## General idea of the lab + +*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. + +Here are the standard instructions for the game: + +> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** +> +> * **Each person needs at least 20 bushels of grain per year to survive** +> * **Each person can farm at most 10 acres of land** +> * **It takes 2 bushels of grain to farm an acre of land** +> * **The market price for land fluctuates yearly** +> +> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** + +### Maven + +There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. + +### Details + +Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): + +```java +package hammurabi; // package declaration +import java.util.Random; // imports go here +import java.util.Scanner; + +public class Hammurabi { // must save in a file named Hammurabi.java + Random rand = new Random(); // this is an instance variable + Scanner scanner = new Scanner(System.in); + + public static void main(String\[\] args) { // required in every Java program + new Hammurabi().playGame(); + } + + void playGame() { + // declare local variables here: grain, population, etc. + // statements go after the declations + } + + //other methods go here +} +``` + +### Playing the game + +Here is what you start the game with: + +* 100 people +* 2800 bushels of grain in storage +* 1000 acres of land +* Land value is 19 bushels/acre + + +Each year, print out a summary similar to the following: + + O great Hammurabi! + You are in year 1 of your ten year rule. + In the previous year 0 people starved to death. + In the previous year 5 people entered the kingdom. + The population is now 100. + We harvested 3000 bushels at 3 bushels per acre. + Rats destroyed 200 bushels, leaving 2800 bushels in storage. + The city owns 1000 acres of land. + Land is currently worth 19 bushels per acre. + +The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. + +Here's what your `playGame` method needs to do each year, for up to 10 years: + +> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: +> +> `int askHowManyAcresToBuy(int price, int bushels)` +> +> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. +> +> ` +> int askHowManyAcresToSell(int acresOwned)` +> +> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. +> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. +> +> ` +> int askHowMuchGrainToFeedPeople(int bushels)` +> +> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. +> +> ` +> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` +> +> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. +> +> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) +> +> Then the method needs to determine: +> +> 1. If there is a plague, and how many people die from it. +> 2. How many people starved. +> 3. How many people came to the city. +> 4. How good the harvest is. +> 5. If you have a problem with rats, and how much grain they eat. +> 6. How much land costs (for deciding what to do next). +> +> These can all be local variables of your `playGame` method. +> +> Use the following methods, **in this order,** to make the necessary calculations: +> +> `int plagueDeaths(int population)` +> +> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). +> +> ` +> int starvationDeaths(int population, int bushelsFedToPeople)` +> +> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). +> +> ` +> boolean uprising(int population, int howManyPeopleStarved)` +> +> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) +> +> ` +> int immigrants(int population, int acresOwned, int grainInStorage)` +> +> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. +> +> ` +> int harvest(int acres, int bushelsUsedAsSeed)` +> +> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. +> +> ` +> int grainEatenByRats(int bushels)` +> +> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). +> +> ` +> int newCostOfLand()` +> +> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) + +Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. + +When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. + +When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. + +Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. + +All the required arithmetic in this program should be **integer**. You do not need doubles. + +### Urgent! + +> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. + +### Things you need to know: + +#### Random numbers + +To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: + +> `static Random rand = new Random();` + +To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as + +> `myNewNumber = rand.nextInt(5); +> if (rand.nextInt(100) < 15) { ... }` + +To do something that happens `p` percent of the time, use + +> `if (rand.nextInt(100) < p) { _...do something..._ }` + +#### Getting input + +To get a number from the player, add this method to your program: + +```java + /** + * Prints the given message (which should ask the user for some integral + * quantity), and returns the number entered by the user. If the user's + * response isn't an integer, the question is repeated until the user + * does give a integer response. + * + * @param message The request to present to the user. + * @return The user's numeric response. + */ + int getNumber(String message) { + while (true) { + System.out.print(message); + try { + return scanner.nextInt(); + } + catch (InputMismatchException e) { + System.out.println("\"" + scanner.next() + "\" isn't a number!"); + } + } + } +``` + +Here is an example of how you can use this method: + +> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` + +### Structure of the solution + +* Project name: `Hammurabi` +* Package name: `hammurabi` +* Class names and method signatures: + * `class Hammurabi` + * `public static void main(String[] args)` + * Numerous other methods, as described above. + +The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. + +### Yo! Test it! + +You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! + +But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. + +### Credits + +Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html new file mode 100644 index 0000000..78bbf24 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html @@ -0,0 +1,299 @@ + + + + + + + CIT591 Hammurabi + + + + + +

CIT 591 Assignment 3: + Hammurabi
+ Fall 2010, David Matuszek

+ +

Purpose of this assignment

+ +
    +
  • To get you started using Java.
  • +
+ +

General idea of the assignment

+ +

Hammurabi is a very old computer game. Your job is to bring it into the + 21st century by writing it in Java.

+ +

Here are the standard instructions for the game:

+ +
+

Congratulations, you are the newest ruler of + ancient Samaria, elected for a ten year term of office. Your duties are to + dispense food, direct farming, and buy and sell land as needed to support + your people. Watch out for rat infestiations and the plague! Grain is the + general currency, measured in bushels. The following will help you in your + decisions:

+ +
    +
  • Each person needs at least 20 bushels of + grain per year to survive
  • + +
  • Each person can farm at most 10 acres of + land
  • + +
  • It takes 2 bushels of grain to farm an acre + of land
  • + +
  • The market price for land fluctuates + yearly
  • +
+ +

Rule wisely and you will be showered with + appreciation at the end of your term. Rule poorly and you will be kicked + out of office!

+
+ +

Details

+ +

Define a single class named Hammurabi. Use the following skeleton (but leave out the // comments):

+
package hammurabi;               // package declaration
+
+import java.util.Random;         // imports go here
+import java.util.Scanner;
+
+/**
+ * The Hammurabi game.
+ * @author Your name goes here
+ * @author Your partner's name goes here
+ */
+public class Hammurabi {         // must save in a file named Hammurabi.java
+    Random rand = new Random();  // this is an instance variable
+    Scanner scanner = new Scanner(System.in);
+
+    public static void main(String[] args) { // required in every Java program
+        new Hammurabi().playGame();
+    }
+
+    void playGame() {
+        // declare local variables here: grain, population, etc.
+        // statements go after the declations
+    }
+
+    //other methods go here
+}
+

Playing the game

+

Here is what you start the game with: +

    +
  • 100 people
  • +
  • 2800 bushels of grain in storage
  • +
  • 1000 acres of land
  • +
  • Land value is 19 bushels/acre

    +
  • +
+

Each year, print out a summary similar to the following:

+
+O great Hammurabi!
+You are in year 1 of your ten year rule.
+In the previous year 0 people starved to death.
+In the previous year 5 people entered the kingdom.
+The population is now 100.
+We harvested 3000 bushels at 3 bushels per acre.
+Rats destroyed 200 bushels, leaving 2800 bushels in storage.
+The city owns 1000 acres of land.
+Land is currently worth 19 bushels per acre.
+
+ +

The above summary represents the initial state, at the beginning of + the first year--that is, when you first take office, and before you do any of + the computations below). So, for example, the previous year (under a + different ruler) must have started with 95 people; none starved, and 5 + entered the kingdom, so as you enter office you rule 100 people.

+ +

Here's what your playGame method needs to do each year, for up to 10 years:

+ +
+

Ask the player the following questions. These questions should be asked in this order. Do not give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below:

+
+
int askHowManyAcresToBuy(int price, int bushels)
+
Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase.
+

+ int askHowManyAcresToSell(int acresOwned)
+
Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have.
+ Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn.
+

+ int askHowMuchGrainToFeedPeople(int bushels)
+
Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You can feed them more than they need to survive.
+

+ int askHowManyAcresToPlant(int acresOwned, int population, int bushels)
+
Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year.
+
+

For each + question, do "sanity checking"; that is, test whether the answer is + possible (you have enough grain, you have enough people to do the planting + etc.), and keep asking until you get a possible value. (For example, + O Great Hammurabi, surely you jest! We have only 3415 bushels left!)

+ +

Then the method needs to determine:

+ +
    +
  1. If there is a plague, and how many people die from it.
  2. +
  3. How many people starved.
  4. +
  5. How many people came to the city.
  6. +
  7. How good the harvest is.
  8. +
  9. If you have a problem with rats, and how much grain they eat.
  10. +
  11. How much land costs (for deciding what to do next).
  12. +
+

These can all be local variables of your playGame method.

+

Use the following methods, in this order, to make the necessary calculations:

+
+
int plagueDeaths(int population)
+
Each year, there is a 15% chance of a horrible plague. When this + happens, half your people die. Return the number of plague deaths (possibly zero).
+

+ int starvationDeaths(int population, int bushelsFedToPeople)
+
Each person needs 20 bushels of grain to survive. If you feed them + more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero).
+

+ boolean uprising(int population, int howManyPeopleStarved)
+
Return true if more than + 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.)
+

+ int immigrants(int population, int acresOwned, int grainInStorage)
+
Nobody will come to the city if people are starving (so don't call this method). If everyone is + well fed, compute how many people come to the city as: (20 * number of acres you have + amount of grain you have in + storage) / (100 * population) + 1.
+

+ int harvest(int acres, int bushelsUsedAsSeed)
+
Choose a random integer between 1 and 6, inclusive. Each acre that was planted + with seed will yield this many bushels of grain. (Example: if you planted + 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested.
+

+ int grainEatenByRats(int bushels)
+
There is a 40% chance that you will have a rat infestation. When this + happens, rats will eat somewhere between 10% and 30% of your + grain. Return the amount of grain eaten by rats (possibly zero).
+

+ int newCostOfLand()
+
The price of land is random, and ranges from 17 to 23 bushels per + acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell + land.)
+
+
+

Do these computations, in this order, for each of ten years. Each + computation should be done in a separate method, and none of these methods + should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it.

+ +

When the computations are finished, call a method printSummary to print the + summary for the year. This method will take several parameters.

+ + +

When the game ends , use a method finalSummary to print out a final summary, and to tell the + player how good a job he/she did. I'll leave the details up to you, but the + usual evaluation is based on how many people starved, and how many acres per + person you end up with.

+

Your playGame method will be quite long, but very straightforward; it does very little but call other methods.

+

All the required arithmetic in this program should be integer. You + do not need doubles.

+ +

I suggest that you first get the simplest possible version of the program + running and tested out (that is, leave out things like rats, plagues, and + immigration), then add these things one at a time to a working + program, testing as you go.

+ +

Things you need to know:

+ +

Random numbers

+ +

To get a random number generator, you first need to import + java.util.Random (or java.util.*). Then, you can + create a random number generator with a statement such as:

+ +
+

static Random rand = new Random();

+
+ +

To get a new random number in the range 0..n-1, where + n is an int, call rand.nextInt(n). + To get a new random number in the range min..max, use + the expression rand.nextInt(max - min + 1) + min. You + can use the rand method in statements such as

+ +
+

myNewNumber = rand.nextInt(5);
+ if (rand.nextInt(100) < 15) { ... }

+
+ +

To do something that happens p percent of the time, use

+ +
+

if (rand.nextInt(100) < p) { ...do something... + }

+
+ +

Getting input

+

To get a number from the player, add this method to your program:

+
+/**
+ * Prints the given message (which should ask the user for some integral
+ * quantity), and returns the number entered by the user. If the user's
+ * response isn't an integer, the question is repeated until the user
+ * does give a integer response.
+ * 
+ * @param message The request to present to the user.
+ * @return The user's numeric response.
+ */
+ int getNumber(String message) {
+    while (true) {
+        System.out.print(message);
+        try {
+            return scanner.nextInt();
+        }
+        catch (InputMismatchException e) {
+            System.out.println("\"" + scanner.next() + "\" isn't a number!");
+        }
+    }
+}
+
+ +

Here is an example of how you can use this method:

+ +
+

sell = getNumber("O great Hammurabi, how many acres shall you sell?");

+
+ +

Structure of the assignment:

+ +
    +
  • Project name: Hammurabi
  • + +
  • Package name: hammurabi
  • + +
  • Class names and method signatures: + +
      +
    • + class Hammurabi + +
        +
      • public static void main(String[] args)
      • + +
      • Numerous other methods, as described above.
      • +
      +
    • +
    +
  • + +
+ +

The above are requirements. The methods that do calculations, not input/output, will be tested by my test methods, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument names are irrelevant). You may have additional methods if you wish.

+ +

Due date:

+ +

Thursday, October 21, before midnight. Turn in your zipped assignment via + Blackboard. Email submissions will incur the wrath of Hammurabi (and won't be graded).

+ + + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md new file mode 100644 index 0000000..796d85c --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md @@ -0,0 +1,6 @@ +# Notes + +from the original Dave Matuszek course of 2010. + +https://www.cis.upenn.edu/~matuszek/cit591-2010/Assignments/06-hammurabi.html + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml new file mode 100644 index 0000000..d789654 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + + io.zipcoder + MicroLabs-Loops + 1.0-SNAPSHOT + + + + + junit + junit + 4.13.2 + + + + + + 1.8 + 1.8 + + \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore new file mode 100644 index 0000000..a1c2a23 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore @@ -0,0 +1,23 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE new file mode 100644 index 0000000..22474e4 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Zip Code Wilmington Core + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md new file mode 100644 index 0000000..e4672c9 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md @@ -0,0 +1,228 @@ +# hamurabi +an ancient (in more ways than one) computer game (text) + +## General idea of the lab + +*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. + +Here are the standard instructions for the game: + +> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** +> +> * **Each person needs at least 20 bushels of grain per year to survive** +> * **Each person can farm at most 10 acres of land** +> * **It takes 2 bushels of grain to farm an acre of land** +> * **The market price for land fluctuates yearly** +> +> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** + +### Maven + +There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. + +### Details + +Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): + +```java +package hammurabi; // package declaration +import java.util.Random; // imports go here +import java.util.Scanner; + +public class Hammurabi { // must save in a file named Hammurabi.java + Random rand = new Random(); // this is an instance variable + Scanner scanner = new Scanner(System.in); + + public static void main(String\[\] args) { // required in every Java program + new Hammurabi().playGame(); + } + + void playGame() { + // declare local variables here: grain, population, etc. + // statements go after the declations + } + + //other methods go here +} +``` + +### Playing the game + +Here is what you start the game with: + +* 100 people +* 2800 bushels of grain in storage +* 1000 acres of land +* Land value is 19 bushels/acre + + +Each year, print out a summary similar to the following: + + O great Hammurabi! + You are in year 1 of your ten year rule. + In the previous year 0 people starved to death. + In the previous year 5 people entered the kingdom. + The population is now 100. + We harvested 3000 bushels at 3 bushels per acre. + Rats destroyed 200 bushels, leaving 2800 bushels in storage. + The city owns 1000 acres of land. + Land is currently worth 19 bushels per acre. + +The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. + +Here's what your `playGame` method needs to do each year, for up to 10 years: + +> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: +> +> `int askHowManyAcresToBuy(int price, int bushels)` +> +> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. +> +> ` +> int askHowManyAcresToSell(int acresOwned)` +> +> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. +> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. +> +> ` +> int askHowMuchGrainToFeedPeople(int bushels)` +> +> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. +> +> ` +> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` +> +> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. +> +> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) +> +> Then the method needs to determine: +> +> 1. If there is a plague, and how many people die from it. +> 2. How many people starved. +> 3. How many people came to the city. +> 4. How good the harvest is. +> 5. If you have a problem with rats, and how much grain they eat. +> 6. How much land costs (for deciding what to do next). +> +> These can all be local variables of your `playGame` method. +> +> Use the following methods, **in this order,** to make the necessary calculations: +> +> `int plagueDeaths(int population)` +> +> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). +> +> ` +> int starvationDeaths(int population, int bushelsFedToPeople)` +> +> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). +> +> ` +> boolean uprising(int population, int howManyPeopleStarved)` +> +> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) +> +> ` +> int immigrants(int population, int acresOwned, int grainInStorage)` +> +> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. +> +> ` +> int harvest(int acres, int bushelsUsedAsSeed)` +> +> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. +> +> ` +> int grainEatenByRats(int bushels)` +> +> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). +> +> ` +> int newCostOfLand()` +> +> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) + +Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. + +When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. + +When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. + +Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. + +All the required arithmetic in this program should be **integer**. You do not need doubles. + +### Urgent! + +> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. + +### Things you need to know: + +#### Random numbers + +To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: + +> `static Random rand = new Random();` + +To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as + +> `myNewNumber = rand.nextInt(5); +> if (rand.nextInt(100) < 15) { ... }` + +To do something that happens `p` percent of the time, use + +> `if (rand.nextInt(100) < p) { _...do something..._ }` + +#### Getting input + +To get a number from the player, add this method to your program: + +```java + /** + * Prints the given message (which should ask the user for some integral + * quantity), and returns the number entered by the user. If the user's + * response isn't an integer, the question is repeated until the user + * does give a integer response. + * + * @param message The request to present to the user. + * @return The user's numeric response. + */ + int getNumber(String message) { + while (true) { + System.out.print(message); + try { + return scanner.nextInt(); + } + catch (InputMismatchException e) { + System.out.println("\"" + scanner.next() + "\" isn't a number!"); + } + } + } +``` + +Here is an example of how you can use this method: + +> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` + +### Structure of the solution + +* Project name: `Hammurabi` +* Package name: `hammurabi` +* Class names and method signatures: + * `class Hammurabi` + * `public static void main(String[] args)` + * Numerous other methods, as described above. + +The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. + +### Yo! Test it! + +You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! + +But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. + +### Credits + +Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html new file mode 100644 index 0000000..78bbf24 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html @@ -0,0 +1,299 @@ + + + + + + + CIT591 Hammurabi + + + + + +

CIT 591 Assignment 3: + Hammurabi
+ Fall 2010, David Matuszek

+ +

Purpose of this assignment

+ +
    +
  • To get you started using Java.
  • +
+ +

General idea of the assignment

+ +

Hammurabi is a very old computer game. Your job is to bring it into the + 21st century by writing it in Java.

+ +

Here are the standard instructions for the game:

+ +
+

Congratulations, you are the newest ruler of + ancient Samaria, elected for a ten year term of office. Your duties are to + dispense food, direct farming, and buy and sell land as needed to support + your people. Watch out for rat infestiations and the plague! Grain is the + general currency, measured in bushels. The following will help you in your + decisions:

+ +
    +
  • Each person needs at least 20 bushels of + grain per year to survive
  • + +
  • Each person can farm at most 10 acres of + land
  • + +
  • It takes 2 bushels of grain to farm an acre + of land
  • + +
  • The market price for land fluctuates + yearly
  • +
+ +

Rule wisely and you will be showered with + appreciation at the end of your term. Rule poorly and you will be kicked + out of office!

+
+ +

Details

+ +

Define a single class named Hammurabi. Use the following skeleton (but leave out the // comments):

+
package hammurabi;               // package declaration
+
+import java.util.Random;         // imports go here
+import java.util.Scanner;
+
+/**
+ * The Hammurabi game.
+ * @author Your name goes here
+ * @author Your partner's name goes here
+ */
+public class Hammurabi {         // must save in a file named Hammurabi.java
+    Random rand = new Random();  // this is an instance variable
+    Scanner scanner = new Scanner(System.in);
+
+    public static void main(String[] args) { // required in every Java program
+        new Hammurabi().playGame();
+    }
+
+    void playGame() {
+        // declare local variables here: grain, population, etc.
+        // statements go after the declations
+    }
+
+    //other methods go here
+}
+

Playing the game

+

Here is what you start the game with: +

    +
  • 100 people
  • +
  • 2800 bushels of grain in storage
  • +
  • 1000 acres of land
  • +
  • Land value is 19 bushels/acre

    +
  • +
+

Each year, print out a summary similar to the following:

+
+O great Hammurabi!
+You are in year 1 of your ten year rule.
+In the previous year 0 people starved to death.
+In the previous year 5 people entered the kingdom.
+The population is now 100.
+We harvested 3000 bushels at 3 bushels per acre.
+Rats destroyed 200 bushels, leaving 2800 bushels in storage.
+The city owns 1000 acres of land.
+Land is currently worth 19 bushels per acre.
+
+ +

The above summary represents the initial state, at the beginning of + the first year--that is, when you first take office, and before you do any of + the computations below). So, for example, the previous year (under a + different ruler) must have started with 95 people; none starved, and 5 + entered the kingdom, so as you enter office you rule 100 people.

+ +

Here's what your playGame method needs to do each year, for up to 10 years:

+ +
+

Ask the player the following questions. These questions should be asked in this order. Do not give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below:

+
+
int askHowManyAcresToBuy(int price, int bushels)
+
Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase.
+

+ int askHowManyAcresToSell(int acresOwned)
+
Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have.
+ Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn.
+

+ int askHowMuchGrainToFeedPeople(int bushels)
+
Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You can feed them more than they need to survive.
+

+ int askHowManyAcresToPlant(int acresOwned, int population, int bushels)
+
Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year.
+
+

For each + question, do "sanity checking"; that is, test whether the answer is + possible (you have enough grain, you have enough people to do the planting + etc.), and keep asking until you get a possible value. (For example, + O Great Hammurabi, surely you jest! We have only 3415 bushels left!)

+ +

Then the method needs to determine:

+ +
    +
  1. If there is a plague, and how many people die from it.
  2. +
  3. How many people starved.
  4. +
  5. How many people came to the city.
  6. +
  7. How good the harvest is.
  8. +
  9. If you have a problem with rats, and how much grain they eat.
  10. +
  11. How much land costs (for deciding what to do next).
  12. +
+

These can all be local variables of your playGame method.

+

Use the following methods, in this order, to make the necessary calculations:

+
+
int plagueDeaths(int population)
+
Each year, there is a 15% chance of a horrible plague. When this + happens, half your people die. Return the number of plague deaths (possibly zero).
+

+ int starvationDeaths(int population, int bushelsFedToPeople)
+
Each person needs 20 bushels of grain to survive. If you feed them + more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero).
+

+ boolean uprising(int population, int howManyPeopleStarved)
+
Return true if more than + 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.)
+

+ int immigrants(int population, int acresOwned, int grainInStorage)
+
Nobody will come to the city if people are starving (so don't call this method). If everyone is + well fed, compute how many people come to the city as: (20 * number of acres you have + amount of grain you have in + storage) / (100 * population) + 1.
+

+ int harvest(int acres, int bushelsUsedAsSeed)
+
Choose a random integer between 1 and 6, inclusive. Each acre that was planted + with seed will yield this many bushels of grain. (Example: if you planted + 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested.
+

+ int grainEatenByRats(int bushels)
+
There is a 40% chance that you will have a rat infestation. When this + happens, rats will eat somewhere between 10% and 30% of your + grain. Return the amount of grain eaten by rats (possibly zero).
+

+ int newCostOfLand()
+
The price of land is random, and ranges from 17 to 23 bushels per + acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell + land.)
+
+
+

Do these computations, in this order, for each of ten years. Each + computation should be done in a separate method, and none of these methods + should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it.

+ +

When the computations are finished, call a method printSummary to print the + summary for the year. This method will take several parameters.

+ + +

When the game ends , use a method finalSummary to print out a final summary, and to tell the + player how good a job he/she did. I'll leave the details up to you, but the + usual evaluation is based on how many people starved, and how many acres per + person you end up with.

+

Your playGame method will be quite long, but very straightforward; it does very little but call other methods.

+

All the required arithmetic in this program should be integer. You + do not need doubles.

+ +

I suggest that you first get the simplest possible version of the program + running and tested out (that is, leave out things like rats, plagues, and + immigration), then add these things one at a time to a working + program, testing as you go.

+ +

Things you need to know:

+ +

Random numbers

+ +

To get a random number generator, you first need to import + java.util.Random (or java.util.*). Then, you can + create a random number generator with a statement such as:

+ +
+

static Random rand = new Random();

+
+ +

To get a new random number in the range 0..n-1, where + n is an int, call rand.nextInt(n). + To get a new random number in the range min..max, use + the expression rand.nextInt(max - min + 1) + min. You + can use the rand method in statements such as

+ +
+

myNewNumber = rand.nextInt(5);
+ if (rand.nextInt(100) < 15) { ... }

+
+ +

To do something that happens p percent of the time, use

+ +
+

if (rand.nextInt(100) < p) { ...do something... + }

+
+ +

Getting input

+

To get a number from the player, add this method to your program:

+
+/**
+ * Prints the given message (which should ask the user for some integral
+ * quantity), and returns the number entered by the user. If the user's
+ * response isn't an integer, the question is repeated until the user
+ * does give a integer response.
+ * 
+ * @param message The request to present to the user.
+ * @return The user's numeric response.
+ */
+ int getNumber(String message) {
+    while (true) {
+        System.out.print(message);
+        try {
+            return scanner.nextInt();
+        }
+        catch (InputMismatchException e) {
+            System.out.println("\"" + scanner.next() + "\" isn't a number!");
+        }
+    }
+}
+
+ +

Here is an example of how you can use this method:

+ +
+

sell = getNumber("O great Hammurabi, how many acres shall you sell?");

+
+ +

Structure of the assignment:

+ +
    +
  • Project name: Hammurabi
  • + +
  • Package name: hammurabi
  • + +
  • Class names and method signatures: + +
      +
    • + class Hammurabi + +
        +
      • public static void main(String[] args)
      • + +
      • Numerous other methods, as described above.
      • +
      +
    • +
    +
  • + +
+ +

The above are requirements. The methods that do calculations, not input/output, will be tested by my test methods, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument names are irrelevant). You may have additional methods if you wish.

+ +

Due date:

+ +

Thursday, October 21, before midnight. Turn in your zipped assignment via + Blackboard. Email submissions will incur the wrath of Hammurabi (and won't be graded).

+ + + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md new file mode 100644 index 0000000..796d85c --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md @@ -0,0 +1,6 @@ +# Notes + +from the original Dave Matuszek course of 2010. + +https://www.cis.upenn.edu/~matuszek/cit591-2010/Assignments/06-hammurabi.html + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml new file mode 100644 index 0000000..d789654 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + + io.zipcoder + MicroLabs-Loops + 1.0-SNAPSHOT + + + + + junit + junit + 4.13.2 + + + + + + 1.8 + 1.8 + + \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore new file mode 100644 index 0000000..a1c2a23 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore @@ -0,0 +1,23 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE new file mode 100644 index 0000000..22474e4 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Zip Code Wilmington Core + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md new file mode 100644 index 0000000..e4672c9 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md @@ -0,0 +1,228 @@ +# hamurabi +an ancient (in more ways than one) computer game (text) + +## General idea of the lab + +*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. + +Here are the standard instructions for the game: + +> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** +> +> * **Each person needs at least 20 bushels of grain per year to survive** +> * **Each person can farm at most 10 acres of land** +> * **It takes 2 bushels of grain to farm an acre of land** +> * **The market price for land fluctuates yearly** +> +> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** + +### Maven + +There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. + +### Details + +Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): + +```java +package hammurabi; // package declaration +import java.util.Random; // imports go here +import java.util.Scanner; + +public class Hammurabi { // must save in a file named Hammurabi.java + Random rand = new Random(); // this is an instance variable + Scanner scanner = new Scanner(System.in); + + public static void main(String\[\] args) { // required in every Java program + new Hammurabi().playGame(); + } + + void playGame() { + // declare local variables here: grain, population, etc. + // statements go after the declations + } + + //other methods go here +} +``` + +### Playing the game + +Here is what you start the game with: + +* 100 people +* 2800 bushels of grain in storage +* 1000 acres of land +* Land value is 19 bushels/acre + + +Each year, print out a summary similar to the following: + + O great Hammurabi! + You are in year 1 of your ten year rule. + In the previous year 0 people starved to death. + In the previous year 5 people entered the kingdom. + The population is now 100. + We harvested 3000 bushels at 3 bushels per acre. + Rats destroyed 200 bushels, leaving 2800 bushels in storage. + The city owns 1000 acres of land. + Land is currently worth 19 bushels per acre. + +The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. + +Here's what your `playGame` method needs to do each year, for up to 10 years: + +> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: +> +> `int askHowManyAcresToBuy(int price, int bushels)` +> +> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. +> +> ` +> int askHowManyAcresToSell(int acresOwned)` +> +> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. +> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. +> +> ` +> int askHowMuchGrainToFeedPeople(int bushels)` +> +> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. +> +> ` +> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` +> +> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. +> +> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) +> +> Then the method needs to determine: +> +> 1. If there is a plague, and how many people die from it. +> 2. How many people starved. +> 3. How many people came to the city. +> 4. How good the harvest is. +> 5. If you have a problem with rats, and how much grain they eat. +> 6. How much land costs (for deciding what to do next). +> +> These can all be local variables of your `playGame` method. +> +> Use the following methods, **in this order,** to make the necessary calculations: +> +> `int plagueDeaths(int population)` +> +> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). +> +> ` +> int starvationDeaths(int population, int bushelsFedToPeople)` +> +> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). +> +> ` +> boolean uprising(int population, int howManyPeopleStarved)` +> +> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) +> +> ` +> int immigrants(int population, int acresOwned, int grainInStorage)` +> +> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. +> +> ` +> int harvest(int acres, int bushelsUsedAsSeed)` +> +> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. +> +> ` +> int grainEatenByRats(int bushels)` +> +> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). +> +> ` +> int newCostOfLand()` +> +> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) + +Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. + +When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. + +When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. + +Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. + +All the required arithmetic in this program should be **integer**. You do not need doubles. + +### Urgent! + +> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. + +### Things you need to know: + +#### Random numbers + +To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: + +> `static Random rand = new Random();` + +To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as + +> `myNewNumber = rand.nextInt(5); +> if (rand.nextInt(100) < 15) { ... }` + +To do something that happens `p` percent of the time, use + +> `if (rand.nextInt(100) < p) { _...do something..._ }` + +#### Getting input + +To get a number from the player, add this method to your program: + +```java + /** + * Prints the given message (which should ask the user for some integral + * quantity), and returns the number entered by the user. If the user's + * response isn't an integer, the question is repeated until the user + * does give a integer response. + * + * @param message The request to present to the user. + * @return The user's numeric response. + */ + int getNumber(String message) { + while (true) { + System.out.print(message); + try { + return scanner.nextInt(); + } + catch (InputMismatchException e) { + System.out.println("\"" + scanner.next() + "\" isn't a number!"); + } + } + } +``` + +Here is an example of how you can use this method: + +> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` + +### Structure of the solution + +* Project name: `Hammurabi` +* Package name: `hammurabi` +* Class names and method signatures: + * `class Hammurabi` + * `public static void main(String[] args)` + * Numerous other methods, as described above. + +The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. + +### Yo! Test it! + +You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! + +But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. + +### Credits + +Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html new file mode 100644 index 0000000..78bbf24 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html @@ -0,0 +1,299 @@ + + + + + + + CIT591 Hammurabi + + + + + +

CIT 591 Assignment 3: + Hammurabi
+ Fall 2010, David Matuszek

+ +

Purpose of this assignment

+ +
    +
  • To get you started using Java.
  • +
+ +

General idea of the assignment

+ +

Hammurabi is a very old computer game. Your job is to bring it into the + 21st century by writing it in Java.

+ +

Here are the standard instructions for the game:

+ +
+

Congratulations, you are the newest ruler of + ancient Samaria, elected for a ten year term of office. Your duties are to + dispense food, direct farming, and buy and sell land as needed to support + your people. Watch out for rat infestiations and the plague! Grain is the + general currency, measured in bushels. The following will help you in your + decisions:

+ +
    +
  • Each person needs at least 20 bushels of + grain per year to survive
  • + +
  • Each person can farm at most 10 acres of + land
  • + +
  • It takes 2 bushels of grain to farm an acre + of land
  • + +
  • The market price for land fluctuates + yearly
  • +
+ +

Rule wisely and you will be showered with + appreciation at the end of your term. Rule poorly and you will be kicked + out of office!

+
+ +

Details

+ +

Define a single class named Hammurabi. Use the following skeleton (but leave out the // comments):

+
package hammurabi;               // package declaration
+
+import java.util.Random;         // imports go here
+import java.util.Scanner;
+
+/**
+ * The Hammurabi game.
+ * @author Your name goes here
+ * @author Your partner's name goes here
+ */
+public class Hammurabi {         // must save in a file named Hammurabi.java
+    Random rand = new Random();  // this is an instance variable
+    Scanner scanner = new Scanner(System.in);
+
+    public static void main(String[] args) { // required in every Java program
+        new Hammurabi().playGame();
+    }
+
+    void playGame() {
+        // declare local variables here: grain, population, etc.
+        // statements go after the declations
+    }
+
+    //other methods go here
+}
+

Playing the game

+

Here is what you start the game with: +

    +
  • 100 people
  • +
  • 2800 bushels of grain in storage
  • +
  • 1000 acres of land
  • +
  • Land value is 19 bushels/acre

    +
  • +
+

Each year, print out a summary similar to the following:

+
+O great Hammurabi!
+You are in year 1 of your ten year rule.
+In the previous year 0 people starved to death.
+In the previous year 5 people entered the kingdom.
+The population is now 100.
+We harvested 3000 bushels at 3 bushels per acre.
+Rats destroyed 200 bushels, leaving 2800 bushels in storage.
+The city owns 1000 acres of land.
+Land is currently worth 19 bushels per acre.
+
+ +

The above summary represents the initial state, at the beginning of + the first year--that is, when you first take office, and before you do any of + the computations below). So, for example, the previous year (under a + different ruler) must have started with 95 people; none starved, and 5 + entered the kingdom, so as you enter office you rule 100 people.

+ +

Here's what your playGame method needs to do each year, for up to 10 years:

+ +
+

Ask the player the following questions. These questions should be asked in this order. Do not give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below:

+
+
int askHowManyAcresToBuy(int price, int bushels)
+
Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase.
+

+ int askHowManyAcresToSell(int acresOwned)
+
Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have.
+ Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn.
+

+ int askHowMuchGrainToFeedPeople(int bushels)
+
Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You can feed them more than they need to survive.
+

+ int askHowManyAcresToPlant(int acresOwned, int population, int bushels)
+
Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year.
+
+

For each + question, do "sanity checking"; that is, test whether the answer is + possible (you have enough grain, you have enough people to do the planting + etc.), and keep asking until you get a possible value. (For example, + O Great Hammurabi, surely you jest! We have only 3415 bushels left!)

+ +

Then the method needs to determine:

+ +
    +
  1. If there is a plague, and how many people die from it.
  2. +
  3. How many people starved.
  4. +
  5. How many people came to the city.
  6. +
  7. How good the harvest is.
  8. +
  9. If you have a problem with rats, and how much grain they eat.
  10. +
  11. How much land costs (for deciding what to do next).
  12. +
+

These can all be local variables of your playGame method.

+

Use the following methods, in this order, to make the necessary calculations:

+
+
int plagueDeaths(int population)
+
Each year, there is a 15% chance of a horrible plague. When this + happens, half your people die. Return the number of plague deaths (possibly zero).
+

+ int starvationDeaths(int population, int bushelsFedToPeople)
+
Each person needs 20 bushels of grain to survive. If you feed them + more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero).
+

+ boolean uprising(int population, int howManyPeopleStarved)
+
Return true if more than + 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.)
+

+ int immigrants(int population, int acresOwned, int grainInStorage)
+
Nobody will come to the city if people are starving (so don't call this method). If everyone is + well fed, compute how many people come to the city as: (20 * number of acres you have + amount of grain you have in + storage) / (100 * population) + 1.
+

+ int harvest(int acres, int bushelsUsedAsSeed)
+
Choose a random integer between 1 and 6, inclusive. Each acre that was planted + with seed will yield this many bushels of grain. (Example: if you planted + 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested.
+

+ int grainEatenByRats(int bushels)
+
There is a 40% chance that you will have a rat infestation. When this + happens, rats will eat somewhere between 10% and 30% of your + grain. Return the amount of grain eaten by rats (possibly zero).
+

+ int newCostOfLand()
+
The price of land is random, and ranges from 17 to 23 bushels per + acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell + land.)
+
+
+

Do these computations, in this order, for each of ten years. Each + computation should be done in a separate method, and none of these methods + should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it.

+ +

When the computations are finished, call a method printSummary to print the + summary for the year. This method will take several parameters.

+ + +

When the game ends , use a method finalSummary to print out a final summary, and to tell the + player how good a job he/she did. I'll leave the details up to you, but the + usual evaluation is based on how many people starved, and how many acres per + person you end up with.

+

Your playGame method will be quite long, but very straightforward; it does very little but call other methods.

+

All the required arithmetic in this program should be integer. You + do not need doubles.

+ +

I suggest that you first get the simplest possible version of the program + running and tested out (that is, leave out things like rats, plagues, and + immigration), then add these things one at a time to a working + program, testing as you go.

+ +

Things you need to know:

+ +

Random numbers

+ +

To get a random number generator, you first need to import + java.util.Random (or java.util.*). Then, you can + create a random number generator with a statement such as:

+ +
+

static Random rand = new Random();

+
+ +

To get a new random number in the range 0..n-1, where + n is an int, call rand.nextInt(n). + To get a new random number in the range min..max, use + the expression rand.nextInt(max - min + 1) + min. You + can use the rand method in statements such as

+ +
+

myNewNumber = rand.nextInt(5);
+ if (rand.nextInt(100) < 15) { ... }

+
+ +

To do something that happens p percent of the time, use

+ +
+

if (rand.nextInt(100) < p) { ...do something... + }

+
+ +

Getting input

+

To get a number from the player, add this method to your program:

+
+/**
+ * Prints the given message (which should ask the user for some integral
+ * quantity), and returns the number entered by the user. If the user's
+ * response isn't an integer, the question is repeated until the user
+ * does give a integer response.
+ * 
+ * @param message The request to present to the user.
+ * @return The user's numeric response.
+ */
+ int getNumber(String message) {
+    while (true) {
+        System.out.print(message);
+        try {
+            return scanner.nextInt();
+        }
+        catch (InputMismatchException e) {
+            System.out.println("\"" + scanner.next() + "\" isn't a number!");
+        }
+    }
+}
+
+ +

Here is an example of how you can use this method:

+ +
+

sell = getNumber("O great Hammurabi, how many acres shall you sell?");

+
+ +

Structure of the assignment:

+ +
    +
  • Project name: Hammurabi
  • + +
  • Package name: hammurabi
  • + +
  • Class names and method signatures: + +
      +
    • + class Hammurabi + +
        +
      • public static void main(String[] args)
      • + +
      • Numerous other methods, as described above.
      • +
      +
    • +
    +
  • + +
+ +

The above are requirements. The methods that do calculations, not input/output, will be tested by my test methods, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument names are irrelevant). You may have additional methods if you wish.

+ +

Due date:

+ +

Thursday, October 21, before midnight. Turn in your zipped assignment via + Blackboard. Email submissions will incur the wrath of Hammurabi (and won't be graded).

+ + + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md new file mode 100644 index 0000000..796d85c --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md @@ -0,0 +1,6 @@ +# Notes + +from the original Dave Matuszek course of 2010. + +https://www.cis.upenn.edu/~matuszek/cit591-2010/Assignments/06-hammurabi.html + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml new file mode 100644 index 0000000..d789654 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + + io.zipcoder + MicroLabs-Loops + 1.0-SNAPSHOT + + + + + junit + junit + 4.13.2 + + + + + + 1.8 + 1.8 + + \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore new file mode 100644 index 0000000..a1c2a23 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore @@ -0,0 +1,23 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE new file mode 100644 index 0000000..22474e4 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Zip Code Wilmington Core + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md new file mode 100644 index 0000000..e4672c9 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md @@ -0,0 +1,228 @@ +# hamurabi +an ancient (in more ways than one) computer game (text) + +## General idea of the lab + +*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. + +Here are the standard instructions for the game: + +> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** +> +> * **Each person needs at least 20 bushels of grain per year to survive** +> * **Each person can farm at most 10 acres of land** +> * **It takes 2 bushels of grain to farm an acre of land** +> * **The market price for land fluctuates yearly** +> +> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** + +### Maven + +There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. + +### Details + +Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): + +```java +package hammurabi; // package declaration +import java.util.Random; // imports go here +import java.util.Scanner; + +public class Hammurabi { // must save in a file named Hammurabi.java + Random rand = new Random(); // this is an instance variable + Scanner scanner = new Scanner(System.in); + + public static void main(String\[\] args) { // required in every Java program + new Hammurabi().playGame(); + } + + void playGame() { + // declare local variables here: grain, population, etc. + // statements go after the declations + } + + //other methods go here +} +``` + +### Playing the game + +Here is what you start the game with: + +* 100 people +* 2800 bushels of grain in storage +* 1000 acres of land +* Land value is 19 bushels/acre + + +Each year, print out a summary similar to the following: + + O great Hammurabi! + You are in year 1 of your ten year rule. + In the previous year 0 people starved to death. + In the previous year 5 people entered the kingdom. + The population is now 100. + We harvested 3000 bushels at 3 bushels per acre. + Rats destroyed 200 bushels, leaving 2800 bushels in storage. + The city owns 1000 acres of land. + Land is currently worth 19 bushels per acre. + +The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. + +Here's what your `playGame` method needs to do each year, for up to 10 years: + +> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: +> +> `int askHowManyAcresToBuy(int price, int bushels)` +> +> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. +> +> ` +> int askHowManyAcresToSell(int acresOwned)` +> +> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. +> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. +> +> ` +> int askHowMuchGrainToFeedPeople(int bushels)` +> +> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. +> +> ` +> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` +> +> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. +> +> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) +> +> Then the method needs to determine: +> +> 1. If there is a plague, and how many people die from it. +> 2. How many people starved. +> 3. How many people came to the city. +> 4. How good the harvest is. +> 5. If you have a problem with rats, and how much grain they eat. +> 6. How much land costs (for deciding what to do next). +> +> These can all be local variables of your `playGame` method. +> +> Use the following methods, **in this order,** to make the necessary calculations: +> +> `int plagueDeaths(int population)` +> +> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). +> +> ` +> int starvationDeaths(int population, int bushelsFedToPeople)` +> +> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). +> +> ` +> boolean uprising(int population, int howManyPeopleStarved)` +> +> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) +> +> ` +> int immigrants(int population, int acresOwned, int grainInStorage)` +> +> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. +> +> ` +> int harvest(int acres, int bushelsUsedAsSeed)` +> +> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. +> +> ` +> int grainEatenByRats(int bushels)` +> +> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). +> +> ` +> int newCostOfLand()` +> +> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) + +Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. + +When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. + +When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. + +Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. + +All the required arithmetic in this program should be **integer**. You do not need doubles. + +### Urgent! + +> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. + +### Things you need to know: + +#### Random numbers + +To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: + +> `static Random rand = new Random();` + +To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as + +> `myNewNumber = rand.nextInt(5); +> if (rand.nextInt(100) < 15) { ... }` + +To do something that happens `p` percent of the time, use + +> `if (rand.nextInt(100) < p) { _...do something..._ }` + +#### Getting input + +To get a number from the player, add this method to your program: + +```java + /** + * Prints the given message (which should ask the user for some integral + * quantity), and returns the number entered by the user. If the user's + * response isn't an integer, the question is repeated until the user + * does give a integer response. + * + * @param message The request to present to the user. + * @return The user's numeric response. + */ + int getNumber(String message) { + while (true) { + System.out.print(message); + try { + return scanner.nextInt(); + } + catch (InputMismatchException e) { + System.out.println("\"" + scanner.next() + "\" isn't a number!"); + } + } + } +``` + +Here is an example of how you can use this method: + +> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` + +### Structure of the solution + +* Project name: `Hammurabi` +* Package name: `hammurabi` +* Class names and method signatures: + * `class Hammurabi` + * `public static void main(String[] args)` + * Numerous other methods, as described above. + +The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. + +### Yo! Test it! + +You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! + +But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. + +### Credits + +Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html new file mode 100644 index 0000000..78bbf24 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html @@ -0,0 +1,299 @@ + + + + + + + CIT591 Hammurabi + + + + + +

CIT 591 Assignment 3: + Hammurabi
+ Fall 2010, David Matuszek

+ +

Purpose of this assignment

+ +
    +
  • To get you started using Java.
  • +
+ +

General idea of the assignment

+ +

Hammurabi is a very old computer game. Your job is to bring it into the + 21st century by writing it in Java.

+ +

Here are the standard instructions for the game:

+ +
+

Congratulations, you are the newest ruler of + ancient Samaria, elected for a ten year term of office. Your duties are to + dispense food, direct farming, and buy and sell land as needed to support + your people. Watch out for rat infestiations and the plague! Grain is the + general currency, measured in bushels. The following will help you in your + decisions:

+ +
    +
  • Each person needs at least 20 bushels of + grain per year to survive
  • + +
  • Each person can farm at most 10 acres of + land
  • + +
  • It takes 2 bushels of grain to farm an acre + of land
  • + +
  • The market price for land fluctuates + yearly
  • +
+ +

Rule wisely and you will be showered with + appreciation at the end of your term. Rule poorly and you will be kicked + out of office!

+
+ +

Details

+ +

Define a single class named Hammurabi. Use the following skeleton (but leave out the // comments):

+
package hammurabi;               // package declaration
+
+import java.util.Random;         // imports go here
+import java.util.Scanner;
+
+/**
+ * The Hammurabi game.
+ * @author Your name goes here
+ * @author Your partner's name goes here
+ */
+public class Hammurabi {         // must save in a file named Hammurabi.java
+    Random rand = new Random();  // this is an instance variable
+    Scanner scanner = new Scanner(System.in);
+
+    public static void main(String[] args) { // required in every Java program
+        new Hammurabi().playGame();
+    }
+
+    void playGame() {
+        // declare local variables here: grain, population, etc.
+        // statements go after the declations
+    }
+
+    //other methods go here
+}
+

Playing the game

+

Here is what you start the game with: +

    +
  • 100 people
  • +
  • 2800 bushels of grain in storage
  • +
  • 1000 acres of land
  • +
  • Land value is 19 bushels/acre

    +
  • +
+

Each year, print out a summary similar to the following:

+
+O great Hammurabi!
+You are in year 1 of your ten year rule.
+In the previous year 0 people starved to death.
+In the previous year 5 people entered the kingdom.
+The population is now 100.
+We harvested 3000 bushels at 3 bushels per acre.
+Rats destroyed 200 bushels, leaving 2800 bushels in storage.
+The city owns 1000 acres of land.
+Land is currently worth 19 bushels per acre.
+
+ +

The above summary represents the initial state, at the beginning of + the first year--that is, when you first take office, and before you do any of + the computations below). So, for example, the previous year (under a + different ruler) must have started with 95 people; none starved, and 5 + entered the kingdom, so as you enter office you rule 100 people.

+ +

Here's what your playGame method needs to do each year, for up to 10 years:

+ +
+

Ask the player the following questions. These questions should be asked in this order. Do not give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below:

+
+
int askHowManyAcresToBuy(int price, int bushels)
+
Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase.
+

+ int askHowManyAcresToSell(int acresOwned)
+
Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have.
+ Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn.
+

+ int askHowMuchGrainToFeedPeople(int bushels)
+
Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You can feed them more than they need to survive.
+

+ int askHowManyAcresToPlant(int acresOwned, int population, int bushels)
+
Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year.
+
+

For each + question, do "sanity checking"; that is, test whether the answer is + possible (you have enough grain, you have enough people to do the planting + etc.), and keep asking until you get a possible value. (For example, + O Great Hammurabi, surely you jest! We have only 3415 bushels left!)

+ +

Then the method needs to determine:

+ +
    +
  1. If there is a plague, and how many people die from it.
  2. +
  3. How many people starved.
  4. +
  5. How many people came to the city.
  6. +
  7. How good the harvest is.
  8. +
  9. If you have a problem with rats, and how much grain they eat.
  10. +
  11. How much land costs (for deciding what to do next).
  12. +
+

These can all be local variables of your playGame method.

+

Use the following methods, in this order, to make the necessary calculations:

+
+
int plagueDeaths(int population)
+
Each year, there is a 15% chance of a horrible plague. When this + happens, half your people die. Return the number of plague deaths (possibly zero).
+

+ int starvationDeaths(int population, int bushelsFedToPeople)
+
Each person needs 20 bushels of grain to survive. If you feed them + more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero).
+

+ boolean uprising(int population, int howManyPeopleStarved)
+
Return true if more than + 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.)
+

+ int immigrants(int population, int acresOwned, int grainInStorage)
+
Nobody will come to the city if people are starving (so don't call this method). If everyone is + well fed, compute how many people come to the city as: (20 * number of acres you have + amount of grain you have in + storage) / (100 * population) + 1.
+

+ int harvest(int acres, int bushelsUsedAsSeed)
+
Choose a random integer between 1 and 6, inclusive. Each acre that was planted + with seed will yield this many bushels of grain. (Example: if you planted + 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested.
+

+ int grainEatenByRats(int bushels)
+
There is a 40% chance that you will have a rat infestation. When this + happens, rats will eat somewhere between 10% and 30% of your + grain. Return the amount of grain eaten by rats (possibly zero).
+

+ int newCostOfLand()
+
The price of land is random, and ranges from 17 to 23 bushels per + acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell + land.)
+
+
+

Do these computations, in this order, for each of ten years. Each + computation should be done in a separate method, and none of these methods + should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it.

+ +

When the computations are finished, call a method printSummary to print the + summary for the year. This method will take several parameters.

+ + +

When the game ends , use a method finalSummary to print out a final summary, and to tell the + player how good a job he/she did. I'll leave the details up to you, but the + usual evaluation is based on how many people starved, and how many acres per + person you end up with.

+

Your playGame method will be quite long, but very straightforward; it does very little but call other methods.

+

All the required arithmetic in this program should be integer. You + do not need doubles.

+ +

I suggest that you first get the simplest possible version of the program + running and tested out (that is, leave out things like rats, plagues, and + immigration), then add these things one at a time to a working + program, testing as you go.

+ +

Things you need to know:

+ +

Random numbers

+ +

To get a random number generator, you first need to import + java.util.Random (or java.util.*). Then, you can + create a random number generator with a statement such as:

+ +
+

static Random rand = new Random();

+
+ +

To get a new random number in the range 0..n-1, where + n is an int, call rand.nextInt(n). + To get a new random number in the range min..max, use + the expression rand.nextInt(max - min + 1) + min. You + can use the rand method in statements such as

+ +
+

myNewNumber = rand.nextInt(5);
+ if (rand.nextInt(100) < 15) { ... }

+
+ +

To do something that happens p percent of the time, use

+ +
+

if (rand.nextInt(100) < p) { ...do something... + }

+
+ +

Getting input

+

To get a number from the player, add this method to your program:

+
+/**
+ * Prints the given message (which should ask the user for some integral
+ * quantity), and returns the number entered by the user. If the user's
+ * response isn't an integer, the question is repeated until the user
+ * does give a integer response.
+ * 
+ * @param message The request to present to the user.
+ * @return The user's numeric response.
+ */
+ int getNumber(String message) {
+    while (true) {
+        System.out.print(message);
+        try {
+            return scanner.nextInt();
+        }
+        catch (InputMismatchException e) {
+            System.out.println("\"" + scanner.next() + "\" isn't a number!");
+        }
+    }
+}
+
+ +

Here is an example of how you can use this method:

+ +
+

sell = getNumber("O great Hammurabi, how many acres shall you sell?");

+
+ +

Structure of the assignment:

+ +
    +
  • Project name: Hammurabi
  • + +
  • Package name: hammurabi
  • + +
  • Class names and method signatures: + +
      +
    • + class Hammurabi + +
        +
      • public static void main(String[] args)
      • + +
      • Numerous other methods, as described above.
      • +
      +
    • +
    +
  • + +
+ +

The above are requirements. The methods that do calculations, not input/output, will be tested by my test methods, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument names are irrelevant). You may have additional methods if you wish.

+ +

Due date:

+ +

Thursday, October 21, before midnight. Turn in your zipped assignment via + Blackboard. Email submissions will incur the wrath of Hammurabi (and won't be graded).

+ + + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md new file mode 100644 index 0000000..796d85c --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md @@ -0,0 +1,6 @@ +# Notes + +from the original Dave Matuszek course of 2010. + +https://www.cis.upenn.edu/~matuszek/cit591-2010/Assignments/06-hammurabi.html + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml new file mode 100644 index 0000000..d789654 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + + io.zipcoder + MicroLabs-Loops + 1.0-SNAPSHOT + + + + + junit + junit + 4.13.2 + + + + + + 1.8 + 1.8 + + \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore new file mode 100644 index 0000000..a1c2a23 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore @@ -0,0 +1,23 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE new file mode 100644 index 0000000..22474e4 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Zip Code Wilmington Core + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md new file mode 100644 index 0000000..e4672c9 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md @@ -0,0 +1,228 @@ +# hamurabi +an ancient (in more ways than one) computer game (text) + +## General idea of the lab + +*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. + +Here are the standard instructions for the game: + +> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** +> +> * **Each person needs at least 20 bushels of grain per year to survive** +> * **Each person can farm at most 10 acres of land** +> * **It takes 2 bushels of grain to farm an acre of land** +> * **The market price for land fluctuates yearly** +> +> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** + +### Maven + +There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. + +### Details + +Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): + +```java +package hammurabi; // package declaration +import java.util.Random; // imports go here +import java.util.Scanner; + +public class Hammurabi { // must save in a file named Hammurabi.java + Random rand = new Random(); // this is an instance variable + Scanner scanner = new Scanner(System.in); + + public static void main(String\[\] args) { // required in every Java program + new Hammurabi().playGame(); + } + + void playGame() { + // declare local variables here: grain, population, etc. + // statements go after the declations + } + + //other methods go here +} +``` + +### Playing the game + +Here is what you start the game with: + +* 100 people +* 2800 bushels of grain in storage +* 1000 acres of land +* Land value is 19 bushels/acre + + +Each year, print out a summary similar to the following: + + O great Hammurabi! + You are in year 1 of your ten year rule. + In the previous year 0 people starved to death. + In the previous year 5 people entered the kingdom. + The population is now 100. + We harvested 3000 bushels at 3 bushels per acre. + Rats destroyed 200 bushels, leaving 2800 bushels in storage. + The city owns 1000 acres of land. + Land is currently worth 19 bushels per acre. + +The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. + +Here's what your `playGame` method needs to do each year, for up to 10 years: + +> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: +> +> `int askHowManyAcresToBuy(int price, int bushels)` +> +> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. +> +> ` +> int askHowManyAcresToSell(int acresOwned)` +> +> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. +> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. +> +> ` +> int askHowMuchGrainToFeedPeople(int bushels)` +> +> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. +> +> ` +> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` +> +> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. +> +> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) +> +> Then the method needs to determine: +> +> 1. If there is a plague, and how many people die from it. +> 2. How many people starved. +> 3. How many people came to the city. +> 4. How good the harvest is. +> 5. If you have a problem with rats, and how much grain they eat. +> 6. How much land costs (for deciding what to do next). +> +> These can all be local variables of your `playGame` method. +> +> Use the following methods, **in this order,** to make the necessary calculations: +> +> `int plagueDeaths(int population)` +> +> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). +> +> ` +> int starvationDeaths(int population, int bushelsFedToPeople)` +> +> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). +> +> ` +> boolean uprising(int population, int howManyPeopleStarved)` +> +> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) +> +> ` +> int immigrants(int population, int acresOwned, int grainInStorage)` +> +> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. +> +> ` +> int harvest(int acres, int bushelsUsedAsSeed)` +> +> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. +> +> ` +> int grainEatenByRats(int bushels)` +> +> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). +> +> ` +> int newCostOfLand()` +> +> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) + +Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. + +When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. + +When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. + +Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. + +All the required arithmetic in this program should be **integer**. You do not need doubles. + +### Urgent! + +> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. + +### Things you need to know: + +#### Random numbers + +To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: + +> `static Random rand = new Random();` + +To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as + +> `myNewNumber = rand.nextInt(5); +> if (rand.nextInt(100) < 15) { ... }` + +To do something that happens `p` percent of the time, use + +> `if (rand.nextInt(100) < p) { _...do something..._ }` + +#### Getting input + +To get a number from the player, add this method to your program: + +```java + /** + * Prints the given message (which should ask the user for some integral + * quantity), and returns the number entered by the user. If the user's + * response isn't an integer, the question is repeated until the user + * does give a integer response. + * + * @param message The request to present to the user. + * @return The user's numeric response. + */ + int getNumber(String message) { + while (true) { + System.out.print(message); + try { + return scanner.nextInt(); + } + catch (InputMismatchException e) { + System.out.println("\"" + scanner.next() + "\" isn't a number!"); + } + } + } +``` + +Here is an example of how you can use this method: + +> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` + +### Structure of the solution + +* Project name: `Hammurabi` +* Package name: `hammurabi` +* Class names and method signatures: + * `class Hammurabi` + * `public static void main(String[] args)` + * Numerous other methods, as described above. + +The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. + +### Yo! Test it! + +You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! + +But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. + +### Credits + +Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html new file mode 100644 index 0000000..78bbf24 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html @@ -0,0 +1,299 @@ + + + + + + + CIT591 Hammurabi + + + + + +

CIT 591 Assignment 3: + Hammurabi
+ Fall 2010, David Matuszek

+ +

Purpose of this assignment

+ +
    +
  • To get you started using Java.
  • +
+ +

General idea of the assignment

+ +

Hammurabi is a very old computer game. Your job is to bring it into the + 21st century by writing it in Java.

+ +

Here are the standard instructions for the game:

+ +
+

Congratulations, you are the newest ruler of + ancient Samaria, elected for a ten year term of office. Your duties are to + dispense food, direct farming, and buy and sell land as needed to support + your people. Watch out for rat infestiations and the plague! Grain is the + general currency, measured in bushels. The following will help you in your + decisions:

+ +
    +
  • Each person needs at least 20 bushels of + grain per year to survive
  • + +
  • Each person can farm at most 10 acres of + land
  • + +
  • It takes 2 bushels of grain to farm an acre + of land
  • + +
  • The market price for land fluctuates + yearly
  • +
+ +

Rule wisely and you will be showered with + appreciation at the end of your term. Rule poorly and you will be kicked + out of office!

+
+ +

Details

+ +

Define a single class named Hammurabi. Use the following skeleton (but leave out the // comments):

+
package hammurabi;               // package declaration
+
+import java.util.Random;         // imports go here
+import java.util.Scanner;
+
+/**
+ * The Hammurabi game.
+ * @author Your name goes here
+ * @author Your partner's name goes here
+ */
+public class Hammurabi {         // must save in a file named Hammurabi.java
+    Random rand = new Random();  // this is an instance variable
+    Scanner scanner = new Scanner(System.in);
+
+    public static void main(String[] args) { // required in every Java program
+        new Hammurabi().playGame();
+    }
+
+    void playGame() {
+        // declare local variables here: grain, population, etc.
+        // statements go after the declations
+    }
+
+    //other methods go here
+}
+

Playing the game

+

Here is what you start the game with: +

    +
  • 100 people
  • +
  • 2800 bushels of grain in storage
  • +
  • 1000 acres of land
  • +
  • Land value is 19 bushels/acre

    +
  • +
+

Each year, print out a summary similar to the following:

+
+O great Hammurabi!
+You are in year 1 of your ten year rule.
+In the previous year 0 people starved to death.
+In the previous year 5 people entered the kingdom.
+The population is now 100.
+We harvested 3000 bushels at 3 bushels per acre.
+Rats destroyed 200 bushels, leaving 2800 bushels in storage.
+The city owns 1000 acres of land.
+Land is currently worth 19 bushels per acre.
+
+ +

The above summary represents the initial state, at the beginning of + the first year--that is, when you first take office, and before you do any of + the computations below). So, for example, the previous year (under a + different ruler) must have started with 95 people; none starved, and 5 + entered the kingdom, so as you enter office you rule 100 people.

+ +

Here's what your playGame method needs to do each year, for up to 10 years:

+ +
+

Ask the player the following questions. These questions should be asked in this order. Do not give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below:

+
+
int askHowManyAcresToBuy(int price, int bushels)
+
Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase.
+

+ int askHowManyAcresToSell(int acresOwned)
+
Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have.
+ Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn.
+

+ int askHowMuchGrainToFeedPeople(int bushels)
+
Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You can feed them more than they need to survive.
+

+ int askHowManyAcresToPlant(int acresOwned, int population, int bushels)
+
Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year.
+
+

For each + question, do "sanity checking"; that is, test whether the answer is + possible (you have enough grain, you have enough people to do the planting + etc.), and keep asking until you get a possible value. (For example, + O Great Hammurabi, surely you jest! We have only 3415 bushels left!)

+ +

Then the method needs to determine:

+ +
    +
  1. If there is a plague, and how many people die from it.
  2. +
  3. How many people starved.
  4. +
  5. How many people came to the city.
  6. +
  7. How good the harvest is.
  8. +
  9. If you have a problem with rats, and how much grain they eat.
  10. +
  11. How much land costs (for deciding what to do next).
  12. +
+

These can all be local variables of your playGame method.

+

Use the following methods, in this order, to make the necessary calculations:

+
+
int plagueDeaths(int population)
+
Each year, there is a 15% chance of a horrible plague. When this + happens, half your people die. Return the number of plague deaths (possibly zero).
+

+ int starvationDeaths(int population, int bushelsFedToPeople)
+
Each person needs 20 bushels of grain to survive. If you feed them + more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero).
+

+ boolean uprising(int population, int howManyPeopleStarved)
+
Return true if more than + 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.)
+

+ int immigrants(int population, int acresOwned, int grainInStorage)
+
Nobody will come to the city if people are starving (so don't call this method). If everyone is + well fed, compute how many people come to the city as: (20 * number of acres you have + amount of grain you have in + storage) / (100 * population) + 1.
+

+ int harvest(int acres, int bushelsUsedAsSeed)
+
Choose a random integer between 1 and 6, inclusive. Each acre that was planted + with seed will yield this many bushels of grain. (Example: if you planted + 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested.
+

+ int grainEatenByRats(int bushels)
+
There is a 40% chance that you will have a rat infestation. When this + happens, rats will eat somewhere between 10% and 30% of your + grain. Return the amount of grain eaten by rats (possibly zero).
+

+ int newCostOfLand()
+
The price of land is random, and ranges from 17 to 23 bushels per + acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell + land.)
+
+
+

Do these computations, in this order, for each of ten years. Each + computation should be done in a separate method, and none of these methods + should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it.

+ +

When the computations are finished, call a method printSummary to print the + summary for the year. This method will take several parameters.

+ + +

When the game ends , use a method finalSummary to print out a final summary, and to tell the + player how good a job he/she did. I'll leave the details up to you, but the + usual evaluation is based on how many people starved, and how many acres per + person you end up with.

+

Your playGame method will be quite long, but very straightforward; it does very little but call other methods.

+

All the required arithmetic in this program should be integer. You + do not need doubles.

+ +

I suggest that you first get the simplest possible version of the program + running and tested out (that is, leave out things like rats, plagues, and + immigration), then add these things one at a time to a working + program, testing as you go.

+ +

Things you need to know:

+ +

Random numbers

+ +

To get a random number generator, you first need to import + java.util.Random (or java.util.*). Then, you can + create a random number generator with a statement such as:

+ +
+

static Random rand = new Random();

+
+ +

To get a new random number in the range 0..n-1, where + n is an int, call rand.nextInt(n). + To get a new random number in the range min..max, use + the expression rand.nextInt(max - min + 1) + min. You + can use the rand method in statements such as

+ +
+

myNewNumber = rand.nextInt(5);
+ if (rand.nextInt(100) < 15) { ... }

+
+ +

To do something that happens p percent of the time, use

+ +
+

if (rand.nextInt(100) < p) { ...do something... + }

+
+ +

Getting input

+

To get a number from the player, add this method to your program:

+
+/**
+ * Prints the given message (which should ask the user for some integral
+ * quantity), and returns the number entered by the user. If the user's
+ * response isn't an integer, the question is repeated until the user
+ * does give a integer response.
+ * 
+ * @param message The request to present to the user.
+ * @return The user's numeric response.
+ */
+ int getNumber(String message) {
+    while (true) {
+        System.out.print(message);
+        try {
+            return scanner.nextInt();
+        }
+        catch (InputMismatchException e) {
+            System.out.println("\"" + scanner.next() + "\" isn't a number!");
+        }
+    }
+}
+
+ +

Here is an example of how you can use this method:

+ +
+

sell = getNumber("O great Hammurabi, how many acres shall you sell?");

+
+ +

Structure of the assignment:

+ +
    +
  • Project name: Hammurabi
  • + +
  • Package name: hammurabi
  • + +
  • Class names and method signatures: + +
      +
    • + class Hammurabi + +
        +
      • public static void main(String[] args)
      • + +
      • Numerous other methods, as described above.
      • +
      +
    • +
    +
  • + +
+ +

The above are requirements. The methods that do calculations, not input/output, will be tested by my test methods, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument names are irrelevant). You may have additional methods if you wish.

+ +

Due date:

+ +

Thursday, October 21, before midnight. Turn in your zipped assignment via + Blackboard. Email submissions will incur the wrath of Hammurabi (and won't be graded).

+ + + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md new file mode 100644 index 0000000..796d85c --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md @@ -0,0 +1,6 @@ +# Notes + +from the original Dave Matuszek course of 2010. + +https://www.cis.upenn.edu/~matuszek/cit591-2010/Assignments/06-hammurabi.html + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml new file mode 100644 index 0000000..d789654 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + + io.zipcoder + MicroLabs-Loops + 1.0-SNAPSHOT + + + + + junit + junit + 4.13.2 + + + + + + 1.8 + 1.8 + + \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore new file mode 100644 index 0000000..a1c2a23 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore @@ -0,0 +1,23 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE new file mode 100644 index 0000000..22474e4 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Zip Code Wilmington Core + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md new file mode 100644 index 0000000..e4672c9 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md @@ -0,0 +1,228 @@ +# hamurabi +an ancient (in more ways than one) computer game (text) + +## General idea of the lab + +*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. + +Here are the standard instructions for the game: + +> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** +> +> * **Each person needs at least 20 bushels of grain per year to survive** +> * **Each person can farm at most 10 acres of land** +> * **It takes 2 bushels of grain to farm an acre of land** +> * **The market price for land fluctuates yearly** +> +> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** + +### Maven + +There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. + +### Details + +Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): + +```java +package hammurabi; // package declaration +import java.util.Random; // imports go here +import java.util.Scanner; + +public class Hammurabi { // must save in a file named Hammurabi.java + Random rand = new Random(); // this is an instance variable + Scanner scanner = new Scanner(System.in); + + public static void main(String\[\] args) { // required in every Java program + new Hammurabi().playGame(); + } + + void playGame() { + // declare local variables here: grain, population, etc. + // statements go after the declations + } + + //other methods go here +} +``` + +### Playing the game + +Here is what you start the game with: + +* 100 people +* 2800 bushels of grain in storage +* 1000 acres of land +* Land value is 19 bushels/acre + + +Each year, print out a summary similar to the following: + + O great Hammurabi! + You are in year 1 of your ten year rule. + In the previous year 0 people starved to death. + In the previous year 5 people entered the kingdom. + The population is now 100. + We harvested 3000 bushels at 3 bushels per acre. + Rats destroyed 200 bushels, leaving 2800 bushels in storage. + The city owns 1000 acres of land. + Land is currently worth 19 bushels per acre. + +The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. + +Here's what your `playGame` method needs to do each year, for up to 10 years: + +> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: +> +> `int askHowManyAcresToBuy(int price, int bushels)` +> +> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. +> +> ` +> int askHowManyAcresToSell(int acresOwned)` +> +> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. +> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. +> +> ` +> int askHowMuchGrainToFeedPeople(int bushels)` +> +> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. +> +> ` +> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` +> +> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. +> +> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) +> +> Then the method needs to determine: +> +> 1. If there is a plague, and how many people die from it. +> 2. How many people starved. +> 3. How many people came to the city. +> 4. How good the harvest is. +> 5. If you have a problem with rats, and how much grain they eat. +> 6. How much land costs (for deciding what to do next). +> +> These can all be local variables of your `playGame` method. +> +> Use the following methods, **in this order,** to make the necessary calculations: +> +> `int plagueDeaths(int population)` +> +> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). +> +> ` +> int starvationDeaths(int population, int bushelsFedToPeople)` +> +> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). +> +> ` +> boolean uprising(int population, int howManyPeopleStarved)` +> +> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) +> +> ` +> int immigrants(int population, int acresOwned, int grainInStorage)` +> +> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. +> +> ` +> int harvest(int acres, int bushelsUsedAsSeed)` +> +> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. +> +> ` +> int grainEatenByRats(int bushels)` +> +> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). +> +> ` +> int newCostOfLand()` +> +> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) + +Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. + +When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. + +When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. + +Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. + +All the required arithmetic in this program should be **integer**. You do not need doubles. + +### Urgent! + +> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. + +### Things you need to know: + +#### Random numbers + +To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: + +> `static Random rand = new Random();` + +To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as + +> `myNewNumber = rand.nextInt(5); +> if (rand.nextInt(100) < 15) { ... }` + +To do something that happens `p` percent of the time, use + +> `if (rand.nextInt(100) < p) { _...do something..._ }` + +#### Getting input + +To get a number from the player, add this method to your program: + +```java + /** + * Prints the given message (which should ask the user for some integral + * quantity), and returns the number entered by the user. If the user's + * response isn't an integer, the question is repeated until the user + * does give a integer response. + * + * @param message The request to present to the user. + * @return The user's numeric response. + */ + int getNumber(String message) { + while (true) { + System.out.print(message); + try { + return scanner.nextInt(); + } + catch (InputMismatchException e) { + System.out.println("\"" + scanner.next() + "\" isn't a number!"); + } + } + } +``` + +Here is an example of how you can use this method: + +> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` + +### Structure of the solution + +* Project name: `Hammurabi` +* Package name: `hammurabi` +* Class names and method signatures: + * `class Hammurabi` + * `public static void main(String[] args)` + * Numerous other methods, as described above. + +The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. + +### Yo! Test it! + +You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! + +But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. + +### Credits + +Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html new file mode 100644 index 0000000..78bbf24 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html @@ -0,0 +1,299 @@ + + + + + + + CIT591 Hammurabi + + + + + +

CIT 591 Assignment 3: + Hammurabi
+ Fall 2010, David Matuszek

+ +

Purpose of this assignment

+ +
    +
  • To get you started using Java.
  • +
+ +

General idea of the assignment

+ +

Hammurabi is a very old computer game. Your job is to bring it into the + 21st century by writing it in Java.

+ +

Here are the standard instructions for the game:

+ +
+

Congratulations, you are the newest ruler of + ancient Samaria, elected for a ten year term of office. Your duties are to + dispense food, direct farming, and buy and sell land as needed to support + your people. Watch out for rat infestiations and the plague! Grain is the + general currency, measured in bushels. The following will help you in your + decisions:

+ +
    +
  • Each person needs at least 20 bushels of + grain per year to survive
  • + +
  • Each person can farm at most 10 acres of + land
  • + +
  • It takes 2 bushels of grain to farm an acre + of land
  • + +
  • The market price for land fluctuates + yearly
  • +
+ +

Rule wisely and you will be showered with + appreciation at the end of your term. Rule poorly and you will be kicked + out of office!

+
+ +

Details

+ +

Define a single class named Hammurabi. Use the following skeleton (but leave out the // comments):

+
package hammurabi;               // package declaration
+
+import java.util.Random;         // imports go here
+import java.util.Scanner;
+
+/**
+ * The Hammurabi game.
+ * @author Your name goes here
+ * @author Your partner's name goes here
+ */
+public class Hammurabi {         // must save in a file named Hammurabi.java
+    Random rand = new Random();  // this is an instance variable
+    Scanner scanner = new Scanner(System.in);
+
+    public static void main(String[] args) { // required in every Java program
+        new Hammurabi().playGame();
+    }
+
+    void playGame() {
+        // declare local variables here: grain, population, etc.
+        // statements go after the declations
+    }
+
+    //other methods go here
+}
+

Playing the game

+

Here is what you start the game with: +

    +
  • 100 people
  • +
  • 2800 bushels of grain in storage
  • +
  • 1000 acres of land
  • +
  • Land value is 19 bushels/acre

    +
  • +
+

Each year, print out a summary similar to the following:

+
+O great Hammurabi!
+You are in year 1 of your ten year rule.
+In the previous year 0 people starved to death.
+In the previous year 5 people entered the kingdom.
+The population is now 100.
+We harvested 3000 bushels at 3 bushels per acre.
+Rats destroyed 200 bushels, leaving 2800 bushels in storage.
+The city owns 1000 acres of land.
+Land is currently worth 19 bushels per acre.
+
+ +

The above summary represents the initial state, at the beginning of + the first year--that is, when you first take office, and before you do any of + the computations below). So, for example, the previous year (under a + different ruler) must have started with 95 people; none starved, and 5 + entered the kingdom, so as you enter office you rule 100 people.

+ +

Here's what your playGame method needs to do each year, for up to 10 years:

+ +
+

Ask the player the following questions. These questions should be asked in this order. Do not give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below:

+
+
int askHowManyAcresToBuy(int price, int bushels)
+
Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase.
+

+ int askHowManyAcresToSell(int acresOwned)
+
Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have.
+ Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn.
+

+ int askHowMuchGrainToFeedPeople(int bushels)
+
Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You can feed them more than they need to survive.
+

+ int askHowManyAcresToPlant(int acresOwned, int population, int bushels)
+
Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year.
+
+

For each + question, do "sanity checking"; that is, test whether the answer is + possible (you have enough grain, you have enough people to do the planting + etc.), and keep asking until you get a possible value. (For example, + O Great Hammurabi, surely you jest! We have only 3415 bushels left!)

+ +

Then the method needs to determine:

+ +
    +
  1. If there is a plague, and how many people die from it.
  2. +
  3. How many people starved.
  4. +
  5. How many people came to the city.
  6. +
  7. How good the harvest is.
  8. +
  9. If you have a problem with rats, and how much grain they eat.
  10. +
  11. How much land costs (for deciding what to do next).
  12. +
+

These can all be local variables of your playGame method.

+

Use the following methods, in this order, to make the necessary calculations:

+
+
int plagueDeaths(int population)
+
Each year, there is a 15% chance of a horrible plague. When this + happens, half your people die. Return the number of plague deaths (possibly zero).
+

+ int starvationDeaths(int population, int bushelsFedToPeople)
+
Each person needs 20 bushels of grain to survive. If you feed them + more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero).
+

+ boolean uprising(int population, int howManyPeopleStarved)
+
Return true if more than + 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.)
+

+ int immigrants(int population, int acresOwned, int grainInStorage)
+
Nobody will come to the city if people are starving (so don't call this method). If everyone is + well fed, compute how many people come to the city as: (20 * number of acres you have + amount of grain you have in + storage) / (100 * population) + 1.
+

+ int harvest(int acres, int bushelsUsedAsSeed)
+
Choose a random integer between 1 and 6, inclusive. Each acre that was planted + with seed will yield this many bushels of grain. (Example: if you planted + 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested.
+

+ int grainEatenByRats(int bushels)
+
There is a 40% chance that you will have a rat infestation. When this + happens, rats will eat somewhere between 10% and 30% of your + grain. Return the amount of grain eaten by rats (possibly zero).
+

+ int newCostOfLand()
+
The price of land is random, and ranges from 17 to 23 bushels per + acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell + land.)
+
+
+

Do these computations, in this order, for each of ten years. Each + computation should be done in a separate method, and none of these methods + should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it.

+ +

When the computations are finished, call a method printSummary to print the + summary for the year. This method will take several parameters.

+ + +

When the game ends , use a method finalSummary to print out a final summary, and to tell the + player how good a job he/she did. I'll leave the details up to you, but the + usual evaluation is based on how many people starved, and how many acres per + person you end up with.

+

Your playGame method will be quite long, but very straightforward; it does very little but call other methods.

+

All the required arithmetic in this program should be integer. You + do not need doubles.

+ +

I suggest that you first get the simplest possible version of the program + running and tested out (that is, leave out things like rats, plagues, and + immigration), then add these things one at a time to a working + program, testing as you go.

+ +

Things you need to know:

+ +

Random numbers

+ +

To get a random number generator, you first need to import + java.util.Random (or java.util.*). Then, you can + create a random number generator with a statement such as:

+ +
+

static Random rand = new Random();

+
+ +

To get a new random number in the range 0..n-1, where + n is an int, call rand.nextInt(n). + To get a new random number in the range min..max, use + the expression rand.nextInt(max - min + 1) + min. You + can use the rand method in statements such as

+ +
+

myNewNumber = rand.nextInt(5);
+ if (rand.nextInt(100) < 15) { ... }

+
+ +

To do something that happens p percent of the time, use

+ +
+

if (rand.nextInt(100) < p) { ...do something... + }

+
+ +

Getting input

+

To get a number from the player, add this method to your program:

+
+/**
+ * Prints the given message (which should ask the user for some integral
+ * quantity), and returns the number entered by the user. If the user's
+ * response isn't an integer, the question is repeated until the user
+ * does give a integer response.
+ * 
+ * @param message The request to present to the user.
+ * @return The user's numeric response.
+ */
+ int getNumber(String message) {
+    while (true) {
+        System.out.print(message);
+        try {
+            return scanner.nextInt();
+        }
+        catch (InputMismatchException e) {
+            System.out.println("\"" + scanner.next() + "\" isn't a number!");
+        }
+    }
+}
+
+ +

Here is an example of how you can use this method:

+ +
+

sell = getNumber("O great Hammurabi, how many acres shall you sell?");

+
+ +

Structure of the assignment:

+ +
    +
  • Project name: Hammurabi
  • + +
  • Package name: hammurabi
  • + +
  • Class names and method signatures: + +
      +
    • + class Hammurabi + +
        +
      • public static void main(String[] args)
      • + +
      • Numerous other methods, as described above.
      • +
      +
    • +
    +
  • + +
+ +

The above are requirements. The methods that do calculations, not input/output, will be tested by my test methods, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument names are irrelevant). You may have additional methods if you wish.

+ +

Due date:

+ +

Thursday, October 21, before midnight. Turn in your zipped assignment via + Blackboard. Email submissions will incur the wrath of Hammurabi (and won't be graded).

+ + + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md new file mode 100644 index 0000000..796d85c --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md @@ -0,0 +1,6 @@ +# Notes + +from the original Dave Matuszek course of 2010. + +https://www.cis.upenn.edu/~matuszek/cit591-2010/Assignments/06-hammurabi.html + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml new file mode 100644 index 0000000..d789654 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + + io.zipcoder + MicroLabs-Loops + 1.0-SNAPSHOT + + + + + junit + junit + 4.13.2 + + + + + + 1.8 + 1.8 + + \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore new file mode 100644 index 0000000..a1c2a23 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore @@ -0,0 +1,23 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE new file mode 100644 index 0000000..22474e4 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Zip Code Wilmington Core + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md new file mode 100644 index 0000000..e4672c9 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md @@ -0,0 +1,228 @@ +# hamurabi +an ancient (in more ways than one) computer game (text) + +## General idea of the lab + +*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. + +Here are the standard instructions for the game: + +> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** +> +> * **Each person needs at least 20 bushels of grain per year to survive** +> * **Each person can farm at most 10 acres of land** +> * **It takes 2 bushels of grain to farm an acre of land** +> * **The market price for land fluctuates yearly** +> +> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** + +### Maven + +There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. + +### Details + +Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): + +```java +package hammurabi; // package declaration +import java.util.Random; // imports go here +import java.util.Scanner; + +public class Hammurabi { // must save in a file named Hammurabi.java + Random rand = new Random(); // this is an instance variable + Scanner scanner = new Scanner(System.in); + + public static void main(String\[\] args) { // required in every Java program + new Hammurabi().playGame(); + } + + void playGame() { + // declare local variables here: grain, population, etc. + // statements go after the declations + } + + //other methods go here +} +``` + +### Playing the game + +Here is what you start the game with: + +* 100 people +* 2800 bushels of grain in storage +* 1000 acres of land +* Land value is 19 bushels/acre + + +Each year, print out a summary similar to the following: + + O great Hammurabi! + You are in year 1 of your ten year rule. + In the previous year 0 people starved to death. + In the previous year 5 people entered the kingdom. + The population is now 100. + We harvested 3000 bushels at 3 bushels per acre. + Rats destroyed 200 bushels, leaving 2800 bushels in storage. + The city owns 1000 acres of land. + Land is currently worth 19 bushels per acre. + +The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. + +Here's what your `playGame` method needs to do each year, for up to 10 years: + +> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: +> +> `int askHowManyAcresToBuy(int price, int bushels)` +> +> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. +> +> ` +> int askHowManyAcresToSell(int acresOwned)` +> +> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. +> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. +> +> ` +> int askHowMuchGrainToFeedPeople(int bushels)` +> +> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. +> +> ` +> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` +> +> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. +> +> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) +> +> Then the method needs to determine: +> +> 1. If there is a plague, and how many people die from it. +> 2. How many people starved. +> 3. How many people came to the city. +> 4. How good the harvest is. +> 5. If you have a problem with rats, and how much grain they eat. +> 6. How much land costs (for deciding what to do next). +> +> These can all be local variables of your `playGame` method. +> +> Use the following methods, **in this order,** to make the necessary calculations: +> +> `int plagueDeaths(int population)` +> +> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). +> +> ` +> int starvationDeaths(int population, int bushelsFedToPeople)` +> +> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). +> +> ` +> boolean uprising(int population, int howManyPeopleStarved)` +> +> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) +> +> ` +> int immigrants(int population, int acresOwned, int grainInStorage)` +> +> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. +> +> ` +> int harvest(int acres, int bushelsUsedAsSeed)` +> +> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. +> +> ` +> int grainEatenByRats(int bushels)` +> +> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). +> +> ` +> int newCostOfLand()` +> +> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) + +Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. + +When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. + +When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. + +Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. + +All the required arithmetic in this program should be **integer**. You do not need doubles. + +### Urgent! + +> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. + +### Things you need to know: + +#### Random numbers + +To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: + +> `static Random rand = new Random();` + +To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as + +> `myNewNumber = rand.nextInt(5); +> if (rand.nextInt(100) < 15) { ... }` + +To do something that happens `p` percent of the time, use + +> `if (rand.nextInt(100) < p) { _...do something..._ }` + +#### Getting input + +To get a number from the player, add this method to your program: + +```java + /** + * Prints the given message (which should ask the user for some integral + * quantity), and returns the number entered by the user. If the user's + * response isn't an integer, the question is repeated until the user + * does give a integer response. + * + * @param message The request to present to the user. + * @return The user's numeric response. + */ + int getNumber(String message) { + while (true) { + System.out.print(message); + try { + return scanner.nextInt(); + } + catch (InputMismatchException e) { + System.out.println("\"" + scanner.next() + "\" isn't a number!"); + } + } + } +``` + +Here is an example of how you can use this method: + +> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` + +### Structure of the solution + +* Project name: `Hammurabi` +* Package name: `hammurabi` +* Class names and method signatures: + * `class Hammurabi` + * `public static void main(String[] args)` + * Numerous other methods, as described above. + +The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. + +### Yo! Test it! + +You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! + +But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. + +### Credits + +Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html new file mode 100644 index 0000000..78bbf24 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html @@ -0,0 +1,299 @@ + + + + + + + CIT591 Hammurabi + + + + + +

CIT 591 Assignment 3: + Hammurabi
+ Fall 2010, David Matuszek

+ +

Purpose of this assignment

+ +
    +
  • To get you started using Java.
  • +
+ +

General idea of the assignment

+ +

Hammurabi is a very old computer game. Your job is to bring it into the + 21st century by writing it in Java.

+ +

Here are the standard instructions for the game:

+ +
+

Congratulations, you are the newest ruler of + ancient Samaria, elected for a ten year term of office. Your duties are to + dispense food, direct farming, and buy and sell land as needed to support + your people. Watch out for rat infestiations and the plague! Grain is the + general currency, measured in bushels. The following will help you in your + decisions:

+ +
    +
  • Each person needs at least 20 bushels of + grain per year to survive
  • + +
  • Each person can farm at most 10 acres of + land
  • + +
  • It takes 2 bushels of grain to farm an acre + of land
  • + +
  • The market price for land fluctuates + yearly
  • +
+ +

Rule wisely and you will be showered with + appreciation at the end of your term. Rule poorly and you will be kicked + out of office!

+
+ +

Details

+ +

Define a single class named Hammurabi. Use the following skeleton (but leave out the // comments):

+
package hammurabi;               // package declaration
+
+import java.util.Random;         // imports go here
+import java.util.Scanner;
+
+/**
+ * The Hammurabi game.
+ * @author Your name goes here
+ * @author Your partner's name goes here
+ */
+public class Hammurabi {         // must save in a file named Hammurabi.java
+    Random rand = new Random();  // this is an instance variable
+    Scanner scanner = new Scanner(System.in);
+
+    public static void main(String[] args) { // required in every Java program
+        new Hammurabi().playGame();
+    }
+
+    void playGame() {
+        // declare local variables here: grain, population, etc.
+        // statements go after the declations
+    }
+
+    //other methods go here
+}
+

Playing the game

+

Here is what you start the game with: +

    +
  • 100 people
  • +
  • 2800 bushels of grain in storage
  • +
  • 1000 acres of land
  • +
  • Land value is 19 bushels/acre

    +
  • +
+

Each year, print out a summary similar to the following:

+
+O great Hammurabi!
+You are in year 1 of your ten year rule.
+In the previous year 0 people starved to death.
+In the previous year 5 people entered the kingdom.
+The population is now 100.
+We harvested 3000 bushels at 3 bushels per acre.
+Rats destroyed 200 bushels, leaving 2800 bushels in storage.
+The city owns 1000 acres of land.
+Land is currently worth 19 bushels per acre.
+
+ +

The above summary represents the initial state, at the beginning of + the first year--that is, when you first take office, and before you do any of + the computations below). So, for example, the previous year (under a + different ruler) must have started with 95 people; none starved, and 5 + entered the kingdom, so as you enter office you rule 100 people.

+ +

Here's what your playGame method needs to do each year, for up to 10 years:

+ +
+

Ask the player the following questions. These questions should be asked in this order. Do not give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below:

+
+
int askHowManyAcresToBuy(int price, int bushels)
+
Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase.
+

+ int askHowManyAcresToSell(int acresOwned)
+
Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have.
+ Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn.
+

+ int askHowMuchGrainToFeedPeople(int bushels)
+
Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You can feed them more than they need to survive.
+

+ int askHowManyAcresToPlant(int acresOwned, int population, int bushels)
+
Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year.
+
+

For each + question, do "sanity checking"; that is, test whether the answer is + possible (you have enough grain, you have enough people to do the planting + etc.), and keep asking until you get a possible value. (For example, + O Great Hammurabi, surely you jest! We have only 3415 bushels left!)

+ +

Then the method needs to determine:

+ +
    +
  1. If there is a plague, and how many people die from it.
  2. +
  3. How many people starved.
  4. +
  5. How many people came to the city.
  6. +
  7. How good the harvest is.
  8. +
  9. If you have a problem with rats, and how much grain they eat.
  10. +
  11. How much land costs (for deciding what to do next).
  12. +
+

These can all be local variables of your playGame method.

+

Use the following methods, in this order, to make the necessary calculations:

+
+
int plagueDeaths(int population)
+
Each year, there is a 15% chance of a horrible plague. When this + happens, half your people die. Return the number of plague deaths (possibly zero).
+

+ int starvationDeaths(int population, int bushelsFedToPeople)
+
Each person needs 20 bushels of grain to survive. If you feed them + more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero).
+

+ boolean uprising(int population, int howManyPeopleStarved)
+
Return true if more than + 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.)
+

+ int immigrants(int population, int acresOwned, int grainInStorage)
+
Nobody will come to the city if people are starving (so don't call this method). If everyone is + well fed, compute how many people come to the city as: (20 * number of acres you have + amount of grain you have in + storage) / (100 * population) + 1.
+

+ int harvest(int acres, int bushelsUsedAsSeed)
+
Choose a random integer between 1 and 6, inclusive. Each acre that was planted + with seed will yield this many bushels of grain. (Example: if you planted + 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested.
+

+ int grainEatenByRats(int bushels)
+
There is a 40% chance that you will have a rat infestation. When this + happens, rats will eat somewhere between 10% and 30% of your + grain. Return the amount of grain eaten by rats (possibly zero).
+

+ int newCostOfLand()
+
The price of land is random, and ranges from 17 to 23 bushels per + acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell + land.)
+
+
+

Do these computations, in this order, for each of ten years. Each + computation should be done in a separate method, and none of these methods + should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it.

+ +

When the computations are finished, call a method printSummary to print the + summary for the year. This method will take several parameters.

+ + +

When the game ends , use a method finalSummary to print out a final summary, and to tell the + player how good a job he/she did. I'll leave the details up to you, but the + usual evaluation is based on how many people starved, and how many acres per + person you end up with.

+

Your playGame method will be quite long, but very straightforward; it does very little but call other methods.

+

All the required arithmetic in this program should be integer. You + do not need doubles.

+ +

I suggest that you first get the simplest possible version of the program + running and tested out (that is, leave out things like rats, plagues, and + immigration), then add these things one at a time to a working + program, testing as you go.

+ +

Things you need to know:

+ +

Random numbers

+ +

To get a random number generator, you first need to import + java.util.Random (or java.util.*). Then, you can + create a random number generator with a statement such as:

+ +
+

static Random rand = new Random();

+
+ +

To get a new random number in the range 0..n-1, where + n is an int, call rand.nextInt(n). + To get a new random number in the range min..max, use + the expression rand.nextInt(max - min + 1) + min. You + can use the rand method in statements such as

+ +
+

myNewNumber = rand.nextInt(5);
+ if (rand.nextInt(100) < 15) { ... }

+
+ +

To do something that happens p percent of the time, use

+ +
+

if (rand.nextInt(100) < p) { ...do something... + }

+
+ +

Getting input

+

To get a number from the player, add this method to your program:

+
+/**
+ * Prints the given message (which should ask the user for some integral
+ * quantity), and returns the number entered by the user. If the user's
+ * response isn't an integer, the question is repeated until the user
+ * does give a integer response.
+ * 
+ * @param message The request to present to the user.
+ * @return The user's numeric response.
+ */
+ int getNumber(String message) {
+    while (true) {
+        System.out.print(message);
+        try {
+            return scanner.nextInt();
+        }
+        catch (InputMismatchException e) {
+            System.out.println("\"" + scanner.next() + "\" isn't a number!");
+        }
+    }
+}
+
+ +

Here is an example of how you can use this method:

+ +
+

sell = getNumber("O great Hammurabi, how many acres shall you sell?");

+
+ +

Structure of the assignment:

+ +
    +
  • Project name: Hammurabi
  • + +
  • Package name: hammurabi
  • + +
  • Class names and method signatures: + +
      +
    • + class Hammurabi + +
        +
      • public static void main(String[] args)
      • + +
      • Numerous other methods, as described above.
      • +
      +
    • +
    +
  • + +
+ +

The above are requirements. The methods that do calculations, not input/output, will be tested by my test methods, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument names are irrelevant). You may have additional methods if you wish.

+ +

Due date:

+ +

Thursday, October 21, before midnight. Turn in your zipped assignment via + Blackboard. Email submissions will incur the wrath of Hammurabi (and won't be graded).

+ + + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md new file mode 100644 index 0000000..796d85c --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md @@ -0,0 +1,6 @@ +# Notes + +from the original Dave Matuszek course of 2010. + +https://www.cis.upenn.edu/~matuszek/cit591-2010/Assignments/06-hammurabi.html + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml new file mode 100644 index 0000000..d789654 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + + io.zipcoder + MicroLabs-Loops + 1.0-SNAPSHOT + + + + + junit + junit + 4.13.2 + + + + + + 1.8 + 1.8 + + \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore new file mode 100644 index 0000000..a1c2a23 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore @@ -0,0 +1,23 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE new file mode 100644 index 0000000..22474e4 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Zip Code Wilmington Core + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md new file mode 100644 index 0000000..e4672c9 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md @@ -0,0 +1,228 @@ +# hamurabi +an ancient (in more ways than one) computer game (text) + +## General idea of the lab + +*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. + +Here are the standard instructions for the game: + +> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** +> +> * **Each person needs at least 20 bushels of grain per year to survive** +> * **Each person can farm at most 10 acres of land** +> * **It takes 2 bushels of grain to farm an acre of land** +> * **The market price for land fluctuates yearly** +> +> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** + +### Maven + +There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. + +### Details + +Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): + +```java +package hammurabi; // package declaration +import java.util.Random; // imports go here +import java.util.Scanner; + +public class Hammurabi { // must save in a file named Hammurabi.java + Random rand = new Random(); // this is an instance variable + Scanner scanner = new Scanner(System.in); + + public static void main(String\[\] args) { // required in every Java program + new Hammurabi().playGame(); + } + + void playGame() { + // declare local variables here: grain, population, etc. + // statements go after the declations + } + + //other methods go here +} +``` + +### Playing the game + +Here is what you start the game with: + +* 100 people +* 2800 bushels of grain in storage +* 1000 acres of land +* Land value is 19 bushels/acre + + +Each year, print out a summary similar to the following: + + O great Hammurabi! + You are in year 1 of your ten year rule. + In the previous year 0 people starved to death. + In the previous year 5 people entered the kingdom. + The population is now 100. + We harvested 3000 bushels at 3 bushels per acre. + Rats destroyed 200 bushels, leaving 2800 bushels in storage. + The city owns 1000 acres of land. + Land is currently worth 19 bushels per acre. + +The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. + +Here's what your `playGame` method needs to do each year, for up to 10 years: + +> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: +> +> `int askHowManyAcresToBuy(int price, int bushels)` +> +> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. +> +> ` +> int askHowManyAcresToSell(int acresOwned)` +> +> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. +> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. +> +> ` +> int askHowMuchGrainToFeedPeople(int bushels)` +> +> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. +> +> ` +> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` +> +> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. +> +> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) +> +> Then the method needs to determine: +> +> 1. If there is a plague, and how many people die from it. +> 2. How many people starved. +> 3. How many people came to the city. +> 4. How good the harvest is. +> 5. If you have a problem with rats, and how much grain they eat. +> 6. How much land costs (for deciding what to do next). +> +> These can all be local variables of your `playGame` method. +> +> Use the following methods, **in this order,** to make the necessary calculations: +> +> `int plagueDeaths(int population)` +> +> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). +> +> ` +> int starvationDeaths(int population, int bushelsFedToPeople)` +> +> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). +> +> ` +> boolean uprising(int population, int howManyPeopleStarved)` +> +> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) +> +> ` +> int immigrants(int population, int acresOwned, int grainInStorage)` +> +> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. +> +> ` +> int harvest(int acres, int bushelsUsedAsSeed)` +> +> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. +> +> ` +> int grainEatenByRats(int bushels)` +> +> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). +> +> ` +> int newCostOfLand()` +> +> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) + +Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. + +When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. + +When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. + +Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. + +All the required arithmetic in this program should be **integer**. You do not need doubles. + +### Urgent! + +> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. + +### Things you need to know: + +#### Random numbers + +To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: + +> `static Random rand = new Random();` + +To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as + +> `myNewNumber = rand.nextInt(5); +> if (rand.nextInt(100) < 15) { ... }` + +To do something that happens `p` percent of the time, use + +> `if (rand.nextInt(100) < p) { _...do something..._ }` + +#### Getting input + +To get a number from the player, add this method to your program: + +```java + /** + * Prints the given message (which should ask the user for some integral + * quantity), and returns the number entered by the user. If the user's + * response isn't an integer, the question is repeated until the user + * does give a integer response. + * + * @param message The request to present to the user. + * @return The user's numeric response. + */ + int getNumber(String message) { + while (true) { + System.out.print(message); + try { + return scanner.nextInt(); + } + catch (InputMismatchException e) { + System.out.println("\"" + scanner.next() + "\" isn't a number!"); + } + } + } +``` + +Here is an example of how you can use this method: + +> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` + +### Structure of the solution + +* Project name: `Hammurabi` +* Package name: `hammurabi` +* Class names and method signatures: + * `class Hammurabi` + * `public static void main(String[] args)` + * Numerous other methods, as described above. + +The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. + +### Yo! Test it! + +You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! + +But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. + +### Credits + +Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html new file mode 100644 index 0000000..78bbf24 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html @@ -0,0 +1,299 @@ + + + + + + + CIT591 Hammurabi + + + + + +

CIT 591 Assignment 3: + Hammurabi
+ Fall 2010, David Matuszek

+ +

Purpose of this assignment

+ +
    +
  • To get you started using Java.
  • +
+ +

General idea of the assignment

+ +

Hammurabi is a very old computer game. Your job is to bring it into the + 21st century by writing it in Java.

+ +

Here are the standard instructions for the game:

+ +
+

Congratulations, you are the newest ruler of + ancient Samaria, elected for a ten year term of office. Your duties are to + dispense food, direct farming, and buy and sell land as needed to support + your people. Watch out for rat infestiations and the plague! Grain is the + general currency, measured in bushels. The following will help you in your + decisions:

+ +
    +
  • Each person needs at least 20 bushels of + grain per year to survive
  • + +
  • Each person can farm at most 10 acres of + land
  • + +
  • It takes 2 bushels of grain to farm an acre + of land
  • + +
  • The market price for land fluctuates + yearly
  • +
+ +

Rule wisely and you will be showered with + appreciation at the end of your term. Rule poorly and you will be kicked + out of office!

+
+ +

Details

+ +

Define a single class named Hammurabi. Use the following skeleton (but leave out the // comments):

+
package hammurabi;               // package declaration
+
+import java.util.Random;         // imports go here
+import java.util.Scanner;
+
+/**
+ * The Hammurabi game.
+ * @author Your name goes here
+ * @author Your partner's name goes here
+ */
+public class Hammurabi {         // must save in a file named Hammurabi.java
+    Random rand = new Random();  // this is an instance variable
+    Scanner scanner = new Scanner(System.in);
+
+    public static void main(String[] args) { // required in every Java program
+        new Hammurabi().playGame();
+    }
+
+    void playGame() {
+        // declare local variables here: grain, population, etc.
+        // statements go after the declations
+    }
+
+    //other methods go here
+}
+

Playing the game

+

Here is what you start the game with: +

    +
  • 100 people
  • +
  • 2800 bushels of grain in storage
  • +
  • 1000 acres of land
  • +
  • Land value is 19 bushels/acre

    +
  • +
+

Each year, print out a summary similar to the following:

+
+O great Hammurabi!
+You are in year 1 of your ten year rule.
+In the previous year 0 people starved to death.
+In the previous year 5 people entered the kingdom.
+The population is now 100.
+We harvested 3000 bushels at 3 bushels per acre.
+Rats destroyed 200 bushels, leaving 2800 bushels in storage.
+The city owns 1000 acres of land.
+Land is currently worth 19 bushels per acre.
+
+ +

The above summary represents the initial state, at the beginning of + the first year--that is, when you first take office, and before you do any of + the computations below). So, for example, the previous year (under a + different ruler) must have started with 95 people; none starved, and 5 + entered the kingdom, so as you enter office you rule 100 people.

+ +

Here's what your playGame method needs to do each year, for up to 10 years:

+ +
+

Ask the player the following questions. These questions should be asked in this order. Do not give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below:

+
+
int askHowManyAcresToBuy(int price, int bushels)
+
Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase.
+

+ int askHowManyAcresToSell(int acresOwned)
+
Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have.
+ Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn.
+

+ int askHowMuchGrainToFeedPeople(int bushels)
+
Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You can feed them more than they need to survive.
+

+ int askHowManyAcresToPlant(int acresOwned, int population, int bushels)
+
Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year.
+
+

For each + question, do "sanity checking"; that is, test whether the answer is + possible (you have enough grain, you have enough people to do the planting + etc.), and keep asking until you get a possible value. (For example, + O Great Hammurabi, surely you jest! We have only 3415 bushels left!)

+ +

Then the method needs to determine:

+ +
    +
  1. If there is a plague, and how many people die from it.
  2. +
  3. How many people starved.
  4. +
  5. How many people came to the city.
  6. +
  7. How good the harvest is.
  8. +
  9. If you have a problem with rats, and how much grain they eat.
  10. +
  11. How much land costs (for deciding what to do next).
  12. +
+

These can all be local variables of your playGame method.

+

Use the following methods, in this order, to make the necessary calculations:

+
+
int plagueDeaths(int population)
+
Each year, there is a 15% chance of a horrible plague. When this + happens, half your people die. Return the number of plague deaths (possibly zero).
+

+ int starvationDeaths(int population, int bushelsFedToPeople)
+
Each person needs 20 bushels of grain to survive. If you feed them + more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero).
+

+ boolean uprising(int population, int howManyPeopleStarved)
+
Return true if more than + 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.)
+

+ int immigrants(int population, int acresOwned, int grainInStorage)
+
Nobody will come to the city if people are starving (so don't call this method). If everyone is + well fed, compute how many people come to the city as: (20 * number of acres you have + amount of grain you have in + storage) / (100 * population) + 1.
+

+ int harvest(int acres, int bushelsUsedAsSeed)
+
Choose a random integer between 1 and 6, inclusive. Each acre that was planted + with seed will yield this many bushels of grain. (Example: if you planted + 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested.
+

+ int grainEatenByRats(int bushels)
+
There is a 40% chance that you will have a rat infestation. When this + happens, rats will eat somewhere between 10% and 30% of your + grain. Return the amount of grain eaten by rats (possibly zero).
+

+ int newCostOfLand()
+
The price of land is random, and ranges from 17 to 23 bushels per + acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell + land.)
+
+
+

Do these computations, in this order, for each of ten years. Each + computation should be done in a separate method, and none of these methods + should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it.

+ +

When the computations are finished, call a method printSummary to print the + summary for the year. This method will take several parameters.

+ + +

When the game ends , use a method finalSummary to print out a final summary, and to tell the + player how good a job he/she did. I'll leave the details up to you, but the + usual evaluation is based on how many people starved, and how many acres per + person you end up with.

+

Your playGame method will be quite long, but very straightforward; it does very little but call other methods.

+

All the required arithmetic in this program should be integer. You + do not need doubles.

+ +

I suggest that you first get the simplest possible version of the program + running and tested out (that is, leave out things like rats, plagues, and + immigration), then add these things one at a time to a working + program, testing as you go.

+ +

Things you need to know:

+ +

Random numbers

+ +

To get a random number generator, you first need to import + java.util.Random (or java.util.*). Then, you can + create a random number generator with a statement such as:

+ +
+

static Random rand = new Random();

+
+ +

To get a new random number in the range 0..n-1, where + n is an int, call rand.nextInt(n). + To get a new random number in the range min..max, use + the expression rand.nextInt(max - min + 1) + min. You + can use the rand method in statements such as

+ +
+

myNewNumber = rand.nextInt(5);
+ if (rand.nextInt(100) < 15) { ... }

+
+ +

To do something that happens p percent of the time, use

+ +
+

if (rand.nextInt(100) < p) { ...do something... + }

+
+ +

Getting input

+

To get a number from the player, add this method to your program:

+
+/**
+ * Prints the given message (which should ask the user for some integral
+ * quantity), and returns the number entered by the user. If the user's
+ * response isn't an integer, the question is repeated until the user
+ * does give a integer response.
+ * 
+ * @param message The request to present to the user.
+ * @return The user's numeric response.
+ */
+ int getNumber(String message) {
+    while (true) {
+        System.out.print(message);
+        try {
+            return scanner.nextInt();
+        }
+        catch (InputMismatchException e) {
+            System.out.println("\"" + scanner.next() + "\" isn't a number!");
+        }
+    }
+}
+
+ +

Here is an example of how you can use this method:

+ +
+

sell = getNumber("O great Hammurabi, how many acres shall you sell?");

+
+ +

Structure of the assignment:

+ +
    +
  • Project name: Hammurabi
  • + +
  • Package name: hammurabi
  • + +
  • Class names and method signatures: + +
      +
    • + class Hammurabi + +
        +
      • public static void main(String[] args)
      • + +
      • Numerous other methods, as described above.
      • +
      +
    • +
    +
  • + +
+ +

The above are requirements. The methods that do calculations, not input/output, will be tested by my test methods, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument names are irrelevant). You may have additional methods if you wish.

+ +

Due date:

+ +

Thursday, October 21, before midnight. Turn in your zipped assignment via + Blackboard. Email submissions will incur the wrath of Hammurabi (and won't be graded).

+ + + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md new file mode 100644 index 0000000..796d85c --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md @@ -0,0 +1,6 @@ +# Notes + +from the original Dave Matuszek course of 2010. + +https://www.cis.upenn.edu/~matuszek/cit591-2010/Assignments/06-hammurabi.html + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml new file mode 100644 index 0000000..d789654 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + + io.zipcoder + MicroLabs-Loops + 1.0-SNAPSHOT + + + + + junit + junit + 4.13.2 + + + + + + 1.8 + 1.8 + + \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore new file mode 100644 index 0000000..a1c2a23 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore @@ -0,0 +1,23 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE new file mode 100644 index 0000000..22474e4 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Zip Code Wilmington Core + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md new file mode 100644 index 0000000..e4672c9 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md @@ -0,0 +1,228 @@ +# hamurabi +an ancient (in more ways than one) computer game (text) + +## General idea of the lab + +*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. + +Here are the standard instructions for the game: + +> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** +> +> * **Each person needs at least 20 bushels of grain per year to survive** +> * **Each person can farm at most 10 acres of land** +> * **It takes 2 bushels of grain to farm an acre of land** +> * **The market price for land fluctuates yearly** +> +> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** + +### Maven + +There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. + +### Details + +Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): + +```java +package hammurabi; // package declaration +import java.util.Random; // imports go here +import java.util.Scanner; + +public class Hammurabi { // must save in a file named Hammurabi.java + Random rand = new Random(); // this is an instance variable + Scanner scanner = new Scanner(System.in); + + public static void main(String\[\] args) { // required in every Java program + new Hammurabi().playGame(); + } + + void playGame() { + // declare local variables here: grain, population, etc. + // statements go after the declations + } + + //other methods go here +} +``` + +### Playing the game + +Here is what you start the game with: + +* 100 people +* 2800 bushels of grain in storage +* 1000 acres of land +* Land value is 19 bushels/acre + + +Each year, print out a summary similar to the following: + + O great Hammurabi! + You are in year 1 of your ten year rule. + In the previous year 0 people starved to death. + In the previous year 5 people entered the kingdom. + The population is now 100. + We harvested 3000 bushels at 3 bushels per acre. + Rats destroyed 200 bushels, leaving 2800 bushels in storage. + The city owns 1000 acres of land. + Land is currently worth 19 bushels per acre. + +The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. + +Here's what your `playGame` method needs to do each year, for up to 10 years: + +> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: +> +> `int askHowManyAcresToBuy(int price, int bushels)` +> +> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. +> +> ` +> int askHowManyAcresToSell(int acresOwned)` +> +> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. +> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. +> +> ` +> int askHowMuchGrainToFeedPeople(int bushels)` +> +> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. +> +> ` +> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` +> +> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. +> +> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) +> +> Then the method needs to determine: +> +> 1. If there is a plague, and how many people die from it. +> 2. How many people starved. +> 3. How many people came to the city. +> 4. How good the harvest is. +> 5. If you have a problem with rats, and how much grain they eat. +> 6. How much land costs (for deciding what to do next). +> +> These can all be local variables of your `playGame` method. +> +> Use the following methods, **in this order,** to make the necessary calculations: +> +> `int plagueDeaths(int population)` +> +> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). +> +> ` +> int starvationDeaths(int population, int bushelsFedToPeople)` +> +> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). +> +> ` +> boolean uprising(int population, int howManyPeopleStarved)` +> +> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) +> +> ` +> int immigrants(int population, int acresOwned, int grainInStorage)` +> +> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. +> +> ` +> int harvest(int acres, int bushelsUsedAsSeed)` +> +> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. +> +> ` +> int grainEatenByRats(int bushels)` +> +> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). +> +> ` +> int newCostOfLand()` +> +> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) + +Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. + +When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. + +When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. + +Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. + +All the required arithmetic in this program should be **integer**. You do not need doubles. + +### Urgent! + +> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. + +### Things you need to know: + +#### Random numbers + +To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: + +> `static Random rand = new Random();` + +To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as + +> `myNewNumber = rand.nextInt(5); +> if (rand.nextInt(100) < 15) { ... }` + +To do something that happens `p` percent of the time, use + +> `if (rand.nextInt(100) < p) { _...do something..._ }` + +#### Getting input + +To get a number from the player, add this method to your program: + +```java + /** + * Prints the given message (which should ask the user for some integral + * quantity), and returns the number entered by the user. If the user's + * response isn't an integer, the question is repeated until the user + * does give a integer response. + * + * @param message The request to present to the user. + * @return The user's numeric response. + */ + int getNumber(String message) { + while (true) { + System.out.print(message); + try { + return scanner.nextInt(); + } + catch (InputMismatchException e) { + System.out.println("\"" + scanner.next() + "\" isn't a number!"); + } + } + } +``` + +Here is an example of how you can use this method: + +> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` + +### Structure of the solution + +* Project name: `Hammurabi` +* Package name: `hammurabi` +* Class names and method signatures: + * `class Hammurabi` + * `public static void main(String[] args)` + * Numerous other methods, as described above. + +The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. + +### Yo! Test it! + +You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! + +But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. + +### Credits + +Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html new file mode 100644 index 0000000..78bbf24 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html @@ -0,0 +1,299 @@ + + + + + + + CIT591 Hammurabi + + + + + +

CIT 591 Assignment 3: + Hammurabi
+ Fall 2010, David Matuszek

+ +

Purpose of this assignment

+ +
    +
  • To get you started using Java.
  • +
+ +

General idea of the assignment

+ +

Hammurabi is a very old computer game. Your job is to bring it into the + 21st century by writing it in Java.

+ +

Here are the standard instructions for the game:

+ +
+

Congratulations, you are the newest ruler of + ancient Samaria, elected for a ten year term of office. Your duties are to + dispense food, direct farming, and buy and sell land as needed to support + your people. Watch out for rat infestiations and the plague! Grain is the + general currency, measured in bushels. The following will help you in your + decisions:

+ +
    +
  • Each person needs at least 20 bushels of + grain per year to survive
  • + +
  • Each person can farm at most 10 acres of + land
  • + +
  • It takes 2 bushels of grain to farm an acre + of land
  • + +
  • The market price for land fluctuates + yearly
  • +
+ +

Rule wisely and you will be showered with + appreciation at the end of your term. Rule poorly and you will be kicked + out of office!

+
+ +

Details

+ +

Define a single class named Hammurabi. Use the following skeleton (but leave out the // comments):

+
package hammurabi;               // package declaration
+
+import java.util.Random;         // imports go here
+import java.util.Scanner;
+
+/**
+ * The Hammurabi game.
+ * @author Your name goes here
+ * @author Your partner's name goes here
+ */
+public class Hammurabi {         // must save in a file named Hammurabi.java
+    Random rand = new Random();  // this is an instance variable
+    Scanner scanner = new Scanner(System.in);
+
+    public static void main(String[] args) { // required in every Java program
+        new Hammurabi().playGame();
+    }
+
+    void playGame() {
+        // declare local variables here: grain, population, etc.
+        // statements go after the declations
+    }
+
+    //other methods go here
+}
+

Playing the game

+

Here is what you start the game with: +

    +
  • 100 people
  • +
  • 2800 bushels of grain in storage
  • +
  • 1000 acres of land
  • +
  • Land value is 19 bushels/acre

    +
  • +
+

Each year, print out a summary similar to the following:

+
+O great Hammurabi!
+You are in year 1 of your ten year rule.
+In the previous year 0 people starved to death.
+In the previous year 5 people entered the kingdom.
+The population is now 100.
+We harvested 3000 bushels at 3 bushels per acre.
+Rats destroyed 200 bushels, leaving 2800 bushels in storage.
+The city owns 1000 acres of land.
+Land is currently worth 19 bushels per acre.
+
+ +

The above summary represents the initial state, at the beginning of + the first year--that is, when you first take office, and before you do any of + the computations below). So, for example, the previous year (under a + different ruler) must have started with 95 people; none starved, and 5 + entered the kingdom, so as you enter office you rule 100 people.

+ +

Here's what your playGame method needs to do each year, for up to 10 years:

+ +
+

Ask the player the following questions. These questions should be asked in this order. Do not give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below:

+
+
int askHowManyAcresToBuy(int price, int bushels)
+
Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase.
+

+ int askHowManyAcresToSell(int acresOwned)
+
Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have.
+ Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn.
+

+ int askHowMuchGrainToFeedPeople(int bushels)
+
Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You can feed them more than they need to survive.
+

+ int askHowManyAcresToPlant(int acresOwned, int population, int bushels)
+
Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year.
+
+

For each + question, do "sanity checking"; that is, test whether the answer is + possible (you have enough grain, you have enough people to do the planting + etc.), and keep asking until you get a possible value. (For example, + O Great Hammurabi, surely you jest! We have only 3415 bushels left!)

+ +

Then the method needs to determine:

+ +
    +
  1. If there is a plague, and how many people die from it.
  2. +
  3. How many people starved.
  4. +
  5. How many people came to the city.
  6. +
  7. How good the harvest is.
  8. +
  9. If you have a problem with rats, and how much grain they eat.
  10. +
  11. How much land costs (for deciding what to do next).
  12. +
+

These can all be local variables of your playGame method.

+

Use the following methods, in this order, to make the necessary calculations:

+
+
int plagueDeaths(int population)
+
Each year, there is a 15% chance of a horrible plague. When this + happens, half your people die. Return the number of plague deaths (possibly zero).
+

+ int starvationDeaths(int population, int bushelsFedToPeople)
+
Each person needs 20 bushels of grain to survive. If you feed them + more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero).
+

+ boolean uprising(int population, int howManyPeopleStarved)
+
Return true if more than + 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.)
+

+ int immigrants(int population, int acresOwned, int grainInStorage)
+
Nobody will come to the city if people are starving (so don't call this method). If everyone is + well fed, compute how many people come to the city as: (20 * number of acres you have + amount of grain you have in + storage) / (100 * population) + 1.
+

+ int harvest(int acres, int bushelsUsedAsSeed)
+
Choose a random integer between 1 and 6, inclusive. Each acre that was planted + with seed will yield this many bushels of grain. (Example: if you planted + 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested.
+

+ int grainEatenByRats(int bushels)
+
There is a 40% chance that you will have a rat infestation. When this + happens, rats will eat somewhere between 10% and 30% of your + grain. Return the amount of grain eaten by rats (possibly zero).
+

+ int newCostOfLand()
+
The price of land is random, and ranges from 17 to 23 bushels per + acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell + land.)
+
+
+

Do these computations, in this order, for each of ten years. Each + computation should be done in a separate method, and none of these methods + should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it.

+ +

When the computations are finished, call a method printSummary to print the + summary for the year. This method will take several parameters.

+ + +

When the game ends , use a method finalSummary to print out a final summary, and to tell the + player how good a job he/she did. I'll leave the details up to you, but the + usual evaluation is based on how many people starved, and how many acres per + person you end up with.

+

Your playGame method will be quite long, but very straightforward; it does very little but call other methods.

+

All the required arithmetic in this program should be integer. You + do not need doubles.

+ +

I suggest that you first get the simplest possible version of the program + running and tested out (that is, leave out things like rats, plagues, and + immigration), then add these things one at a time to a working + program, testing as you go.

+ +

Things you need to know:

+ +

Random numbers

+ +

To get a random number generator, you first need to import + java.util.Random (or java.util.*). Then, you can + create a random number generator with a statement such as:

+ +
+

static Random rand = new Random();

+
+ +

To get a new random number in the range 0..n-1, where + n is an int, call rand.nextInt(n). + To get a new random number in the range min..max, use + the expression rand.nextInt(max - min + 1) + min. You + can use the rand method in statements such as

+ +
+

myNewNumber = rand.nextInt(5);
+ if (rand.nextInt(100) < 15) { ... }

+
+ +

To do something that happens p percent of the time, use

+ +
+

if (rand.nextInt(100) < p) { ...do something... + }

+
+ +

Getting input

+

To get a number from the player, add this method to your program:

+
+/**
+ * Prints the given message (which should ask the user for some integral
+ * quantity), and returns the number entered by the user. If the user's
+ * response isn't an integer, the question is repeated until the user
+ * does give a integer response.
+ * 
+ * @param message The request to present to the user.
+ * @return The user's numeric response.
+ */
+ int getNumber(String message) {
+    while (true) {
+        System.out.print(message);
+        try {
+            return scanner.nextInt();
+        }
+        catch (InputMismatchException e) {
+            System.out.println("\"" + scanner.next() + "\" isn't a number!");
+        }
+    }
+}
+
+ +

Here is an example of how you can use this method:

+ +
+

sell = getNumber("O great Hammurabi, how many acres shall you sell?");

+
+ +

Structure of the assignment:

+ +
    +
  • Project name: Hammurabi
  • + +
  • Package name: hammurabi
  • + +
  • Class names and method signatures: + +
      +
    • + class Hammurabi + +
        +
      • public static void main(String[] args)
      • + +
      • Numerous other methods, as described above.
      • +
      +
    • +
    +
  • + +
+ +

The above are requirements. The methods that do calculations, not input/output, will be tested by my test methods, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument names are irrelevant). You may have additional methods if you wish.

+ +

Due date:

+ +

Thursday, October 21, before midnight. Turn in your zipped assignment via + Blackboard. Email submissions will incur the wrath of Hammurabi (and won't be graded).

+ + + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md new file mode 100644 index 0000000..796d85c --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md @@ -0,0 +1,6 @@ +# Notes + +from the original Dave Matuszek course of 2010. + +https://www.cis.upenn.edu/~matuszek/cit591-2010/Assignments/06-hammurabi.html + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml new file mode 100644 index 0000000..d789654 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + + io.zipcoder + MicroLabs-Loops + 1.0-SNAPSHOT + + + + + junit + junit + 4.13.2 + + + + + + 1.8 + 1.8 + + \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore new file mode 100644 index 0000000..a1c2a23 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore @@ -0,0 +1,23 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE new file mode 100644 index 0000000..22474e4 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Zip Code Wilmington Core + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md new file mode 100644 index 0000000..e4672c9 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md @@ -0,0 +1,228 @@ +# hamurabi +an ancient (in more ways than one) computer game (text) + +## General idea of the lab + +*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. + +Here are the standard instructions for the game: + +> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** +> +> * **Each person needs at least 20 bushels of grain per year to survive** +> * **Each person can farm at most 10 acres of land** +> * **It takes 2 bushels of grain to farm an acre of land** +> * **The market price for land fluctuates yearly** +> +> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** + +### Maven + +There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. + +### Details + +Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): + +```java +package hammurabi; // package declaration +import java.util.Random; // imports go here +import java.util.Scanner; + +public class Hammurabi { // must save in a file named Hammurabi.java + Random rand = new Random(); // this is an instance variable + Scanner scanner = new Scanner(System.in); + + public static void main(String\[\] args) { // required in every Java program + new Hammurabi().playGame(); + } + + void playGame() { + // declare local variables here: grain, population, etc. + // statements go after the declations + } + + //other methods go here +} +``` + +### Playing the game + +Here is what you start the game with: + +* 100 people +* 2800 bushels of grain in storage +* 1000 acres of land +* Land value is 19 bushels/acre + + +Each year, print out a summary similar to the following: + + O great Hammurabi! + You are in year 1 of your ten year rule. + In the previous year 0 people starved to death. + In the previous year 5 people entered the kingdom. + The population is now 100. + We harvested 3000 bushels at 3 bushels per acre. + Rats destroyed 200 bushels, leaving 2800 bushels in storage. + The city owns 1000 acres of land. + Land is currently worth 19 bushels per acre. + +The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. + +Here's what your `playGame` method needs to do each year, for up to 10 years: + +> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: +> +> `int askHowManyAcresToBuy(int price, int bushels)` +> +> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. +> +> ` +> int askHowManyAcresToSell(int acresOwned)` +> +> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. +> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. +> +> ` +> int askHowMuchGrainToFeedPeople(int bushels)` +> +> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. +> +> ` +> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` +> +> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. +> +> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) +> +> Then the method needs to determine: +> +> 1. If there is a plague, and how many people die from it. +> 2. How many people starved. +> 3. How many people came to the city. +> 4. How good the harvest is. +> 5. If you have a problem with rats, and how much grain they eat. +> 6. How much land costs (for deciding what to do next). +> +> These can all be local variables of your `playGame` method. +> +> Use the following methods, **in this order,** to make the necessary calculations: +> +> `int plagueDeaths(int population)` +> +> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). +> +> ` +> int starvationDeaths(int population, int bushelsFedToPeople)` +> +> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). +> +> ` +> boolean uprising(int population, int howManyPeopleStarved)` +> +> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) +> +> ` +> int immigrants(int population, int acresOwned, int grainInStorage)` +> +> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. +> +> ` +> int harvest(int acres, int bushelsUsedAsSeed)` +> +> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. +> +> ` +> int grainEatenByRats(int bushels)` +> +> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). +> +> ` +> int newCostOfLand()` +> +> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) + +Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. + +When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. + +When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. + +Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. + +All the required arithmetic in this program should be **integer**. You do not need doubles. + +### Urgent! + +> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. + +### Things you need to know: + +#### Random numbers + +To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: + +> `static Random rand = new Random();` + +To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as + +> `myNewNumber = rand.nextInt(5); +> if (rand.nextInt(100) < 15) { ... }` + +To do something that happens `p` percent of the time, use + +> `if (rand.nextInt(100) < p) { _...do something..._ }` + +#### Getting input + +To get a number from the player, add this method to your program: + +```java + /** + * Prints the given message (which should ask the user for some integral + * quantity), and returns the number entered by the user. If the user's + * response isn't an integer, the question is repeated until the user + * does give a integer response. + * + * @param message The request to present to the user. + * @return The user's numeric response. + */ + int getNumber(String message) { + while (true) { + System.out.print(message); + try { + return scanner.nextInt(); + } + catch (InputMismatchException e) { + System.out.println("\"" + scanner.next() + "\" isn't a number!"); + } + } + } +``` + +Here is an example of how you can use this method: + +> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` + +### Structure of the solution + +* Project name: `Hammurabi` +* Package name: `hammurabi` +* Class names and method signatures: + * `class Hammurabi` + * `public static void main(String[] args)` + * Numerous other methods, as described above. + +The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. + +### Yo! Test it! + +You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! + +But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. + +### Credits + +Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html new file mode 100644 index 0000000..78bbf24 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html @@ -0,0 +1,299 @@ + + + + + + + CIT591 Hammurabi + + + + + +

CIT 591 Assignment 3: + Hammurabi
+ Fall 2010, David Matuszek

+ +

Purpose of this assignment

+ +
    +
  • To get you started using Java.
  • +
+ +

General idea of the assignment

+ +

Hammurabi is a very old computer game. Your job is to bring it into the + 21st century by writing it in Java.

+ +

Here are the standard instructions for the game:

+ +
+

Congratulations, you are the newest ruler of + ancient Samaria, elected for a ten year term of office. Your duties are to + dispense food, direct farming, and buy and sell land as needed to support + your people. Watch out for rat infestiations and the plague! Grain is the + general currency, measured in bushels. The following will help you in your + decisions:

+ +
    +
  • Each person needs at least 20 bushels of + grain per year to survive
  • + +
  • Each person can farm at most 10 acres of + land
  • + +
  • It takes 2 bushels of grain to farm an acre + of land
  • + +
  • The market price for land fluctuates + yearly
  • +
+ +

Rule wisely and you will be showered with + appreciation at the end of your term. Rule poorly and you will be kicked + out of office!

+
+ +

Details

+ +

Define a single class named Hammurabi. Use the following skeleton (but leave out the // comments):

+
package hammurabi;               // package declaration
+
+import java.util.Random;         // imports go here
+import java.util.Scanner;
+
+/**
+ * The Hammurabi game.
+ * @author Your name goes here
+ * @author Your partner's name goes here
+ */
+public class Hammurabi {         // must save in a file named Hammurabi.java
+    Random rand = new Random();  // this is an instance variable
+    Scanner scanner = new Scanner(System.in);
+
+    public static void main(String[] args) { // required in every Java program
+        new Hammurabi().playGame();
+    }
+
+    void playGame() {
+        // declare local variables here: grain, population, etc.
+        // statements go after the declations
+    }
+
+    //other methods go here
+}
+

Playing the game

+

Here is what you start the game with: +

    +
  • 100 people
  • +
  • 2800 bushels of grain in storage
  • +
  • 1000 acres of land
  • +
  • Land value is 19 bushels/acre

    +
  • +
+

Each year, print out a summary similar to the following:

+
+O great Hammurabi!
+You are in year 1 of your ten year rule.
+In the previous year 0 people starved to death.
+In the previous year 5 people entered the kingdom.
+The population is now 100.
+We harvested 3000 bushels at 3 bushels per acre.
+Rats destroyed 200 bushels, leaving 2800 bushels in storage.
+The city owns 1000 acres of land.
+Land is currently worth 19 bushels per acre.
+
+ +

The above summary represents the initial state, at the beginning of + the first year--that is, when you first take office, and before you do any of + the computations below). So, for example, the previous year (under a + different ruler) must have started with 95 people; none starved, and 5 + entered the kingdom, so as you enter office you rule 100 people.

+ +

Here's what your playGame method needs to do each year, for up to 10 years:

+ +
+

Ask the player the following questions. These questions should be asked in this order. Do not give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below:

+
+
int askHowManyAcresToBuy(int price, int bushels)
+
Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase.
+

+ int askHowManyAcresToSell(int acresOwned)
+
Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have.
+ Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn.
+

+ int askHowMuchGrainToFeedPeople(int bushels)
+
Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You can feed them more than they need to survive.
+

+ int askHowManyAcresToPlant(int acresOwned, int population, int bushels)
+
Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year.
+
+

For each + question, do "sanity checking"; that is, test whether the answer is + possible (you have enough grain, you have enough people to do the planting + etc.), and keep asking until you get a possible value. (For example, + O Great Hammurabi, surely you jest! We have only 3415 bushels left!)

+ +

Then the method needs to determine:

+ +
    +
  1. If there is a plague, and how many people die from it.
  2. +
  3. How many people starved.
  4. +
  5. How many people came to the city.
  6. +
  7. How good the harvest is.
  8. +
  9. If you have a problem with rats, and how much grain they eat.
  10. +
  11. How much land costs (for deciding what to do next).
  12. +
+

These can all be local variables of your playGame method.

+

Use the following methods, in this order, to make the necessary calculations:

+
+
int plagueDeaths(int population)
+
Each year, there is a 15% chance of a horrible plague. When this + happens, half your people die. Return the number of plague deaths (possibly zero).
+

+ int starvationDeaths(int population, int bushelsFedToPeople)
+
Each person needs 20 bushels of grain to survive. If you feed them + more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero).
+

+ boolean uprising(int population, int howManyPeopleStarved)
+
Return true if more than + 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.)
+

+ int immigrants(int population, int acresOwned, int grainInStorage)
+
Nobody will come to the city if people are starving (so don't call this method). If everyone is + well fed, compute how many people come to the city as: (20 * number of acres you have + amount of grain you have in + storage) / (100 * population) + 1.
+

+ int harvest(int acres, int bushelsUsedAsSeed)
+
Choose a random integer between 1 and 6, inclusive. Each acre that was planted + with seed will yield this many bushels of grain. (Example: if you planted + 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested.
+

+ int grainEatenByRats(int bushels)
+
There is a 40% chance that you will have a rat infestation. When this + happens, rats will eat somewhere between 10% and 30% of your + grain. Return the amount of grain eaten by rats (possibly zero).
+

+ int newCostOfLand()
+
The price of land is random, and ranges from 17 to 23 bushels per + acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell + land.)
+
+
+

Do these computations, in this order, for each of ten years. Each + computation should be done in a separate method, and none of these methods + should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it.

+ +

When the computations are finished, call a method printSummary to print the + summary for the year. This method will take several parameters.

+ + +

When the game ends , use a method finalSummary to print out a final summary, and to tell the + player how good a job he/she did. I'll leave the details up to you, but the + usual evaluation is based on how many people starved, and how many acres per + person you end up with.

+

Your playGame method will be quite long, but very straightforward; it does very little but call other methods.

+

All the required arithmetic in this program should be integer. You + do not need doubles.

+ +

I suggest that you first get the simplest possible version of the program + running and tested out (that is, leave out things like rats, plagues, and + immigration), then add these things one at a time to a working + program, testing as you go.

+ +

Things you need to know:

+ +

Random numbers

+ +

To get a random number generator, you first need to import + java.util.Random (or java.util.*). Then, you can + create a random number generator with a statement such as:

+ +
+

static Random rand = new Random();

+
+ +

To get a new random number in the range 0..n-1, where + n is an int, call rand.nextInt(n). + To get a new random number in the range min..max, use + the expression rand.nextInt(max - min + 1) + min. You + can use the rand method in statements such as

+ +
+

myNewNumber = rand.nextInt(5);
+ if (rand.nextInt(100) < 15) { ... }

+
+ +

To do something that happens p percent of the time, use

+ +
+

if (rand.nextInt(100) < p) { ...do something... + }

+
+ +

Getting input

+

To get a number from the player, add this method to your program:

+
+/**
+ * Prints the given message (which should ask the user for some integral
+ * quantity), and returns the number entered by the user. If the user's
+ * response isn't an integer, the question is repeated until the user
+ * does give a integer response.
+ * 
+ * @param message The request to present to the user.
+ * @return The user's numeric response.
+ */
+ int getNumber(String message) {
+    while (true) {
+        System.out.print(message);
+        try {
+            return scanner.nextInt();
+        }
+        catch (InputMismatchException e) {
+            System.out.println("\"" + scanner.next() + "\" isn't a number!");
+        }
+    }
+}
+
+ +

Here is an example of how you can use this method:

+ +
+

sell = getNumber("O great Hammurabi, how many acres shall you sell?");

+
+ +

Structure of the assignment:

+ +
    +
  • Project name: Hammurabi
  • + +
  • Package name: hammurabi
  • + +
  • Class names and method signatures: + +
      +
    • + class Hammurabi + +
        +
      • public static void main(String[] args)
      • + +
      • Numerous other methods, as described above.
      • +
      +
    • +
    +
  • + +
+ +

The above are requirements. The methods that do calculations, not input/output, will be tested by my test methods, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument names are irrelevant). You may have additional methods if you wish.

+ +

Due date:

+ +

Thursday, October 21, before midnight. Turn in your zipped assignment via + Blackboard. Email submissions will incur the wrath of Hammurabi (and won't be graded).

+ + + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md new file mode 100644 index 0000000..796d85c --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md @@ -0,0 +1,6 @@ +# Notes + +from the original Dave Matuszek course of 2010. + +https://www.cis.upenn.edu/~matuszek/cit591-2010/Assignments/06-hammurabi.html + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml new file mode 100644 index 0000000..d789654 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + + io.zipcoder + MicroLabs-Loops + 1.0-SNAPSHOT + + + + + junit + junit + 4.13.2 + + + + + + 1.8 + 1.8 + + \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore new file mode 100644 index 0000000..a1c2a23 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore @@ -0,0 +1,23 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE new file mode 100644 index 0000000..22474e4 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Zip Code Wilmington Core + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md new file mode 100644 index 0000000..e4672c9 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md @@ -0,0 +1,228 @@ +# hamurabi +an ancient (in more ways than one) computer game (text) + +## General idea of the lab + +*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. + +Here are the standard instructions for the game: + +> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** +> +> * **Each person needs at least 20 bushels of grain per year to survive** +> * **Each person can farm at most 10 acres of land** +> * **It takes 2 bushels of grain to farm an acre of land** +> * **The market price for land fluctuates yearly** +> +> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** + +### Maven + +There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. + +### Details + +Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): + +```java +package hammurabi; // package declaration +import java.util.Random; // imports go here +import java.util.Scanner; + +public class Hammurabi { // must save in a file named Hammurabi.java + Random rand = new Random(); // this is an instance variable + Scanner scanner = new Scanner(System.in); + + public static void main(String\[\] args) { // required in every Java program + new Hammurabi().playGame(); + } + + void playGame() { + // declare local variables here: grain, population, etc. + // statements go after the declations + } + + //other methods go here +} +``` + +### Playing the game + +Here is what you start the game with: + +* 100 people +* 2800 bushels of grain in storage +* 1000 acres of land +* Land value is 19 bushels/acre + + +Each year, print out a summary similar to the following: + + O great Hammurabi! + You are in year 1 of your ten year rule. + In the previous year 0 people starved to death. + In the previous year 5 people entered the kingdom. + The population is now 100. + We harvested 3000 bushels at 3 bushels per acre. + Rats destroyed 200 bushels, leaving 2800 bushels in storage. + The city owns 1000 acres of land. + Land is currently worth 19 bushels per acre. + +The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. + +Here's what your `playGame` method needs to do each year, for up to 10 years: + +> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: +> +> `int askHowManyAcresToBuy(int price, int bushels)` +> +> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. +> +> ` +> int askHowManyAcresToSell(int acresOwned)` +> +> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. +> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. +> +> ` +> int askHowMuchGrainToFeedPeople(int bushels)` +> +> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. +> +> ` +> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` +> +> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. +> +> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) +> +> Then the method needs to determine: +> +> 1. If there is a plague, and how many people die from it. +> 2. How many people starved. +> 3. How many people came to the city. +> 4. How good the harvest is. +> 5. If you have a problem with rats, and how much grain they eat. +> 6. How much land costs (for deciding what to do next). +> +> These can all be local variables of your `playGame` method. +> +> Use the following methods, **in this order,** to make the necessary calculations: +> +> `int plagueDeaths(int population)` +> +> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). +> +> ` +> int starvationDeaths(int population, int bushelsFedToPeople)` +> +> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). +> +> ` +> boolean uprising(int population, int howManyPeopleStarved)` +> +> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) +> +> ` +> int immigrants(int population, int acresOwned, int grainInStorage)` +> +> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. +> +> ` +> int harvest(int acres, int bushelsUsedAsSeed)` +> +> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. +> +> ` +> int grainEatenByRats(int bushels)` +> +> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). +> +> ` +> int newCostOfLand()` +> +> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) + +Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. + +When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. + +When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. + +Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. + +All the required arithmetic in this program should be **integer**. You do not need doubles. + +### Urgent! + +> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. + +### Things you need to know: + +#### Random numbers + +To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: + +> `static Random rand = new Random();` + +To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as + +> `myNewNumber = rand.nextInt(5); +> if (rand.nextInt(100) < 15) { ... }` + +To do something that happens `p` percent of the time, use + +> `if (rand.nextInt(100) < p) { _...do something..._ }` + +#### Getting input + +To get a number from the player, add this method to your program: + +```java + /** + * Prints the given message (which should ask the user for some integral + * quantity), and returns the number entered by the user. If the user's + * response isn't an integer, the question is repeated until the user + * does give a integer response. + * + * @param message The request to present to the user. + * @return The user's numeric response. + */ + int getNumber(String message) { + while (true) { + System.out.print(message); + try { + return scanner.nextInt(); + } + catch (InputMismatchException e) { + System.out.println("\"" + scanner.next() + "\" isn't a number!"); + } + } + } +``` + +Here is an example of how you can use this method: + +> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` + +### Structure of the solution + +* Project name: `Hammurabi` +* Package name: `hammurabi` +* Class names and method signatures: + * `class Hammurabi` + * `public static void main(String[] args)` + * Numerous other methods, as described above. + +The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. + +### Yo! Test it! + +You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! + +But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. + +### Credits + +Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html new file mode 100644 index 0000000..78bbf24 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html @@ -0,0 +1,299 @@ + + + + + + + CIT591 Hammurabi + + + + + +

CIT 591 Assignment 3: + Hammurabi
+ Fall 2010, David Matuszek

+ +

Purpose of this assignment

+ +
    +
  • To get you started using Java.
  • +
+ +

General idea of the assignment

+ +

Hammurabi is a very old computer game. Your job is to bring it into the + 21st century by writing it in Java.

+ +

Here are the standard instructions for the game:

+ +
+

Congratulations, you are the newest ruler of + ancient Samaria, elected for a ten year term of office. Your duties are to + dispense food, direct farming, and buy and sell land as needed to support + your people. Watch out for rat infestiations and the plague! Grain is the + general currency, measured in bushels. The following will help you in your + decisions:

+ +
    +
  • Each person needs at least 20 bushels of + grain per year to survive
  • + +
  • Each person can farm at most 10 acres of + land
  • + +
  • It takes 2 bushels of grain to farm an acre + of land
  • + +
  • The market price for land fluctuates + yearly
  • +
+ +

Rule wisely and you will be showered with + appreciation at the end of your term. Rule poorly and you will be kicked + out of office!

+
+ +

Details

+ +

Define a single class named Hammurabi. Use the following skeleton (but leave out the // comments):

+
package hammurabi;               // package declaration
+
+import java.util.Random;         // imports go here
+import java.util.Scanner;
+
+/**
+ * The Hammurabi game.
+ * @author Your name goes here
+ * @author Your partner's name goes here
+ */
+public class Hammurabi {         // must save in a file named Hammurabi.java
+    Random rand = new Random();  // this is an instance variable
+    Scanner scanner = new Scanner(System.in);
+
+    public static void main(String[] args) { // required in every Java program
+        new Hammurabi().playGame();
+    }
+
+    void playGame() {
+        // declare local variables here: grain, population, etc.
+        // statements go after the declations
+    }
+
+    //other methods go here
+}
+

Playing the game

+

Here is what you start the game with: +

    +
  • 100 people
  • +
  • 2800 bushels of grain in storage
  • +
  • 1000 acres of land
  • +
  • Land value is 19 bushels/acre

    +
  • +
+

Each year, print out a summary similar to the following:

+
+O great Hammurabi!
+You are in year 1 of your ten year rule.
+In the previous year 0 people starved to death.
+In the previous year 5 people entered the kingdom.
+The population is now 100.
+We harvested 3000 bushels at 3 bushels per acre.
+Rats destroyed 200 bushels, leaving 2800 bushels in storage.
+The city owns 1000 acres of land.
+Land is currently worth 19 bushels per acre.
+
+ +

The above summary represents the initial state, at the beginning of + the first year--that is, when you first take office, and before you do any of + the computations below). So, for example, the previous year (under a + different ruler) must have started with 95 people; none starved, and 5 + entered the kingdom, so as you enter office you rule 100 people.

+ +

Here's what your playGame method needs to do each year, for up to 10 years:

+ +
+

Ask the player the following questions. These questions should be asked in this order. Do not give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below:

+
+
int askHowManyAcresToBuy(int price, int bushels)
+
Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase.
+

+ int askHowManyAcresToSell(int acresOwned)
+
Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have.
+ Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn.
+

+ int askHowMuchGrainToFeedPeople(int bushels)
+
Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You can feed them more than they need to survive.
+

+ int askHowManyAcresToPlant(int acresOwned, int population, int bushels)
+
Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year.
+
+

For each + question, do "sanity checking"; that is, test whether the answer is + possible (you have enough grain, you have enough people to do the planting + etc.), and keep asking until you get a possible value. (For example, + O Great Hammurabi, surely you jest! We have only 3415 bushels left!)

+ +

Then the method needs to determine:

+ +
    +
  1. If there is a plague, and how many people die from it.
  2. +
  3. How many people starved.
  4. +
  5. How many people came to the city.
  6. +
  7. How good the harvest is.
  8. +
  9. If you have a problem with rats, and how much grain they eat.
  10. +
  11. How much land costs (for deciding what to do next).
  12. +
+

These can all be local variables of your playGame method.

+

Use the following methods, in this order, to make the necessary calculations:

+
+
int plagueDeaths(int population)
+
Each year, there is a 15% chance of a horrible plague. When this + happens, half your people die. Return the number of plague deaths (possibly zero).
+

+ int starvationDeaths(int population, int bushelsFedToPeople)
+
Each person needs 20 bushels of grain to survive. If you feed them + more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero).
+

+ boolean uprising(int population, int howManyPeopleStarved)
+
Return true if more than + 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.)
+

+ int immigrants(int population, int acresOwned, int grainInStorage)
+
Nobody will come to the city if people are starving (so don't call this method). If everyone is + well fed, compute how many people come to the city as: (20 * number of acres you have + amount of grain you have in + storage) / (100 * population) + 1.
+

+ int harvest(int acres, int bushelsUsedAsSeed)
+
Choose a random integer between 1 and 6, inclusive. Each acre that was planted + with seed will yield this many bushels of grain. (Example: if you planted + 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested.
+

+ int grainEatenByRats(int bushels)
+
There is a 40% chance that you will have a rat infestation. When this + happens, rats will eat somewhere between 10% and 30% of your + grain. Return the amount of grain eaten by rats (possibly zero).
+

+ int newCostOfLand()
+
The price of land is random, and ranges from 17 to 23 bushels per + acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell + land.)
+
+
+

Do these computations, in this order, for each of ten years. Each + computation should be done in a separate method, and none of these methods + should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it.

+ +

When the computations are finished, call a method printSummary to print the + summary for the year. This method will take several parameters.

+ + +

When the game ends , use a method finalSummary to print out a final summary, and to tell the + player how good a job he/she did. I'll leave the details up to you, but the + usual evaluation is based on how many people starved, and how many acres per + person you end up with.

+

Your playGame method will be quite long, but very straightforward; it does very little but call other methods.

+

All the required arithmetic in this program should be integer. You + do not need doubles.

+ +

I suggest that you first get the simplest possible version of the program + running and tested out (that is, leave out things like rats, plagues, and + immigration), then add these things one at a time to a working + program, testing as you go.

+ +

Things you need to know:

+ +

Random numbers

+ +

To get a random number generator, you first need to import + java.util.Random (or java.util.*). Then, you can + create a random number generator with a statement such as:

+ +
+

static Random rand = new Random();

+
+ +

To get a new random number in the range 0..n-1, where + n is an int, call rand.nextInt(n). + To get a new random number in the range min..max, use + the expression rand.nextInt(max - min + 1) + min. You + can use the rand method in statements such as

+ +
+

myNewNumber = rand.nextInt(5);
+ if (rand.nextInt(100) < 15) { ... }

+
+ +

To do something that happens p percent of the time, use

+ +
+

if (rand.nextInt(100) < p) { ...do something... + }

+
+ +

Getting input

+

To get a number from the player, add this method to your program:

+
+/**
+ * Prints the given message (which should ask the user for some integral
+ * quantity), and returns the number entered by the user. If the user's
+ * response isn't an integer, the question is repeated until the user
+ * does give a integer response.
+ * 
+ * @param message The request to present to the user.
+ * @return The user's numeric response.
+ */
+ int getNumber(String message) {
+    while (true) {
+        System.out.print(message);
+        try {
+            return scanner.nextInt();
+        }
+        catch (InputMismatchException e) {
+            System.out.println("\"" + scanner.next() + "\" isn't a number!");
+        }
+    }
+}
+
+ +

Here is an example of how you can use this method:

+ +
+

sell = getNumber("O great Hammurabi, how many acres shall you sell?");

+
+ +

Structure of the assignment:

+ +
    +
  • Project name: Hammurabi
  • + +
  • Package name: hammurabi
  • + +
  • Class names and method signatures: + +
      +
    • + class Hammurabi + +
        +
      • public static void main(String[] args)
      • + +
      • Numerous other methods, as described above.
      • +
      +
    • +
    +
  • + +
+ +

The above are requirements. The methods that do calculations, not input/output, will be tested by my test methods, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument names are irrelevant). You may have additional methods if you wish.

+ +

Due date:

+ +

Thursday, October 21, before midnight. Turn in your zipped assignment via + Blackboard. Email submissions will incur the wrath of Hammurabi (and won't be graded).

+ + + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md new file mode 100644 index 0000000..796d85c --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md @@ -0,0 +1,6 @@ +# Notes + +from the original Dave Matuszek course of 2010. + +https://www.cis.upenn.edu/~matuszek/cit591-2010/Assignments/06-hammurabi.html + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml new file mode 100644 index 0000000..d789654 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + + io.zipcoder + MicroLabs-Loops + 1.0-SNAPSHOT + + + + + junit + junit + 4.13.2 + + + + + + 1.8 + 1.8 + + \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore new file mode 100644 index 0000000..a1c2a23 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore @@ -0,0 +1,23 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE new file mode 100644 index 0000000..22474e4 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Zip Code Wilmington Core + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md new file mode 100644 index 0000000..e4672c9 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md @@ -0,0 +1,228 @@ +# hamurabi +an ancient (in more ways than one) computer game (text) + +## General idea of the lab + +*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. + +Here are the standard instructions for the game: + +> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** +> +> * **Each person needs at least 20 bushels of grain per year to survive** +> * **Each person can farm at most 10 acres of land** +> * **It takes 2 bushels of grain to farm an acre of land** +> * **The market price for land fluctuates yearly** +> +> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** + +### Maven + +There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. + +### Details + +Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): + +```java +package hammurabi; // package declaration +import java.util.Random; // imports go here +import java.util.Scanner; + +public class Hammurabi { // must save in a file named Hammurabi.java + Random rand = new Random(); // this is an instance variable + Scanner scanner = new Scanner(System.in); + + public static void main(String\[\] args) { // required in every Java program + new Hammurabi().playGame(); + } + + void playGame() { + // declare local variables here: grain, population, etc. + // statements go after the declations + } + + //other methods go here +} +``` + +### Playing the game + +Here is what you start the game with: + +* 100 people +* 2800 bushels of grain in storage +* 1000 acres of land +* Land value is 19 bushels/acre + + +Each year, print out a summary similar to the following: + + O great Hammurabi! + You are in year 1 of your ten year rule. + In the previous year 0 people starved to death. + In the previous year 5 people entered the kingdom. + The population is now 100. + We harvested 3000 bushels at 3 bushels per acre. + Rats destroyed 200 bushels, leaving 2800 bushels in storage. + The city owns 1000 acres of land. + Land is currently worth 19 bushels per acre. + +The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. + +Here's what your `playGame` method needs to do each year, for up to 10 years: + +> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: +> +> `int askHowManyAcresToBuy(int price, int bushels)` +> +> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. +> +> ` +> int askHowManyAcresToSell(int acresOwned)` +> +> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. +> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. +> +> ` +> int askHowMuchGrainToFeedPeople(int bushels)` +> +> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. +> +> ` +> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` +> +> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. +> +> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) +> +> Then the method needs to determine: +> +> 1. If there is a plague, and how many people die from it. +> 2. How many people starved. +> 3. How many people came to the city. +> 4. How good the harvest is. +> 5. If you have a problem with rats, and how much grain they eat. +> 6. How much land costs (for deciding what to do next). +> +> These can all be local variables of your `playGame` method. +> +> Use the following methods, **in this order,** to make the necessary calculations: +> +> `int plagueDeaths(int population)` +> +> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). +> +> ` +> int starvationDeaths(int population, int bushelsFedToPeople)` +> +> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). +> +> ` +> boolean uprising(int population, int howManyPeopleStarved)` +> +> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) +> +> ` +> int immigrants(int population, int acresOwned, int grainInStorage)` +> +> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. +> +> ` +> int harvest(int acres, int bushelsUsedAsSeed)` +> +> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. +> +> ` +> int grainEatenByRats(int bushels)` +> +> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). +> +> ` +> int newCostOfLand()` +> +> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) + +Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. + +When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. + +When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. + +Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. + +All the required arithmetic in this program should be **integer**. You do not need doubles. + +### Urgent! + +> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. + +### Things you need to know: + +#### Random numbers + +To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: + +> `static Random rand = new Random();` + +To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as + +> `myNewNumber = rand.nextInt(5); +> if (rand.nextInt(100) < 15) { ... }` + +To do something that happens `p` percent of the time, use + +> `if (rand.nextInt(100) < p) { _...do something..._ }` + +#### Getting input + +To get a number from the player, add this method to your program: + +```java + /** + * Prints the given message (which should ask the user for some integral + * quantity), and returns the number entered by the user. If the user's + * response isn't an integer, the question is repeated until the user + * does give a integer response. + * + * @param message The request to present to the user. + * @return The user's numeric response. + */ + int getNumber(String message) { + while (true) { + System.out.print(message); + try { + return scanner.nextInt(); + } + catch (InputMismatchException e) { + System.out.println("\"" + scanner.next() + "\" isn't a number!"); + } + } + } +``` + +Here is an example of how you can use this method: + +> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` + +### Structure of the solution + +* Project name: `Hammurabi` +* Package name: `hammurabi` +* Class names and method signatures: + * `class Hammurabi` + * `public static void main(String[] args)` + * Numerous other methods, as described above. + +The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. + +### Yo! Test it! + +You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! + +But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. + +### Credits + +Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html new file mode 100644 index 0000000..78bbf24 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html @@ -0,0 +1,299 @@ + + + + + + + CIT591 Hammurabi + + + + + +

CIT 591 Assignment 3: + Hammurabi
+ Fall 2010, David Matuszek

+ +

Purpose of this assignment

+ +
    +
  • To get you started using Java.
  • +
+ +

General idea of the assignment

+ +

Hammurabi is a very old computer game. Your job is to bring it into the + 21st century by writing it in Java.

+ +

Here are the standard instructions for the game:

+ +
+

Congratulations, you are the newest ruler of + ancient Samaria, elected for a ten year term of office. Your duties are to + dispense food, direct farming, and buy and sell land as needed to support + your people. Watch out for rat infestiations and the plague! Grain is the + general currency, measured in bushels. The following will help you in your + decisions:

+ +
    +
  • Each person needs at least 20 bushels of + grain per year to survive
  • + +
  • Each person can farm at most 10 acres of + land
  • + +
  • It takes 2 bushels of grain to farm an acre + of land
  • + +
  • The market price for land fluctuates + yearly
  • +
+ +

Rule wisely and you will be showered with + appreciation at the end of your term. Rule poorly and you will be kicked + out of office!

+
+ +

Details

+ +

Define a single class named Hammurabi. Use the following skeleton (but leave out the // comments):

+
package hammurabi;               // package declaration
+
+import java.util.Random;         // imports go here
+import java.util.Scanner;
+
+/**
+ * The Hammurabi game.
+ * @author Your name goes here
+ * @author Your partner's name goes here
+ */
+public class Hammurabi {         // must save in a file named Hammurabi.java
+    Random rand = new Random();  // this is an instance variable
+    Scanner scanner = new Scanner(System.in);
+
+    public static void main(String[] args) { // required in every Java program
+        new Hammurabi().playGame();
+    }
+
+    void playGame() {
+        // declare local variables here: grain, population, etc.
+        // statements go after the declations
+    }
+
+    //other methods go here
+}
+

Playing the game

+

Here is what you start the game with: +

    +
  • 100 people
  • +
  • 2800 bushels of grain in storage
  • +
  • 1000 acres of land
  • +
  • Land value is 19 bushels/acre

    +
  • +
+

Each year, print out a summary similar to the following:

+
+O great Hammurabi!
+You are in year 1 of your ten year rule.
+In the previous year 0 people starved to death.
+In the previous year 5 people entered the kingdom.
+The population is now 100.
+We harvested 3000 bushels at 3 bushels per acre.
+Rats destroyed 200 bushels, leaving 2800 bushels in storage.
+The city owns 1000 acres of land.
+Land is currently worth 19 bushels per acre.
+
+ +

The above summary represents the initial state, at the beginning of + the first year--that is, when you first take office, and before you do any of + the computations below). So, for example, the previous year (under a + different ruler) must have started with 95 people; none starved, and 5 + entered the kingdom, so as you enter office you rule 100 people.

+ +

Here's what your playGame method needs to do each year, for up to 10 years:

+ +
+

Ask the player the following questions. These questions should be asked in this order. Do not give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below:

+
+
int askHowManyAcresToBuy(int price, int bushels)
+
Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase.
+

+ int askHowManyAcresToSell(int acresOwned)
+
Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have.
+ Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn.
+

+ int askHowMuchGrainToFeedPeople(int bushels)
+
Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You can feed them more than they need to survive.
+

+ int askHowManyAcresToPlant(int acresOwned, int population, int bushels)
+
Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year.
+
+

For each + question, do "sanity checking"; that is, test whether the answer is + possible (you have enough grain, you have enough people to do the planting + etc.), and keep asking until you get a possible value. (For example, + O Great Hammurabi, surely you jest! We have only 3415 bushels left!)

+ +

Then the method needs to determine:

+ +
    +
  1. If there is a plague, and how many people die from it.
  2. +
  3. How many people starved.
  4. +
  5. How many people came to the city.
  6. +
  7. How good the harvest is.
  8. +
  9. If you have a problem with rats, and how much grain they eat.
  10. +
  11. How much land costs (for deciding what to do next).
  12. +
+

These can all be local variables of your playGame method.

+

Use the following methods, in this order, to make the necessary calculations:

+
+
int plagueDeaths(int population)
+
Each year, there is a 15% chance of a horrible plague. When this + happens, half your people die. Return the number of plague deaths (possibly zero).
+

+ int starvationDeaths(int population, int bushelsFedToPeople)
+
Each person needs 20 bushels of grain to survive. If you feed them + more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero).
+

+ boolean uprising(int population, int howManyPeopleStarved)
+
Return true if more than + 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.)
+

+ int immigrants(int population, int acresOwned, int grainInStorage)
+
Nobody will come to the city if people are starving (so don't call this method). If everyone is + well fed, compute how many people come to the city as: (20 * number of acres you have + amount of grain you have in + storage) / (100 * population) + 1.
+

+ int harvest(int acres, int bushelsUsedAsSeed)
+
Choose a random integer between 1 and 6, inclusive. Each acre that was planted + with seed will yield this many bushels of grain. (Example: if you planted + 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested.
+

+ int grainEatenByRats(int bushels)
+
There is a 40% chance that you will have a rat infestation. When this + happens, rats will eat somewhere between 10% and 30% of your + grain. Return the amount of grain eaten by rats (possibly zero).
+

+ int newCostOfLand()
+
The price of land is random, and ranges from 17 to 23 bushels per + acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell + land.)
+
+
+

Do these computations, in this order, for each of ten years. Each + computation should be done in a separate method, and none of these methods + should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it.

+ +

When the computations are finished, call a method printSummary to print the + summary for the year. This method will take several parameters.

+ + +

When the game ends , use a method finalSummary to print out a final summary, and to tell the + player how good a job he/she did. I'll leave the details up to you, but the + usual evaluation is based on how many people starved, and how many acres per + person you end up with.

+

Your playGame method will be quite long, but very straightforward; it does very little but call other methods.

+

All the required arithmetic in this program should be integer. You + do not need doubles.

+ +

I suggest that you first get the simplest possible version of the program + running and tested out (that is, leave out things like rats, plagues, and + immigration), then add these things one at a time to a working + program, testing as you go.

+ +

Things you need to know:

+ +

Random numbers

+ +

To get a random number generator, you first need to import + java.util.Random (or java.util.*). Then, you can + create a random number generator with a statement such as:

+ +
+

static Random rand = new Random();

+
+ +

To get a new random number in the range 0..n-1, where + n is an int, call rand.nextInt(n). + To get a new random number in the range min..max, use + the expression rand.nextInt(max - min + 1) + min. You + can use the rand method in statements such as

+ +
+

myNewNumber = rand.nextInt(5);
+ if (rand.nextInt(100) < 15) { ... }

+
+ +

To do something that happens p percent of the time, use

+ +
+

if (rand.nextInt(100) < p) { ...do something... + }

+
+ +

Getting input

+

To get a number from the player, add this method to your program:

+
+/**
+ * Prints the given message (which should ask the user for some integral
+ * quantity), and returns the number entered by the user. If the user's
+ * response isn't an integer, the question is repeated until the user
+ * does give a integer response.
+ * 
+ * @param message The request to present to the user.
+ * @return The user's numeric response.
+ */
+ int getNumber(String message) {
+    while (true) {
+        System.out.print(message);
+        try {
+            return scanner.nextInt();
+        }
+        catch (InputMismatchException e) {
+            System.out.println("\"" + scanner.next() + "\" isn't a number!");
+        }
+    }
+}
+
+ +

Here is an example of how you can use this method:

+ +
+

sell = getNumber("O great Hammurabi, how many acres shall you sell?");

+
+ +

Structure of the assignment:

+ +
    +
  • Project name: Hammurabi
  • + +
  • Package name: hammurabi
  • + +
  • Class names and method signatures: + +
      +
    • + class Hammurabi + +
        +
      • public static void main(String[] args)
      • + +
      • Numerous other methods, as described above.
      • +
      +
    • +
    +
  • + +
+ +

The above are requirements. The methods that do calculations, not input/output, will be tested by my test methods, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument names are irrelevant). You may have additional methods if you wish.

+ +

Due date:

+ +

Thursday, October 21, before midnight. Turn in your zipped assignment via + Blackboard. Email submissions will incur the wrath of Hammurabi (and won't be graded).

+ + + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md new file mode 100644 index 0000000..796d85c --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md @@ -0,0 +1,6 @@ +# Notes + +from the original Dave Matuszek course of 2010. + +https://www.cis.upenn.edu/~matuszek/cit591-2010/Assignments/06-hammurabi.html + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml new file mode 100644 index 0000000..d789654 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + + io.zipcoder + MicroLabs-Loops + 1.0-SNAPSHOT + + + + + junit + junit + 4.13.2 + + + + + + 1.8 + 1.8 + + \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore new file mode 100644 index 0000000..a1c2a23 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore @@ -0,0 +1,23 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE new file mode 100644 index 0000000..22474e4 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Zip Code Wilmington Core + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md new file mode 100644 index 0000000..e4672c9 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md @@ -0,0 +1,228 @@ +# hamurabi +an ancient (in more ways than one) computer game (text) + +## General idea of the lab + +*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. + +Here are the standard instructions for the game: + +> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** +> +> * **Each person needs at least 20 bushels of grain per year to survive** +> * **Each person can farm at most 10 acres of land** +> * **It takes 2 bushels of grain to farm an acre of land** +> * **The market price for land fluctuates yearly** +> +> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** + +### Maven + +There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. + +### Details + +Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): + +```java +package hammurabi; // package declaration +import java.util.Random; // imports go here +import java.util.Scanner; + +public class Hammurabi { // must save in a file named Hammurabi.java + Random rand = new Random(); // this is an instance variable + Scanner scanner = new Scanner(System.in); + + public static void main(String\[\] args) { // required in every Java program + new Hammurabi().playGame(); + } + + void playGame() { + // declare local variables here: grain, population, etc. + // statements go after the declations + } + + //other methods go here +} +``` + +### Playing the game + +Here is what you start the game with: + +* 100 people +* 2800 bushels of grain in storage +* 1000 acres of land +* Land value is 19 bushels/acre + + +Each year, print out a summary similar to the following: + + O great Hammurabi! + You are in year 1 of your ten year rule. + In the previous year 0 people starved to death. + In the previous year 5 people entered the kingdom. + The population is now 100. + We harvested 3000 bushels at 3 bushels per acre. + Rats destroyed 200 bushels, leaving 2800 bushels in storage. + The city owns 1000 acres of land. + Land is currently worth 19 bushels per acre. + +The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. + +Here's what your `playGame` method needs to do each year, for up to 10 years: + +> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: +> +> `int askHowManyAcresToBuy(int price, int bushels)` +> +> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. +> +> ` +> int askHowManyAcresToSell(int acresOwned)` +> +> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. +> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. +> +> ` +> int askHowMuchGrainToFeedPeople(int bushels)` +> +> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. +> +> ` +> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` +> +> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. +> +> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) +> +> Then the method needs to determine: +> +> 1. If there is a plague, and how many people die from it. +> 2. How many people starved. +> 3. How many people came to the city. +> 4. How good the harvest is. +> 5. If you have a problem with rats, and how much grain they eat. +> 6. How much land costs (for deciding what to do next). +> +> These can all be local variables of your `playGame` method. +> +> Use the following methods, **in this order,** to make the necessary calculations: +> +> `int plagueDeaths(int population)` +> +> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). +> +> ` +> int starvationDeaths(int population, int bushelsFedToPeople)` +> +> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). +> +> ` +> boolean uprising(int population, int howManyPeopleStarved)` +> +> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) +> +> ` +> int immigrants(int population, int acresOwned, int grainInStorage)` +> +> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. +> +> ` +> int harvest(int acres, int bushelsUsedAsSeed)` +> +> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. +> +> ` +> int grainEatenByRats(int bushels)` +> +> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). +> +> ` +> int newCostOfLand()` +> +> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) + +Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. + +When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. + +When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. + +Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. + +All the required arithmetic in this program should be **integer**. You do not need doubles. + +### Urgent! + +> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. + +### Things you need to know: + +#### Random numbers + +To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: + +> `static Random rand = new Random();` + +To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as + +> `myNewNumber = rand.nextInt(5); +> if (rand.nextInt(100) < 15) { ... }` + +To do something that happens `p` percent of the time, use + +> `if (rand.nextInt(100) < p) { _...do something..._ }` + +#### Getting input + +To get a number from the player, add this method to your program: + +```java + /** + * Prints the given message (which should ask the user for some integral + * quantity), and returns the number entered by the user. If the user's + * response isn't an integer, the question is repeated until the user + * does give a integer response. + * + * @param message The request to present to the user. + * @return The user's numeric response. + */ + int getNumber(String message) { + while (true) { + System.out.print(message); + try { + return scanner.nextInt(); + } + catch (InputMismatchException e) { + System.out.println("\"" + scanner.next() + "\" isn't a number!"); + } + } + } +``` + +Here is an example of how you can use this method: + +> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` + +### Structure of the solution + +* Project name: `Hammurabi` +* Package name: `hammurabi` +* Class names and method signatures: + * `class Hammurabi` + * `public static void main(String[] args)` + * Numerous other methods, as described above. + +The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. + +### Yo! Test it! + +You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! + +But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. + +### Credits + +Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html new file mode 100644 index 0000000..78bbf24 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html @@ -0,0 +1,299 @@ + + + + + + + CIT591 Hammurabi + + + + + +

CIT 591 Assignment 3: + Hammurabi
+ Fall 2010, David Matuszek

+ +

Purpose of this assignment

+ +
    +
  • To get you started using Java.
  • +
+ +

General idea of the assignment

+ +

Hammurabi is a very old computer game. Your job is to bring it into the + 21st century by writing it in Java.

+ +

Here are the standard instructions for the game:

+ +
+

Congratulations, you are the newest ruler of + ancient Samaria, elected for a ten year term of office. Your duties are to + dispense food, direct farming, and buy and sell land as needed to support + your people. Watch out for rat infestiations and the plague! Grain is the + general currency, measured in bushels. The following will help you in your + decisions:

+ +
    +
  • Each person needs at least 20 bushels of + grain per year to survive
  • + +
  • Each person can farm at most 10 acres of + land
  • + +
  • It takes 2 bushels of grain to farm an acre + of land
  • + +
  • The market price for land fluctuates + yearly
  • +
+ +

Rule wisely and you will be showered with + appreciation at the end of your term. Rule poorly and you will be kicked + out of office!

+
+ +

Details

+ +

Define a single class named Hammurabi. Use the following skeleton (but leave out the // comments):

+
package hammurabi;               // package declaration
+
+import java.util.Random;         // imports go here
+import java.util.Scanner;
+
+/**
+ * The Hammurabi game.
+ * @author Your name goes here
+ * @author Your partner's name goes here
+ */
+public class Hammurabi {         // must save in a file named Hammurabi.java
+    Random rand = new Random();  // this is an instance variable
+    Scanner scanner = new Scanner(System.in);
+
+    public static void main(String[] args) { // required in every Java program
+        new Hammurabi().playGame();
+    }
+
+    void playGame() {
+        // declare local variables here: grain, population, etc.
+        // statements go after the declations
+    }
+
+    //other methods go here
+}
+

Playing the game

+

Here is what you start the game with: +

    +
  • 100 people
  • +
  • 2800 bushels of grain in storage
  • +
  • 1000 acres of land
  • +
  • Land value is 19 bushels/acre

    +
  • +
+

Each year, print out a summary similar to the following:

+
+O great Hammurabi!
+You are in year 1 of your ten year rule.
+In the previous year 0 people starved to death.
+In the previous year 5 people entered the kingdom.
+The population is now 100.
+We harvested 3000 bushels at 3 bushels per acre.
+Rats destroyed 200 bushels, leaving 2800 bushels in storage.
+The city owns 1000 acres of land.
+Land is currently worth 19 bushels per acre.
+
+ +

The above summary represents the initial state, at the beginning of + the first year--that is, when you first take office, and before you do any of + the computations below). So, for example, the previous year (under a + different ruler) must have started with 95 people; none starved, and 5 + entered the kingdom, so as you enter office you rule 100 people.

+ +

Here's what your playGame method needs to do each year, for up to 10 years:

+ +
+

Ask the player the following questions. These questions should be asked in this order. Do not give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below:

+
+
int askHowManyAcresToBuy(int price, int bushels)
+
Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase.
+

+ int askHowManyAcresToSell(int acresOwned)
+
Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have.
+ Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn.
+

+ int askHowMuchGrainToFeedPeople(int bushels)
+
Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You can feed them more than they need to survive.
+

+ int askHowManyAcresToPlant(int acresOwned, int population, int bushels)
+
Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year.
+
+

For each + question, do "sanity checking"; that is, test whether the answer is + possible (you have enough grain, you have enough people to do the planting + etc.), and keep asking until you get a possible value. (For example, + O Great Hammurabi, surely you jest! We have only 3415 bushels left!)

+ +

Then the method needs to determine:

+ +
    +
  1. If there is a plague, and how many people die from it.
  2. +
  3. How many people starved.
  4. +
  5. How many people came to the city.
  6. +
  7. How good the harvest is.
  8. +
  9. If you have a problem with rats, and how much grain they eat.
  10. +
  11. How much land costs (for deciding what to do next).
  12. +
+

These can all be local variables of your playGame method.

+

Use the following methods, in this order, to make the necessary calculations:

+
+
int plagueDeaths(int population)
+
Each year, there is a 15% chance of a horrible plague. When this + happens, half your people die. Return the number of plague deaths (possibly zero).
+

+ int starvationDeaths(int population, int bushelsFedToPeople)
+
Each person needs 20 bushels of grain to survive. If you feed them + more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero).
+

+ boolean uprising(int population, int howManyPeopleStarved)
+
Return true if more than + 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.)
+

+ int immigrants(int population, int acresOwned, int grainInStorage)
+
Nobody will come to the city if people are starving (so don't call this method). If everyone is + well fed, compute how many people come to the city as: (20 * number of acres you have + amount of grain you have in + storage) / (100 * population) + 1.
+

+ int harvest(int acres, int bushelsUsedAsSeed)
+
Choose a random integer between 1 and 6, inclusive. Each acre that was planted + with seed will yield this many bushels of grain. (Example: if you planted + 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested.
+

+ int grainEatenByRats(int bushels)
+
There is a 40% chance that you will have a rat infestation. When this + happens, rats will eat somewhere between 10% and 30% of your + grain. Return the amount of grain eaten by rats (possibly zero).
+

+ int newCostOfLand()
+
The price of land is random, and ranges from 17 to 23 bushels per + acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell + land.)
+
+
+

Do these computations, in this order, for each of ten years. Each + computation should be done in a separate method, and none of these methods + should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it.

+ +

When the computations are finished, call a method printSummary to print the + summary for the year. This method will take several parameters.

+ + +

When the game ends , use a method finalSummary to print out a final summary, and to tell the + player how good a job he/she did. I'll leave the details up to you, but the + usual evaluation is based on how many people starved, and how many acres per + person you end up with.

+

Your playGame method will be quite long, but very straightforward; it does very little but call other methods.

+

All the required arithmetic in this program should be integer. You + do not need doubles.

+ +

I suggest that you first get the simplest possible version of the program + running and tested out (that is, leave out things like rats, plagues, and + immigration), then add these things one at a time to a working + program, testing as you go.

+ +

Things you need to know:

+ +

Random numbers

+ +

To get a random number generator, you first need to import + java.util.Random (or java.util.*). Then, you can + create a random number generator with a statement such as:

+ +
+

static Random rand = new Random();

+
+ +

To get a new random number in the range 0..n-1, where + n is an int, call rand.nextInt(n). + To get a new random number in the range min..max, use + the expression rand.nextInt(max - min + 1) + min. You + can use the rand method in statements such as

+ +
+

myNewNumber = rand.nextInt(5);
+ if (rand.nextInt(100) < 15) { ... }

+
+ +

To do something that happens p percent of the time, use

+ +
+

if (rand.nextInt(100) < p) { ...do something... + }

+
+ +

Getting input

+

To get a number from the player, add this method to your program:

+
+/**
+ * Prints the given message (which should ask the user for some integral
+ * quantity), and returns the number entered by the user. If the user's
+ * response isn't an integer, the question is repeated until the user
+ * does give a integer response.
+ * 
+ * @param message The request to present to the user.
+ * @return The user's numeric response.
+ */
+ int getNumber(String message) {
+    while (true) {
+        System.out.print(message);
+        try {
+            return scanner.nextInt();
+        }
+        catch (InputMismatchException e) {
+            System.out.println("\"" + scanner.next() + "\" isn't a number!");
+        }
+    }
+}
+
+ +

Here is an example of how you can use this method:

+ +
+

sell = getNumber("O great Hammurabi, how many acres shall you sell?");

+
+ +

Structure of the assignment:

+ +
    +
  • Project name: Hammurabi
  • + +
  • Package name: hammurabi
  • + +
  • Class names and method signatures: + +
      +
    • + class Hammurabi + +
        +
      • public static void main(String[] args)
      • + +
      • Numerous other methods, as described above.
      • +
      +
    • +
    +
  • + +
+ +

The above are requirements. The methods that do calculations, not input/output, will be tested by my test methods, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument names are irrelevant). You may have additional methods if you wish.

+ +

Due date:

+ +

Thursday, October 21, before midnight. Turn in your zipped assignment via + Blackboard. Email submissions will incur the wrath of Hammurabi (and won't be graded).

+ + + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md new file mode 100644 index 0000000..796d85c --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md @@ -0,0 +1,6 @@ +# Notes + +from the original Dave Matuszek course of 2010. + +https://www.cis.upenn.edu/~matuszek/cit591-2010/Assignments/06-hammurabi.html + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml new file mode 100644 index 0000000..d789654 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + + io.zipcoder + MicroLabs-Loops + 1.0-SNAPSHOT + + + + + junit + junit + 4.13.2 + + + + + + 1.8 + 1.8 + + \ No newline at end of file From 005cd0997409db6d2d38d2b6382115a4f6788001 Mon Sep 17 00:00:00 2001 From: Yingjie <52tiffany.yang@gmail.com> Date: Sat, 12 Nov 2022 16:08:11 -0500 Subject: [PATCH 13/19] update on some methods --- target/classes/target/classes/.gitignore | 23 -- .../classes/target/classes/.idea/.gitignore | 3 - .../classes/target/classes/.idea/compiler.xml | 16 - .../target/classes/.idea/jarRepositories.xml | 20 -- .../libraries/Maven__junit_junit_4_13_2.xml | 13 - .../Maven__org_hamcrest_hamcrest_core_1_3.xml | 13 - target/classes/target/classes/.idea/misc.xml | 13 - .../classes/target/classes/.idea/modules.xml | 8 - target/classes/target/classes/.idea/vcs.xml | 6 - target/classes/target/classes/Hamurabi.iml | 15 - target/classes/target/classes/LICENSE | 21 -- target/classes/target/classes/README.md | 228 ------------- .../classes/docs/matuszek/06-hammurabi.html | 299 ------------------ .../target/classes/docs/matuszek/README..md | 6 - target/classes/target/classes/pom.xml | 25 -- .../target/classes/target/classes/.gitignore | 23 -- .../classes/target/classes/.idea/.gitignore | 3 - .../classes/target/classes/.idea/compiler.xml | 16 - .../target/classes/.idea/jarRepositories.xml | 20 -- .../libraries/Maven__junit_junit_4_13_2.xml | 13 - .../Maven__org_hamcrest_hamcrest_core_1_3.xml | 13 - .../classes/target/classes/.idea/misc.xml | 13 - .../classes/target/classes/.idea/modules.xml | 8 - .../classes/target/classes/.idea/vcs.xml | 6 - .../classes/target/classes/Hamurabi.iml | 15 - .../target/classes/target/classes/LICENSE | 21 -- .../target/classes/target/classes/README.md | 228 ------------- .../classes/docs/matuszek/06-hammurabi.html | 299 ------------------ .../target/classes/docs/matuszek/README..md | 6 - .../target/classes/target/classes/pom.xml | 25 -- .../target/classes/target/classes/.gitignore | 23 -- .../target/classes/target/classes/LICENSE | 21 -- .../target/classes/target/classes/README.md | 228 ------------- .../classes/docs/matuszek/06-hammurabi.html | 299 ------------------ .../target/classes/docs/matuszek/README..md | 6 - .../target/classes/target/classes/pom.xml | 25 -- .../target/classes/target/classes/.gitignore | 23 -- .../target/classes/target/classes/LICENSE | 21 -- .../target/classes/target/classes/README.md | 228 ------------- .../classes/docs/matuszek/06-hammurabi.html | 299 ------------------ .../target/classes/docs/matuszek/README..md | 6 - .../target/classes/target/classes/pom.xml | 25 -- .../target/classes/target/classes/.gitignore | 23 -- .../target/classes/target/classes/LICENSE | 21 -- .../target/classes/target/classes/README.md | 228 ------------- .../classes/docs/matuszek/06-hammurabi.html | 299 ------------------ .../target/classes/docs/matuszek/README..md | 6 - .../target/classes/target/classes/pom.xml | 25 -- .../target/classes/target/classes/.gitignore | 23 -- .../target/classes/target/classes/LICENSE | 21 -- .../target/classes/target/classes/README.md | 228 ------------- .../classes/docs/matuszek/06-hammurabi.html | 299 ------------------ .../target/classes/docs/matuszek/README..md | 6 - .../target/classes/target/classes/pom.xml | 25 -- .../target/classes/target/classes/.gitignore | 23 -- .../target/classes/target/classes/LICENSE | 21 -- .../target/classes/target/classes/README.md | 228 ------------- .../classes/docs/matuszek/06-hammurabi.html | 299 ------------------ .../target/classes/docs/matuszek/README..md | 6 - .../target/classes/target/classes/pom.xml | 25 -- .../target/classes/target/classes/.gitignore | 23 -- .../target/classes/target/classes/LICENSE | 21 -- .../target/classes/target/classes/README.md | 228 ------------- .../classes/docs/matuszek/06-hammurabi.html | 299 ------------------ .../target/classes/docs/matuszek/README..md | 6 - .../target/classes/target/classes/pom.xml | 25 -- .../target/classes/target/classes/.gitignore | 23 -- .../target/classes/target/classes/LICENSE | 21 -- .../target/classes/target/classes/README.md | 228 ------------- .../classes/docs/matuszek/06-hammurabi.html | 299 ------------------ .../target/classes/docs/matuszek/README..md | 6 - .../target/classes/target/classes/pom.xml | 25 -- .../target/classes/target/classes/.gitignore | 23 -- .../target/classes/target/classes/LICENSE | 21 -- .../target/classes/target/classes/README.md | 228 ------------- .../classes/docs/matuszek/06-hammurabi.html | 299 ------------------ .../target/classes/docs/matuszek/README..md | 6 - .../target/classes/target/classes/pom.xml | 25 -- .../target/classes/target/classes/.gitignore | 23 -- .../target/classes/target/classes/LICENSE | 21 -- .../target/classes/target/classes/README.md | 228 ------------- .../classes/docs/matuszek/06-hammurabi.html | 299 ------------------ .../target/classes/docs/matuszek/README..md | 6 - .../target/classes/target/classes/pom.xml | 25 -- .../target/classes/target/classes/.gitignore | 23 -- .../target/classes/target/classes/LICENSE | 21 -- .../target/classes/target/classes/README.md | 228 ------------- .../classes/docs/matuszek/06-hammurabi.html | 299 ------------------ .../target/classes/docs/matuszek/README..md | 6 - .../target/classes/target/classes/pom.xml | 25 -- .../target/classes/target/classes/.gitignore | 23 -- .../target/classes/target/classes/LICENSE | 21 -- .../target/classes/target/classes/README.md | 228 ------------- .../classes/docs/matuszek/06-hammurabi.html | 299 ------------------ .../target/classes/docs/matuszek/README..md | 6 - .../target/classes/target/classes/pom.xml | 25 -- .../target/classes/target/classes/.gitignore | 23 -- .../target/classes/target/classes/LICENSE | 21 -- .../target/classes/target/classes/README.md | 228 ------------- .../classes/docs/matuszek/06-hammurabi.html | 299 ------------------ .../target/classes/docs/matuszek/README..md | 6 - .../target/classes/target/classes/pom.xml | 25 -- .../target/classes/target/classes/.gitignore | 23 -- .../target/classes/target/classes/LICENSE | 21 -- .../target/classes/target/classes/README.md | 228 ------------- .../classes/docs/matuszek/06-hammurabi.html | 299 ------------------ .../target/classes/docs/matuszek/README..md | 6 - .../target/classes/target/classes/pom.xml | 25 -- .../target/classes/target/classes/.gitignore | 23 -- .../target/classes/target/classes/LICENSE | 21 -- .../target/classes/target/classes/README.md | 228 ------------- .../classes/docs/matuszek/06-hammurabi.html | 299 ------------------ .../target/classes/docs/matuszek/README..md | 6 - .../target/classes/target/classes/pom.xml | 25 -- .../target/classes/target/classes/.gitignore | 23 -- .../target/classes/target/classes/LICENSE | 21 -- .../target/classes/target/classes/README.md | 228 ------------- .../classes/docs/matuszek/06-hammurabi.html | 299 ------------------ .../target/classes/docs/matuszek/README..md | 6 - .../target/classes/target/classes/pom.xml | 25 -- .../target/classes/target/classes/.gitignore | 23 -- .../target/classes/target/classes/LICENSE | 21 -- .../target/classes/target/classes/README.md | 228 ------------- .../classes/docs/matuszek/06-hammurabi.html | 299 ------------------ .../target/classes/docs/matuszek/README..md | 6 - .../target/classes/target/classes/pom.xml | 25 -- .../target/classes/target/classes/.gitignore | 23 -- .../target/classes/target/classes/LICENSE | 21 -- .../target/classes/target/classes/README.md | 228 ------------- .../classes/docs/matuszek/06-hammurabi.html | 299 ------------------ .../target/classes/docs/matuszek/README..md | 6 - .../target/classes/target/classes/pom.xml | 25 -- .../target/classes/target/classes/.gitignore | 23 -- .../target/classes/target/classes/LICENSE | 21 -- .../target/classes/target/classes/README.md | 228 ------------- .../classes/docs/matuszek/06-hammurabi.html | 299 ------------------ .../target/classes/docs/matuszek/README..md | 6 - .../target/classes/target/classes/pom.xml | 25 -- .../target/classes/target/classes/.gitignore | 23 -- .../target/classes/target/classes/LICENSE | 21 -- .../target/classes/target/classes/README.md | 228 ------------- .../classes/docs/matuszek/06-hammurabi.html | 299 ------------------ .../target/classes/docs/matuszek/README..md | 6 - .../target/classes/target/classes/pom.xml | 25 -- .../target/classes/target/classes/.gitignore | 23 -- .../target/classes/target/classes/LICENSE | 21 -- .../target/classes/target/classes/README.md | 228 ------------- .../classes/docs/matuszek/06-hammurabi.html | 299 ------------------ .../target/classes/docs/matuszek/README..md | 6 - .../target/classes/target/classes/pom.xml | 25 -- .../target/classes/target/classes/.gitignore | 23 -- .../target/classes/target/classes/LICENSE | 21 -- .../target/classes/target/classes/README.md | 228 ------------- .../classes/docs/matuszek/06-hammurabi.html | 299 ------------------ .../target/classes/docs/matuszek/README..md | 6 - .../target/classes/target/classes/pom.xml | 25 -- 156 files changed, 14060 deletions(-) delete mode 100644 target/classes/target/classes/.gitignore delete mode 100644 target/classes/target/classes/.idea/.gitignore delete mode 100644 target/classes/target/classes/.idea/compiler.xml delete mode 100644 target/classes/target/classes/.idea/jarRepositories.xml delete mode 100644 target/classes/target/classes/.idea/libraries/Maven__junit_junit_4_13_2.xml delete mode 100644 target/classes/target/classes/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml delete mode 100644 target/classes/target/classes/.idea/misc.xml delete mode 100644 target/classes/target/classes/.idea/modules.xml delete mode 100644 target/classes/target/classes/.idea/vcs.xml delete mode 100644 target/classes/target/classes/Hamurabi.iml delete mode 100644 target/classes/target/classes/LICENSE delete mode 100644 target/classes/target/classes/README.md delete mode 100644 target/classes/target/classes/docs/matuszek/06-hammurabi.html delete mode 100644 target/classes/target/classes/docs/matuszek/README..md delete mode 100644 target/classes/target/classes/pom.xml delete mode 100644 target/classes/target/classes/target/classes/.gitignore delete mode 100644 target/classes/target/classes/target/classes/.idea/.gitignore delete mode 100644 target/classes/target/classes/target/classes/.idea/compiler.xml delete mode 100644 target/classes/target/classes/target/classes/.idea/jarRepositories.xml delete mode 100644 target/classes/target/classes/target/classes/.idea/libraries/Maven__junit_junit_4_13_2.xml delete mode 100644 target/classes/target/classes/target/classes/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml delete mode 100644 target/classes/target/classes/target/classes/.idea/misc.xml delete mode 100644 target/classes/target/classes/target/classes/.idea/modules.xml delete mode 100644 target/classes/target/classes/target/classes/.idea/vcs.xml delete mode 100644 target/classes/target/classes/target/classes/Hamurabi.iml delete mode 100644 target/classes/target/classes/target/classes/LICENSE delete mode 100644 target/classes/target/classes/target/classes/README.md delete mode 100644 target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html delete mode 100644 target/classes/target/classes/target/classes/docs/matuszek/README..md delete mode 100644 target/classes/target/classes/target/classes/pom.xml delete mode 100644 target/classes/target/classes/target/classes/target/classes/.gitignore delete mode 100644 target/classes/target/classes/target/classes/target/classes/LICENSE delete mode 100644 target/classes/target/classes/target/classes/target/classes/README.md delete mode 100644 target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html delete mode 100644 target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md delete mode 100644 target/classes/target/classes/target/classes/target/classes/pom.xml delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/README.md delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml diff --git a/target/classes/target/classes/.gitignore b/target/classes/target/classes/.gitignore deleted file mode 100644 index a1c2a23..0000000 --- a/target/classes/target/classes/.gitignore +++ /dev/null @@ -1,23 +0,0 @@ -# Compiled class file -*.class - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* diff --git a/target/classes/target/classes/.idea/.gitignore b/target/classes/target/classes/.idea/.gitignore deleted file mode 100644 index 26d3352..0000000 --- a/target/classes/target/classes/.idea/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml diff --git a/target/classes/target/classes/.idea/compiler.xml b/target/classes/target/classes/.idea/compiler.xml deleted file mode 100644 index 639314b..0000000 --- a/target/classes/target/classes/.idea/compiler.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/target/classes/target/classes/.idea/jarRepositories.xml b/target/classes/target/classes/.idea/jarRepositories.xml deleted file mode 100644 index 712ab9d..0000000 --- a/target/classes/target/classes/.idea/jarRepositories.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/target/classes/target/classes/.idea/libraries/Maven__junit_junit_4_13_2.xml b/target/classes/target/classes/.idea/libraries/Maven__junit_junit_4_13_2.xml deleted file mode 100644 index 606c352..0000000 --- a/target/classes/target/classes/.idea/libraries/Maven__junit_junit_4_13_2.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/target/classes/target/classes/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml b/target/classes/target/classes/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml deleted file mode 100644 index f58bbc1..0000000 --- a/target/classes/target/classes/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/target/classes/target/classes/.idea/misc.xml b/target/classes/target/classes/.idea/misc.xml deleted file mode 100644 index 213cea6..0000000 --- a/target/classes/target/classes/.idea/misc.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/target/classes/target/classes/.idea/modules.xml b/target/classes/target/classes/.idea/modules.xml deleted file mode 100644 index 16ae36c..0000000 --- a/target/classes/target/classes/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/target/classes/target/classes/.idea/vcs.xml b/target/classes/target/classes/.idea/vcs.xml deleted file mode 100644 index 35eb1dd..0000000 --- a/target/classes/target/classes/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/target/classes/target/classes/Hamurabi.iml b/target/classes/target/classes/Hamurabi.iml deleted file mode 100644 index 903044c..0000000 --- a/target/classes/target/classes/Hamurabi.iml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/target/classes/target/classes/LICENSE b/target/classes/target/classes/LICENSE deleted file mode 100644 index 22474e4..0000000 --- a/target/classes/target/classes/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2022 Zip Code Wilmington Core - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/target/classes/target/classes/README.md b/target/classes/target/classes/README.md deleted file mode 100644 index e4672c9..0000000 --- a/target/classes/target/classes/README.md +++ /dev/null @@ -1,228 +0,0 @@ -# hamurabi -an ancient (in more ways than one) computer game (text) - -## General idea of the lab - -*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. - -Here are the standard instructions for the game: - -> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** -> -> * **Each person needs at least 20 bushels of grain per year to survive** -> * **Each person can farm at most 10 acres of land** -> * **It takes 2 bushels of grain to farm an acre of land** -> * **The market price for land fluctuates yearly** -> -> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** - -### Maven - -There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. - -### Details - -Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): - -```java -package hammurabi; // package declaration -import java.util.Random; // imports go here -import java.util.Scanner; - -public class Hammurabi { // must save in a file named Hammurabi.java - Random rand = new Random(); // this is an instance variable - Scanner scanner = new Scanner(System.in); - - public static void main(String\[\] args) { // required in every Java program - new Hammurabi().playGame(); - } - - void playGame() { - // declare local variables here: grain, population, etc. - // statements go after the declations - } - - //other methods go here -} -``` - -### Playing the game - -Here is what you start the game with: - -* 100 people -* 2800 bushels of grain in storage -* 1000 acres of land -* Land value is 19 bushels/acre - - -Each year, print out a summary similar to the following: - - O great Hammurabi! - You are in year 1 of your ten year rule. - In the previous year 0 people starved to death. - In the previous year 5 people entered the kingdom. - The population is now 100. - We harvested 3000 bushels at 3 bushels per acre. - Rats destroyed 200 bushels, leaving 2800 bushels in storage. - The city owns 1000 acres of land. - Land is currently worth 19 bushels per acre. - -The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. - -Here's what your `playGame` method needs to do each year, for up to 10 years: - -> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: -> -> `int askHowManyAcresToBuy(int price, int bushels)` -> -> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. -> -> ` -> int askHowManyAcresToSell(int acresOwned)` -> -> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. -> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. -> -> ` -> int askHowMuchGrainToFeedPeople(int bushels)` -> -> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. -> -> ` -> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` -> -> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. -> -> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) -> -> Then the method needs to determine: -> -> 1. If there is a plague, and how many people die from it. -> 2. How many people starved. -> 3. How many people came to the city. -> 4. How good the harvest is. -> 5. If you have a problem with rats, and how much grain they eat. -> 6. How much land costs (for deciding what to do next). -> -> These can all be local variables of your `playGame` method. -> -> Use the following methods, **in this order,** to make the necessary calculations: -> -> `int plagueDeaths(int population)` -> -> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). -> -> ` -> int starvationDeaths(int population, int bushelsFedToPeople)` -> -> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). -> -> ` -> boolean uprising(int population, int howManyPeopleStarved)` -> -> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) -> -> ` -> int immigrants(int population, int acresOwned, int grainInStorage)` -> -> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. -> -> ` -> int harvest(int acres, int bushelsUsedAsSeed)` -> -> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. -> -> ` -> int grainEatenByRats(int bushels)` -> -> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). -> -> ` -> int newCostOfLand()` -> -> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) - -Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. - -When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. - -When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. - -Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. - -All the required arithmetic in this program should be **integer**. You do not need doubles. - -### Urgent! - -> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. - -### Things you need to know: - -#### Random numbers - -To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: - -> `static Random rand = new Random();` - -To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as - -> `myNewNumber = rand.nextInt(5); -> if (rand.nextInt(100) < 15) { ... }` - -To do something that happens `p` percent of the time, use - -> `if (rand.nextInt(100) < p) { _...do something..._ }` - -#### Getting input - -To get a number from the player, add this method to your program: - -```java - /** - * Prints the given message (which should ask the user for some integral - * quantity), and returns the number entered by the user. If the user's - * response isn't an integer, the question is repeated until the user - * does give a integer response. - * - * @param message The request to present to the user. - * @return The user's numeric response. - */ - int getNumber(String message) { - while (true) { - System.out.print(message); - try { - return scanner.nextInt(); - } - catch (InputMismatchException e) { - System.out.println("\"" + scanner.next() + "\" isn't a number!"); - } - } - } -``` - -Here is an example of how you can use this method: - -> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` - -### Structure of the solution - -* Project name: `Hammurabi` -* Package name: `hammurabi` -* Class names and method signatures: - * `class Hammurabi` - * `public static void main(String[] args)` - * Numerous other methods, as described above. - -The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. - -### Yo! Test it! - -You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! - -But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. - -### Credits - -Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) - diff --git a/target/classes/target/classes/docs/matuszek/06-hammurabi.html b/target/classes/target/classes/docs/matuszek/06-hammurabi.html deleted file mode 100644 index 78bbf24..0000000 --- a/target/classes/target/classes/docs/matuszek/06-hammurabi.html +++ /dev/null @@ -1,299 +0,0 @@ - - - - - - - CIT591 Hammurabi - - - - - -

CIT 591 Assignment 3: - Hammurabi
- Fall 2010, David Matuszek

- -

Purpose of this assignment

- -
    -
  • To get you started using Java.
  • -
- -

General idea of the assignment

- -

Hammurabi is a very old computer game. Your job is to bring it into the - 21st century by writing it in Java.

- -

Here are the standard instructions for the game:

- -
-

Congratulations, you are the newest ruler of - ancient Samaria, elected for a ten year term of office. Your duties are to - dispense food, direct farming, and buy and sell land as needed to support - your people. Watch out for rat infestiations and the plague! Grain is the - general currency, measured in bushels. The following will help you in your - decisions:

- -
    -
  • Each person needs at least 20 bushels of - grain per year to survive
  • - -
  • Each person can farm at most 10 acres of - land
  • - -
  • It takes 2 bushels of grain to farm an acre - of land
  • - -
  • The market price for land fluctuates - yearly
  • -
- -

Rule wisely and you will be showered with - appreciation at the end of your term. Rule poorly and you will be kicked - out of office!

-
- -

Details

- -

Define a single class named Hammurabi. Use the following skeleton (but leave out the // comments):

-
package hammurabi;               // package declaration
-
-import java.util.Random;         // imports go here
-import java.util.Scanner;
-
-/**
- * The Hammurabi game.
- * @author Your name goes here
- * @author Your partner's name goes here
- */
-public class Hammurabi {         // must save in a file named Hammurabi.java
-    Random rand = new Random();  // this is an instance variable
-    Scanner scanner = new Scanner(System.in);
-
-    public static void main(String[] args) { // required in every Java program
-        new Hammurabi().playGame();
-    }
-
-    void playGame() {
-        // declare local variables here: grain, population, etc.
-        // statements go after the declations
-    }
-
-    //other methods go here
-}
-

Playing the game

-

Here is what you start the game with: -

    -
  • 100 people
  • -
  • 2800 bushels of grain in storage
  • -
  • 1000 acres of land
  • -
  • Land value is 19 bushels/acre

    -
  • -
-

Each year, print out a summary similar to the following:

-
-O great Hammurabi!
-You are in year 1 of your ten year rule.
-In the previous year 0 people starved to death.
-In the previous year 5 people entered the kingdom.
-The population is now 100.
-We harvested 3000 bushels at 3 bushels per acre.
-Rats destroyed 200 bushels, leaving 2800 bushels in storage.
-The city owns 1000 acres of land.
-Land is currently worth 19 bushels per acre.
-
- -

The above summary represents the initial state, at the beginning of - the first year--that is, when you first take office, and before you do any of - the computations below). So, for example, the previous year (under a - different ruler) must have started with 95 people; none starved, and 5 - entered the kingdom, so as you enter office you rule 100 people.

- -

Here's what your playGame method needs to do each year, for up to 10 years:

- -
-

Ask the player the following questions. These questions should be asked in this order. Do not give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below:

-
-
int askHowManyAcresToBuy(int price, int bushels)
-
Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase.
-

- int askHowManyAcresToSell(int acresOwned)
-
Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have.
- Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn.
-

- int askHowMuchGrainToFeedPeople(int bushels)
-
Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You can feed them more than they need to survive.
-

- int askHowManyAcresToPlant(int acresOwned, int population, int bushels)
-
Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year.
-
-

For each - question, do "sanity checking"; that is, test whether the answer is - possible (you have enough grain, you have enough people to do the planting - etc.), and keep asking until you get a possible value. (For example, - O Great Hammurabi, surely you jest! We have only 3415 bushels left!)

- -

Then the method needs to determine:

- -
    -
  1. If there is a plague, and how many people die from it.
  2. -
  3. How many people starved.
  4. -
  5. How many people came to the city.
  6. -
  7. How good the harvest is.
  8. -
  9. If you have a problem with rats, and how much grain they eat.
  10. -
  11. How much land costs (for deciding what to do next).
  12. -
-

These can all be local variables of your playGame method.

-

Use the following methods, in this order, to make the necessary calculations:

-
-
int plagueDeaths(int population)
-
Each year, there is a 15% chance of a horrible plague. When this - happens, half your people die. Return the number of plague deaths (possibly zero).
-

- int starvationDeaths(int population, int bushelsFedToPeople)
-
Each person needs 20 bushels of grain to survive. If you feed them - more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero).
-

- boolean uprising(int population, int howManyPeopleStarved)
-
Return true if more than - 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.)
-

- int immigrants(int population, int acresOwned, int grainInStorage)
-
Nobody will come to the city if people are starving (so don't call this method). If everyone is - well fed, compute how many people come to the city as: (20 * number of acres you have + amount of grain you have in - storage) / (100 * population) + 1.
-

- int harvest(int acres, int bushelsUsedAsSeed)
-
Choose a random integer between 1 and 6, inclusive. Each acre that was planted - with seed will yield this many bushels of grain. (Example: if you planted - 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested.
-

- int grainEatenByRats(int bushels)
-
There is a 40% chance that you will have a rat infestation. When this - happens, rats will eat somewhere between 10% and 30% of your - grain. Return the amount of grain eaten by rats (possibly zero).
-

- int newCostOfLand()
-
The price of land is random, and ranges from 17 to 23 bushels per - acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell - land.)
-
-
-

Do these computations, in this order, for each of ten years. Each - computation should be done in a separate method, and none of these methods - should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it.

- -

When the computations are finished, call a method printSummary to print the - summary for the year. This method will take several parameters.

- - -

When the game ends , use a method finalSummary to print out a final summary, and to tell the - player how good a job he/she did. I'll leave the details up to you, but the - usual evaluation is based on how many people starved, and how many acres per - person you end up with.

-

Your playGame method will be quite long, but very straightforward; it does very little but call other methods.

-

All the required arithmetic in this program should be integer. You - do not need doubles.

- -

I suggest that you first get the simplest possible version of the program - running and tested out (that is, leave out things like rats, plagues, and - immigration), then add these things one at a time to a working - program, testing as you go.

- -

Things you need to know:

- -

Random numbers

- -

To get a random number generator, you first need to import - java.util.Random (or java.util.*). Then, you can - create a random number generator with a statement such as:

- -
-

static Random rand = new Random();

-
- -

To get a new random number in the range 0..n-1, where - n is an int, call rand.nextInt(n). - To get a new random number in the range min..max, use - the expression rand.nextInt(max - min + 1) + min. You - can use the rand method in statements such as

- -
-

myNewNumber = rand.nextInt(5);
- if (rand.nextInt(100) < 15) { ... }

-
- -

To do something that happens p percent of the time, use

- -
-

if (rand.nextInt(100) < p) { ...do something... - }

-
- -

Getting input

-

To get a number from the player, add this method to your program:

-
-/**
- * Prints the given message (which should ask the user for some integral
- * quantity), and returns the number entered by the user. If the user's
- * response isn't an integer, the question is repeated until the user
- * does give a integer response.
- * 
- * @param message The request to present to the user.
- * @return The user's numeric response.
- */
- int getNumber(String message) {
-    while (true) {
-        System.out.print(message);
-        try {
-            return scanner.nextInt();
-        }
-        catch (InputMismatchException e) {
-            System.out.println("\"" + scanner.next() + "\" isn't a number!");
-        }
-    }
-}
-
- -

Here is an example of how you can use this method:

- -
-

sell = getNumber("O great Hammurabi, how many acres shall you sell?");

-
- -

Structure of the assignment:

- -
    -
  • Project name: Hammurabi
  • - -
  • Package name: hammurabi
  • - -
  • Class names and method signatures: - -
      -
    • - class Hammurabi - -
        -
      • public static void main(String[] args)
      • - -
      • Numerous other methods, as described above.
      • -
      -
    • -
    -
  • - -
- -

The above are requirements. The methods that do calculations, not input/output, will be tested by my test methods, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument names are irrelevant). You may have additional methods if you wish.

- -

Due date:

- -

Thursday, October 21, before midnight. Turn in your zipped assignment via - Blackboard. Email submissions will incur the wrath of Hammurabi (and won't be graded).

- - - diff --git a/target/classes/target/classes/docs/matuszek/README..md b/target/classes/target/classes/docs/matuszek/README..md deleted file mode 100644 index 796d85c..0000000 --- a/target/classes/target/classes/docs/matuszek/README..md +++ /dev/null @@ -1,6 +0,0 @@ -# Notes - -from the original Dave Matuszek course of 2010. - -https://www.cis.upenn.edu/~matuszek/cit591-2010/Assignments/06-hammurabi.html - diff --git a/target/classes/target/classes/pom.xml b/target/classes/target/classes/pom.xml deleted file mode 100644 index d789654..0000000 --- a/target/classes/target/classes/pom.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - 4.0.0 - - io.zipcoder - MicroLabs-Loops - 1.0-SNAPSHOT - - - - - junit - junit - 4.13.2 - - - - - - 1.8 - 1.8 - - \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/.gitignore b/target/classes/target/classes/target/classes/.gitignore deleted file mode 100644 index a1c2a23..0000000 --- a/target/classes/target/classes/target/classes/.gitignore +++ /dev/null @@ -1,23 +0,0 @@ -# Compiled class file -*.class - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* diff --git a/target/classes/target/classes/target/classes/.idea/.gitignore b/target/classes/target/classes/target/classes/.idea/.gitignore deleted file mode 100644 index 26d3352..0000000 --- a/target/classes/target/classes/target/classes/.idea/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml diff --git a/target/classes/target/classes/target/classes/.idea/compiler.xml b/target/classes/target/classes/target/classes/.idea/compiler.xml deleted file mode 100644 index 639314b..0000000 --- a/target/classes/target/classes/target/classes/.idea/compiler.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/.idea/jarRepositories.xml b/target/classes/target/classes/target/classes/.idea/jarRepositories.xml deleted file mode 100644 index 712ab9d..0000000 --- a/target/classes/target/classes/target/classes/.idea/jarRepositories.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/.idea/libraries/Maven__junit_junit_4_13_2.xml b/target/classes/target/classes/target/classes/.idea/libraries/Maven__junit_junit_4_13_2.xml deleted file mode 100644 index 606c352..0000000 --- a/target/classes/target/classes/target/classes/.idea/libraries/Maven__junit_junit_4_13_2.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml b/target/classes/target/classes/target/classes/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml deleted file mode 100644 index f58bbc1..0000000 --- a/target/classes/target/classes/target/classes/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/.idea/misc.xml b/target/classes/target/classes/target/classes/.idea/misc.xml deleted file mode 100644 index 213cea6..0000000 --- a/target/classes/target/classes/target/classes/.idea/misc.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/.idea/modules.xml b/target/classes/target/classes/target/classes/.idea/modules.xml deleted file mode 100644 index 16ae36c..0000000 --- a/target/classes/target/classes/target/classes/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/.idea/vcs.xml b/target/classes/target/classes/target/classes/.idea/vcs.xml deleted file mode 100644 index 35eb1dd..0000000 --- a/target/classes/target/classes/target/classes/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/Hamurabi.iml b/target/classes/target/classes/target/classes/Hamurabi.iml deleted file mode 100644 index 903044c..0000000 --- a/target/classes/target/classes/target/classes/Hamurabi.iml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/LICENSE b/target/classes/target/classes/target/classes/LICENSE deleted file mode 100644 index 22474e4..0000000 --- a/target/classes/target/classes/target/classes/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2022 Zip Code Wilmington Core - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/target/classes/target/classes/target/classes/README.md b/target/classes/target/classes/target/classes/README.md deleted file mode 100644 index e4672c9..0000000 --- a/target/classes/target/classes/target/classes/README.md +++ /dev/null @@ -1,228 +0,0 @@ -# hamurabi -an ancient (in more ways than one) computer game (text) - -## General idea of the lab - -*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. - -Here are the standard instructions for the game: - -> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** -> -> * **Each person needs at least 20 bushels of grain per year to survive** -> * **Each person can farm at most 10 acres of land** -> * **It takes 2 bushels of grain to farm an acre of land** -> * **The market price for land fluctuates yearly** -> -> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** - -### Maven - -There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. - -### Details - -Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): - -```java -package hammurabi; // package declaration -import java.util.Random; // imports go here -import java.util.Scanner; - -public class Hammurabi { // must save in a file named Hammurabi.java - Random rand = new Random(); // this is an instance variable - Scanner scanner = new Scanner(System.in); - - public static void main(String\[\] args) { // required in every Java program - new Hammurabi().playGame(); - } - - void playGame() { - // declare local variables here: grain, population, etc. - // statements go after the declations - } - - //other methods go here -} -``` - -### Playing the game - -Here is what you start the game with: - -* 100 people -* 2800 bushels of grain in storage -* 1000 acres of land -* Land value is 19 bushels/acre - - -Each year, print out a summary similar to the following: - - O great Hammurabi! - You are in year 1 of your ten year rule. - In the previous year 0 people starved to death. - In the previous year 5 people entered the kingdom. - The population is now 100. - We harvested 3000 bushels at 3 bushels per acre. - Rats destroyed 200 bushels, leaving 2800 bushels in storage. - The city owns 1000 acres of land. - Land is currently worth 19 bushels per acre. - -The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. - -Here's what your `playGame` method needs to do each year, for up to 10 years: - -> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: -> -> `int askHowManyAcresToBuy(int price, int bushels)` -> -> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. -> -> ` -> int askHowManyAcresToSell(int acresOwned)` -> -> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. -> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. -> -> ` -> int askHowMuchGrainToFeedPeople(int bushels)` -> -> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. -> -> ` -> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` -> -> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. -> -> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) -> -> Then the method needs to determine: -> -> 1. If there is a plague, and how many people die from it. -> 2. How many people starved. -> 3. How many people came to the city. -> 4. How good the harvest is. -> 5. If you have a problem with rats, and how much grain they eat. -> 6. How much land costs (for deciding what to do next). -> -> These can all be local variables of your `playGame` method. -> -> Use the following methods, **in this order,** to make the necessary calculations: -> -> `int plagueDeaths(int population)` -> -> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). -> -> ` -> int starvationDeaths(int population, int bushelsFedToPeople)` -> -> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). -> -> ` -> boolean uprising(int population, int howManyPeopleStarved)` -> -> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) -> -> ` -> int immigrants(int population, int acresOwned, int grainInStorage)` -> -> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. -> -> ` -> int harvest(int acres, int bushelsUsedAsSeed)` -> -> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. -> -> ` -> int grainEatenByRats(int bushels)` -> -> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). -> -> ` -> int newCostOfLand()` -> -> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) - -Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. - -When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. - -When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. - -Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. - -All the required arithmetic in this program should be **integer**. You do not need doubles. - -### Urgent! - -> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. - -### Things you need to know: - -#### Random numbers - -To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: - -> `static Random rand = new Random();` - -To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as - -> `myNewNumber = rand.nextInt(5); -> if (rand.nextInt(100) < 15) { ... }` - -To do something that happens `p` percent of the time, use - -> `if (rand.nextInt(100) < p) { _...do something..._ }` - -#### Getting input - -To get a number from the player, add this method to your program: - -```java - /** - * Prints the given message (which should ask the user for some integral - * quantity), and returns the number entered by the user. If the user's - * response isn't an integer, the question is repeated until the user - * does give a integer response. - * - * @param message The request to present to the user. - * @return The user's numeric response. - */ - int getNumber(String message) { - while (true) { - System.out.print(message); - try { - return scanner.nextInt(); - } - catch (InputMismatchException e) { - System.out.println("\"" + scanner.next() + "\" isn't a number!"); - } - } - } -``` - -Here is an example of how you can use this method: - -> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` - -### Structure of the solution - -* Project name: `Hammurabi` -* Package name: `hammurabi` -* Class names and method signatures: - * `class Hammurabi` - * `public static void main(String[] args)` - * Numerous other methods, as described above. - -The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. - -### Yo! Test it! - -You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! - -But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. - -### Credits - -Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) - diff --git a/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html b/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html deleted file mode 100644 index 78bbf24..0000000 --- a/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html +++ /dev/null @@ -1,299 +0,0 @@ - - - - - - - CIT591 Hammurabi - - - - - -

CIT 591 Assignment 3: - Hammurabi
- Fall 2010, David Matuszek

- -

Purpose of this assignment

- -
    -
  • To get you started using Java.
  • -
- -

General idea of the assignment

- -

Hammurabi is a very old computer game. Your job is to bring it into the - 21st century by writing it in Java.

- -

Here are the standard instructions for the game:

- -
-

Congratulations, you are the newest ruler of - ancient Samaria, elected for a ten year term of office. Your duties are to - dispense food, direct farming, and buy and sell land as needed to support - your people. Watch out for rat infestiations and the plague! Grain is the - general currency, measured in bushels. The following will help you in your - decisions:

- -
    -
  • Each person needs at least 20 bushels of - grain per year to survive
  • - -
  • Each person can farm at most 10 acres of - land
  • - -
  • It takes 2 bushels of grain to farm an acre - of land
  • - -
  • The market price for land fluctuates - yearly
  • -
- -

Rule wisely and you will be showered with - appreciation at the end of your term. Rule poorly and you will be kicked - out of office!

-
- -

Details

- -

Define a single class named Hammurabi. Use the following skeleton (but leave out the // comments):

-
package hammurabi;               // package declaration
-
-import java.util.Random;         // imports go here
-import java.util.Scanner;
-
-/**
- * The Hammurabi game.
- * @author Your name goes here
- * @author Your partner's name goes here
- */
-public class Hammurabi {         // must save in a file named Hammurabi.java
-    Random rand = new Random();  // this is an instance variable
-    Scanner scanner = new Scanner(System.in);
-
-    public static void main(String[] args) { // required in every Java program
-        new Hammurabi().playGame();
-    }
-
-    void playGame() {
-        // declare local variables here: grain, population, etc.
-        // statements go after the declations
-    }
-
-    //other methods go here
-}
-

Playing the game

-

Here is what you start the game with: -

    -
  • 100 people
  • -
  • 2800 bushels of grain in storage
  • -
  • 1000 acres of land
  • -
  • Land value is 19 bushels/acre

    -
  • -
-

Each year, print out a summary similar to the following:

-
-O great Hammurabi!
-You are in year 1 of your ten year rule.
-In the previous year 0 people starved to death.
-In the previous year 5 people entered the kingdom.
-The population is now 100.
-We harvested 3000 bushels at 3 bushels per acre.
-Rats destroyed 200 bushels, leaving 2800 bushels in storage.
-The city owns 1000 acres of land.
-Land is currently worth 19 bushels per acre.
-
- -

The above summary represents the initial state, at the beginning of - the first year--that is, when you first take office, and before you do any of - the computations below). So, for example, the previous year (under a - different ruler) must have started with 95 people; none starved, and 5 - entered the kingdom, so as you enter office you rule 100 people.

- -

Here's what your playGame method needs to do each year, for up to 10 years:

- -
-

Ask the player the following questions. These questions should be asked in this order. Do not give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below:

-
-
int askHowManyAcresToBuy(int price, int bushels)
-
Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase.
-

- int askHowManyAcresToSell(int acresOwned)
-
Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have.
- Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn.
-

- int askHowMuchGrainToFeedPeople(int bushels)
-
Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You can feed them more than they need to survive.
-

- int askHowManyAcresToPlant(int acresOwned, int population, int bushels)
-
Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year.
-
-

For each - question, do "sanity checking"; that is, test whether the answer is - possible (you have enough grain, you have enough people to do the planting - etc.), and keep asking until you get a possible value. (For example, - O Great Hammurabi, surely you jest! We have only 3415 bushels left!)

- -

Then the method needs to determine:

- -
    -
  1. If there is a plague, and how many people die from it.
  2. -
  3. How many people starved.
  4. -
  5. How many people came to the city.
  6. -
  7. How good the harvest is.
  8. -
  9. If you have a problem with rats, and how much grain they eat.
  10. -
  11. How much land costs (for deciding what to do next).
  12. -
-

These can all be local variables of your playGame method.

-

Use the following methods, in this order, to make the necessary calculations:

-
-
int plagueDeaths(int population)
-
Each year, there is a 15% chance of a horrible plague. When this - happens, half your people die. Return the number of plague deaths (possibly zero).
-

- int starvationDeaths(int population, int bushelsFedToPeople)
-
Each person needs 20 bushels of grain to survive. If you feed them - more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero).
-

- boolean uprising(int population, int howManyPeopleStarved)
-
Return true if more than - 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.)
-

- int immigrants(int population, int acresOwned, int grainInStorage)
-
Nobody will come to the city if people are starving (so don't call this method). If everyone is - well fed, compute how many people come to the city as: (20 * number of acres you have + amount of grain you have in - storage) / (100 * population) + 1.
-

- int harvest(int acres, int bushelsUsedAsSeed)
-
Choose a random integer between 1 and 6, inclusive. Each acre that was planted - with seed will yield this many bushels of grain. (Example: if you planted - 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested.
-

- int grainEatenByRats(int bushels)
-
There is a 40% chance that you will have a rat infestation. When this - happens, rats will eat somewhere between 10% and 30% of your - grain. Return the amount of grain eaten by rats (possibly zero).
-

- int newCostOfLand()
-
The price of land is random, and ranges from 17 to 23 bushels per - acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell - land.)
-
-
-

Do these computations, in this order, for each of ten years. Each - computation should be done in a separate method, and none of these methods - should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it.

- -

When the computations are finished, call a method printSummary to print the - summary for the year. This method will take several parameters.

- - -

When the game ends , use a method finalSummary to print out a final summary, and to tell the - player how good a job he/she did. I'll leave the details up to you, but the - usual evaluation is based on how many people starved, and how many acres per - person you end up with.

-

Your playGame method will be quite long, but very straightforward; it does very little but call other methods.

-

All the required arithmetic in this program should be integer. You - do not need doubles.

- -

I suggest that you first get the simplest possible version of the program - running and tested out (that is, leave out things like rats, plagues, and - immigration), then add these things one at a time to a working - program, testing as you go.

- -

Things you need to know:

- -

Random numbers

- -

To get a random number generator, you first need to import - java.util.Random (or java.util.*). Then, you can - create a random number generator with a statement such as:

- -
-

static Random rand = new Random();

-
- -

To get a new random number in the range 0..n-1, where - n is an int, call rand.nextInt(n). - To get a new random number in the range min..max, use - the expression rand.nextInt(max - min + 1) + min. You - can use the rand method in statements such as

- -
-

myNewNumber = rand.nextInt(5);
- if (rand.nextInt(100) < 15) { ... }

-
- -

To do something that happens p percent of the time, use

- -
-

if (rand.nextInt(100) < p) { ...do something... - }

-
- -

Getting input

-

To get a number from the player, add this method to your program:

-
-/**
- * Prints the given message (which should ask the user for some integral
- * quantity), and returns the number entered by the user. If the user's
- * response isn't an integer, the question is repeated until the user
- * does give a integer response.
- * 
- * @param message The request to present to the user.
- * @return The user's numeric response.
- */
- int getNumber(String message) {
-    while (true) {
-        System.out.print(message);
-        try {
-            return scanner.nextInt();
-        }
-        catch (InputMismatchException e) {
-            System.out.println("\"" + scanner.next() + "\" isn't a number!");
-        }
-    }
-}
-
- -

Here is an example of how you can use this method:

- -
-

sell = getNumber("O great Hammurabi, how many acres shall you sell?");

-
- -

Structure of the assignment:

- -
    -
  • Project name: Hammurabi
  • - -
  • Package name: hammurabi
  • - -
  • Class names and method signatures: - -
      -
    • - class Hammurabi - -
        -
      • public static void main(String[] args)
      • - -
      • Numerous other methods, as described above.
      • -
      -
    • -
    -
  • - -
- -

The above are requirements. The methods that do calculations, not input/output, will be tested by my test methods, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument names are irrelevant). You may have additional methods if you wish.

- -

Due date:

- -

Thursday, October 21, before midnight. Turn in your zipped assignment via - Blackboard. Email submissions will incur the wrath of Hammurabi (and won't be graded).

- - - diff --git a/target/classes/target/classes/target/classes/docs/matuszek/README..md b/target/classes/target/classes/target/classes/docs/matuszek/README..md deleted file mode 100644 index 796d85c..0000000 --- a/target/classes/target/classes/target/classes/docs/matuszek/README..md +++ /dev/null @@ -1,6 +0,0 @@ -# Notes - -from the original Dave Matuszek course of 2010. - -https://www.cis.upenn.edu/~matuszek/cit591-2010/Assignments/06-hammurabi.html - diff --git a/target/classes/target/classes/target/classes/pom.xml b/target/classes/target/classes/target/classes/pom.xml deleted file mode 100644 index d789654..0000000 --- a/target/classes/target/classes/target/classes/pom.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - 4.0.0 - - io.zipcoder - MicroLabs-Loops - 1.0-SNAPSHOT - - - - - junit - junit - 4.13.2 - - - - - - 1.8 - 1.8 - - \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/target/classes/.gitignore b/target/classes/target/classes/target/classes/target/classes/.gitignore deleted file mode 100644 index a1c2a23..0000000 --- a/target/classes/target/classes/target/classes/target/classes/.gitignore +++ /dev/null @@ -1,23 +0,0 @@ -# Compiled class file -*.class - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* diff --git a/target/classes/target/classes/target/classes/target/classes/LICENSE b/target/classes/target/classes/target/classes/target/classes/LICENSE deleted file mode 100644 index 22474e4..0000000 --- a/target/classes/target/classes/target/classes/target/classes/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2022 Zip Code Wilmington Core - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/target/classes/target/classes/target/classes/target/classes/README.md b/target/classes/target/classes/target/classes/target/classes/README.md deleted file mode 100644 index e4672c9..0000000 --- a/target/classes/target/classes/target/classes/target/classes/README.md +++ /dev/null @@ -1,228 +0,0 @@ -# hamurabi -an ancient (in more ways than one) computer game (text) - -## General idea of the lab - -*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. - -Here are the standard instructions for the game: - -> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** -> -> * **Each person needs at least 20 bushels of grain per year to survive** -> * **Each person can farm at most 10 acres of land** -> * **It takes 2 bushels of grain to farm an acre of land** -> * **The market price for land fluctuates yearly** -> -> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** - -### Maven - -There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. - -### Details - -Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): - -```java -package hammurabi; // package declaration -import java.util.Random; // imports go here -import java.util.Scanner; - -public class Hammurabi { // must save in a file named Hammurabi.java - Random rand = new Random(); // this is an instance variable - Scanner scanner = new Scanner(System.in); - - public static void main(String\[\] args) { // required in every Java program - new Hammurabi().playGame(); - } - - void playGame() { - // declare local variables here: grain, population, etc. - // statements go after the declations - } - - //other methods go here -} -``` - -### Playing the game - -Here is what you start the game with: - -* 100 people -* 2800 bushels of grain in storage -* 1000 acres of land -* Land value is 19 bushels/acre - - -Each year, print out a summary similar to the following: - - O great Hammurabi! - You are in year 1 of your ten year rule. - In the previous year 0 people starved to death. - In the previous year 5 people entered the kingdom. - The population is now 100. - We harvested 3000 bushels at 3 bushels per acre. - Rats destroyed 200 bushels, leaving 2800 bushels in storage. - The city owns 1000 acres of land. - Land is currently worth 19 bushels per acre. - -The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. - -Here's what your `playGame` method needs to do each year, for up to 10 years: - -> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: -> -> `int askHowManyAcresToBuy(int price, int bushels)` -> -> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. -> -> ` -> int askHowManyAcresToSell(int acresOwned)` -> -> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. -> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. -> -> ` -> int askHowMuchGrainToFeedPeople(int bushels)` -> -> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. -> -> ` -> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` -> -> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. -> -> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) -> -> Then the method needs to determine: -> -> 1. If there is a plague, and how many people die from it. -> 2. How many people starved. -> 3. How many people came to the city. -> 4. How good the harvest is. -> 5. If you have a problem with rats, and how much grain they eat. -> 6. How much land costs (for deciding what to do next). -> -> These can all be local variables of your `playGame` method. -> -> Use the following methods, **in this order,** to make the necessary calculations: -> -> `int plagueDeaths(int population)` -> -> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). -> -> ` -> int starvationDeaths(int population, int bushelsFedToPeople)` -> -> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). -> -> ` -> boolean uprising(int population, int howManyPeopleStarved)` -> -> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) -> -> ` -> int immigrants(int population, int acresOwned, int grainInStorage)` -> -> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. -> -> ` -> int harvest(int acres, int bushelsUsedAsSeed)` -> -> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. -> -> ` -> int grainEatenByRats(int bushels)` -> -> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). -> -> ` -> int newCostOfLand()` -> -> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) - -Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. - -When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. - -When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. - -Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. - -All the required arithmetic in this program should be **integer**. You do not need doubles. - -### Urgent! - -> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. - -### Things you need to know: - -#### Random numbers - -To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: - -> `static Random rand = new Random();` - -To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as - -> `myNewNumber = rand.nextInt(5); -> if (rand.nextInt(100) < 15) { ... }` - -To do something that happens `p` percent of the time, use - -> `if (rand.nextInt(100) < p) { _...do something..._ }` - -#### Getting input - -To get a number from the player, add this method to your program: - -```java - /** - * Prints the given message (which should ask the user for some integral - * quantity), and returns the number entered by the user. If the user's - * response isn't an integer, the question is repeated until the user - * does give a integer response. - * - * @param message The request to present to the user. - * @return The user's numeric response. - */ - int getNumber(String message) { - while (true) { - System.out.print(message); - try { - return scanner.nextInt(); - } - catch (InputMismatchException e) { - System.out.println("\"" + scanner.next() + "\" isn't a number!"); - } - } - } -``` - -Here is an example of how you can use this method: - -> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` - -### Structure of the solution - -* Project name: `Hammurabi` -* Package name: `hammurabi` -* Class names and method signatures: - * `class Hammurabi` - * `public static void main(String[] args)` - * Numerous other methods, as described above. - -The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. - -### Yo! Test it! - -You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! - -But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. - -### Credits - -Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) - diff --git a/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html b/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html deleted file mode 100644 index 78bbf24..0000000 --- a/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html +++ /dev/null @@ -1,299 +0,0 @@ - - - - - - - CIT591 Hammurabi - - - - - -

CIT 591 Assignment 3: - Hammurabi
- Fall 2010, David Matuszek

- -

Purpose of this assignment

- -
    -
  • To get you started using Java.
  • -
- -

General idea of the assignment

- -

Hammurabi is a very old computer game. Your job is to bring it into the - 21st century by writing it in Java.

- -

Here are the standard instructions for the game:

- -
-

Congratulations, you are the newest ruler of - ancient Samaria, elected for a ten year term of office. Your duties are to - dispense food, direct farming, and buy and sell land as needed to support - your people. Watch out for rat infestiations and the plague! Grain is the - general currency, measured in bushels. The following will help you in your - decisions:

- -
    -
  • Each person needs at least 20 bushels of - grain per year to survive
  • - -
  • Each person can farm at most 10 acres of - land
  • - -
  • It takes 2 bushels of grain to farm an acre - of land
  • - -
  • The market price for land fluctuates - yearly
  • -
- -

Rule wisely and you will be showered with - appreciation at the end of your term. Rule poorly and you will be kicked - out of office!

-
- -

Details

- -

Define a single class named Hammurabi. Use the following skeleton (but leave out the // comments):

-
package hammurabi;               // package declaration
-
-import java.util.Random;         // imports go here
-import java.util.Scanner;
-
-/**
- * The Hammurabi game.
- * @author Your name goes here
- * @author Your partner's name goes here
- */
-public class Hammurabi {         // must save in a file named Hammurabi.java
-    Random rand = new Random();  // this is an instance variable
-    Scanner scanner = new Scanner(System.in);
-
-    public static void main(String[] args) { // required in every Java program
-        new Hammurabi().playGame();
-    }
-
-    void playGame() {
-        // declare local variables here: grain, population, etc.
-        // statements go after the declations
-    }
-
-    //other methods go here
-}
-

Playing the game

-

Here is what you start the game with: -

    -
  • 100 people
  • -
  • 2800 bushels of grain in storage
  • -
  • 1000 acres of land
  • -
  • Land value is 19 bushels/acre

    -
  • -
-

Each year, print out a summary similar to the following:

-
-O great Hammurabi!
-You are in year 1 of your ten year rule.
-In the previous year 0 people starved to death.
-In the previous year 5 people entered the kingdom.
-The population is now 100.
-We harvested 3000 bushels at 3 bushels per acre.
-Rats destroyed 200 bushels, leaving 2800 bushels in storage.
-The city owns 1000 acres of land.
-Land is currently worth 19 bushels per acre.
-
- -

The above summary represents the initial state, at the beginning of - the first year--that is, when you first take office, and before you do any of - the computations below). So, for example, the previous year (under a - different ruler) must have started with 95 people; none starved, and 5 - entered the kingdom, so as you enter office you rule 100 people.

- -

Here's what your playGame method needs to do each year, for up to 10 years:

- -
-

Ask the player the following questions. These questions should be asked in this order. Do not give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below:

-
-
int askHowManyAcresToBuy(int price, int bushels)
-
Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase.
-

- int askHowManyAcresToSell(int acresOwned)
-
Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have.
- Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn.
-

- int askHowMuchGrainToFeedPeople(int bushels)
-
Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You can feed them more than they need to survive.
-

- int askHowManyAcresToPlant(int acresOwned, int population, int bushels)
-
Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year.
-
-

For each - question, do "sanity checking"; that is, test whether the answer is - possible (you have enough grain, you have enough people to do the planting - etc.), and keep asking until you get a possible value. (For example, - O Great Hammurabi, surely you jest! We have only 3415 bushels left!)

- -

Then the method needs to determine:

- -
    -
  1. If there is a plague, and how many people die from it.
  2. -
  3. How many people starved.
  4. -
  5. How many people came to the city.
  6. -
  7. How good the harvest is.
  8. -
  9. If you have a problem with rats, and how much grain they eat.
  10. -
  11. How much land costs (for deciding what to do next).
  12. -
-

These can all be local variables of your playGame method.

-

Use the following methods, in this order, to make the necessary calculations:

-
-
int plagueDeaths(int population)
-
Each year, there is a 15% chance of a horrible plague. When this - happens, half your people die. Return the number of plague deaths (possibly zero).
-

- int starvationDeaths(int population, int bushelsFedToPeople)
-
Each person needs 20 bushels of grain to survive. If you feed them - more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero).
-

- boolean uprising(int population, int howManyPeopleStarved)
-
Return true if more than - 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.)
-

- int immigrants(int population, int acresOwned, int grainInStorage)
-
Nobody will come to the city if people are starving (so don't call this method). If everyone is - well fed, compute how many people come to the city as: (20 * number of acres you have + amount of grain you have in - storage) / (100 * population) + 1.
-

- int harvest(int acres, int bushelsUsedAsSeed)
-
Choose a random integer between 1 and 6, inclusive. Each acre that was planted - with seed will yield this many bushels of grain. (Example: if you planted - 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested.
-

- int grainEatenByRats(int bushels)
-
There is a 40% chance that you will have a rat infestation. When this - happens, rats will eat somewhere between 10% and 30% of your - grain. Return the amount of grain eaten by rats (possibly zero).
-

- int newCostOfLand()
-
The price of land is random, and ranges from 17 to 23 bushels per - acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell - land.)
-
-
-

Do these computations, in this order, for each of ten years. Each - computation should be done in a separate method, and none of these methods - should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it.

- -

When the computations are finished, call a method printSummary to print the - summary for the year. This method will take several parameters.

- - -

When the game ends , use a method finalSummary to print out a final summary, and to tell the - player how good a job he/she did. I'll leave the details up to you, but the - usual evaluation is based on how many people starved, and how many acres per - person you end up with.

-

Your playGame method will be quite long, but very straightforward; it does very little but call other methods.

-

All the required arithmetic in this program should be integer. You - do not need doubles.

- -

I suggest that you first get the simplest possible version of the program - running and tested out (that is, leave out things like rats, plagues, and - immigration), then add these things one at a time to a working - program, testing as you go.

- -

Things you need to know:

- -

Random numbers

- -

To get a random number generator, you first need to import - java.util.Random (or java.util.*). Then, you can - create a random number generator with a statement such as:

- -
-

static Random rand = new Random();

-
- -

To get a new random number in the range 0..n-1, where - n is an int, call rand.nextInt(n). - To get a new random number in the range min..max, use - the expression rand.nextInt(max - min + 1) + min. You - can use the rand method in statements such as

- -
-

myNewNumber = rand.nextInt(5);
- if (rand.nextInt(100) < 15) { ... }

-
- -

To do something that happens p percent of the time, use

- -
-

if (rand.nextInt(100) < p) { ...do something... - }

-
- -

Getting input

-

To get a number from the player, add this method to your program:

-
-/**
- * Prints the given message (which should ask the user for some integral
- * quantity), and returns the number entered by the user. If the user's
- * response isn't an integer, the question is repeated until the user
- * does give a integer response.
- * 
- * @param message The request to present to the user.
- * @return The user's numeric response.
- */
- int getNumber(String message) {
-    while (true) {
-        System.out.print(message);
-        try {
-            return scanner.nextInt();
-        }
-        catch (InputMismatchException e) {
-            System.out.println("\"" + scanner.next() + "\" isn't a number!");
-        }
-    }
-}
-
- -

Here is an example of how you can use this method:

- -
-

sell = getNumber("O great Hammurabi, how many acres shall you sell?");

-
- -

Structure of the assignment:

- -
    -
  • Project name: Hammurabi
  • - -
  • Package name: hammurabi
  • - -
  • Class names and method signatures: - -
      -
    • - class Hammurabi - -
        -
      • public static void main(String[] args)
      • - -
      • Numerous other methods, as described above.
      • -
      -
    • -
    -
  • - -
- -

The above are requirements. The methods that do calculations, not input/output, will be tested by my test methods, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument names are irrelevant). You may have additional methods if you wish.

- -

Due date:

- -

Thursday, October 21, before midnight. Turn in your zipped assignment via - Blackboard. Email submissions will incur the wrath of Hammurabi (and won't be graded).

- - - diff --git a/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md b/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md deleted file mode 100644 index 796d85c..0000000 --- a/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md +++ /dev/null @@ -1,6 +0,0 @@ -# Notes - -from the original Dave Matuszek course of 2010. - -https://www.cis.upenn.edu/~matuszek/cit591-2010/Assignments/06-hammurabi.html - diff --git a/target/classes/target/classes/target/classes/target/classes/pom.xml b/target/classes/target/classes/target/classes/target/classes/pom.xml deleted file mode 100644 index d789654..0000000 --- a/target/classes/target/classes/target/classes/target/classes/pom.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - 4.0.0 - - io.zipcoder - MicroLabs-Loops - 1.0-SNAPSHOT - - - - - junit - junit - 4.13.2 - - - - - - 1.8 - 1.8 - - \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore b/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore deleted file mode 100644 index a1c2a23..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore +++ /dev/null @@ -1,23 +0,0 @@ -# Compiled class file -*.class - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE b/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE deleted file mode 100644 index 22474e4..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2022 Zip Code Wilmington Core - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/README.md b/target/classes/target/classes/target/classes/target/classes/target/classes/README.md deleted file mode 100644 index e4672c9..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/README.md +++ /dev/null @@ -1,228 +0,0 @@ -# hamurabi -an ancient (in more ways than one) computer game (text) - -## General idea of the lab - -*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. - -Here are the standard instructions for the game: - -> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** -> -> * **Each person needs at least 20 bushels of grain per year to survive** -> * **Each person can farm at most 10 acres of land** -> * **It takes 2 bushels of grain to farm an acre of land** -> * **The market price for land fluctuates yearly** -> -> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** - -### Maven - -There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. - -### Details - -Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): - -```java -package hammurabi; // package declaration -import java.util.Random; // imports go here -import java.util.Scanner; - -public class Hammurabi { // must save in a file named Hammurabi.java - Random rand = new Random(); // this is an instance variable - Scanner scanner = new Scanner(System.in); - - public static void main(String\[\] args) { // required in every Java program - new Hammurabi().playGame(); - } - - void playGame() { - // declare local variables here: grain, population, etc. - // statements go after the declations - } - - //other methods go here -} -``` - -### Playing the game - -Here is what you start the game with: - -* 100 people -* 2800 bushels of grain in storage -* 1000 acres of land -* Land value is 19 bushels/acre - - -Each year, print out a summary similar to the following: - - O great Hammurabi! - You are in year 1 of your ten year rule. - In the previous year 0 people starved to death. - In the previous year 5 people entered the kingdom. - The population is now 100. - We harvested 3000 bushels at 3 bushels per acre. - Rats destroyed 200 bushels, leaving 2800 bushels in storage. - The city owns 1000 acres of land. - Land is currently worth 19 bushels per acre. - -The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. - -Here's what your `playGame` method needs to do each year, for up to 10 years: - -> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: -> -> `int askHowManyAcresToBuy(int price, int bushels)` -> -> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. -> -> ` -> int askHowManyAcresToSell(int acresOwned)` -> -> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. -> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. -> -> ` -> int askHowMuchGrainToFeedPeople(int bushels)` -> -> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. -> -> ` -> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` -> -> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. -> -> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) -> -> Then the method needs to determine: -> -> 1. If there is a plague, and how many people die from it. -> 2. How many people starved. -> 3. How many people came to the city. -> 4. How good the harvest is. -> 5. If you have a problem with rats, and how much grain they eat. -> 6. How much land costs (for deciding what to do next). -> -> These can all be local variables of your `playGame` method. -> -> Use the following methods, **in this order,** to make the necessary calculations: -> -> `int plagueDeaths(int population)` -> -> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). -> -> ` -> int starvationDeaths(int population, int bushelsFedToPeople)` -> -> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). -> -> ` -> boolean uprising(int population, int howManyPeopleStarved)` -> -> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) -> -> ` -> int immigrants(int population, int acresOwned, int grainInStorage)` -> -> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. -> -> ` -> int harvest(int acres, int bushelsUsedAsSeed)` -> -> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. -> -> ` -> int grainEatenByRats(int bushels)` -> -> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). -> -> ` -> int newCostOfLand()` -> -> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) - -Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. - -When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. - -When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. - -Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. - -All the required arithmetic in this program should be **integer**. You do not need doubles. - -### Urgent! - -> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. - -### Things you need to know: - -#### Random numbers - -To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: - -> `static Random rand = new Random();` - -To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as - -> `myNewNumber = rand.nextInt(5); -> if (rand.nextInt(100) < 15) { ... }` - -To do something that happens `p` percent of the time, use - -> `if (rand.nextInt(100) < p) { _...do something..._ }` - -#### Getting input - -To get a number from the player, add this method to your program: - -```java - /** - * Prints the given message (which should ask the user for some integral - * quantity), and returns the number entered by the user. If the user's - * response isn't an integer, the question is repeated until the user - * does give a integer response. - * - * @param message The request to present to the user. - * @return The user's numeric response. - */ - int getNumber(String message) { - while (true) { - System.out.print(message); - try { - return scanner.nextInt(); - } - catch (InputMismatchException e) { - System.out.println("\"" + scanner.next() + "\" isn't a number!"); - } - } - } -``` - -Here is an example of how you can use this method: - -> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` - -### Structure of the solution - -* Project name: `Hammurabi` -* Package name: `hammurabi` -* Class names and method signatures: - * `class Hammurabi` - * `public static void main(String[] args)` - * Numerous other methods, as described above. - -The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. - -### Yo! Test it! - -You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! - -But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. - -### Credits - -Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html b/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html deleted file mode 100644 index 78bbf24..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html +++ /dev/null @@ -1,299 +0,0 @@ - - - - - - - CIT591 Hammurabi - - - - - -

CIT 591 Assignment 3: - Hammurabi
- Fall 2010, David Matuszek

- -

Purpose of this assignment

- -
    -
  • To get you started using Java.
  • -
- -

General idea of the assignment

- -

Hammurabi is a very old computer game. Your job is to bring it into the - 21st century by writing it in Java.

- -

Here are the standard instructions for the game:

- -
-

Congratulations, you are the newest ruler of - ancient Samaria, elected for a ten year term of office. Your duties are to - dispense food, direct farming, and buy and sell land as needed to support - your people. Watch out for rat infestiations and the plague! Grain is the - general currency, measured in bushels. The following will help you in your - decisions:

- -
    -
  • Each person needs at least 20 bushels of - grain per year to survive
  • - -
  • Each person can farm at most 10 acres of - land
  • - -
  • It takes 2 bushels of grain to farm an acre - of land
  • - -
  • The market price for land fluctuates - yearly
  • -
- -

Rule wisely and you will be showered with - appreciation at the end of your term. Rule poorly and you will be kicked - out of office!

-
- -

Details

- -

Define a single class named Hammurabi. Use the following skeleton (but leave out the // comments):

-
package hammurabi;               // package declaration
-
-import java.util.Random;         // imports go here
-import java.util.Scanner;
-
-/**
- * The Hammurabi game.
- * @author Your name goes here
- * @author Your partner's name goes here
- */
-public class Hammurabi {         // must save in a file named Hammurabi.java
-    Random rand = new Random();  // this is an instance variable
-    Scanner scanner = new Scanner(System.in);
-
-    public static void main(String[] args) { // required in every Java program
-        new Hammurabi().playGame();
-    }
-
-    void playGame() {
-        // declare local variables here: grain, population, etc.
-        // statements go after the declations
-    }
-
-    //other methods go here
-}
-

Playing the game

-

Here is what you start the game with: -

    -
  • 100 people
  • -
  • 2800 bushels of grain in storage
  • -
  • 1000 acres of land
  • -
  • Land value is 19 bushels/acre

    -
  • -
-

Each year, print out a summary similar to the following:

-
-O great Hammurabi!
-You are in year 1 of your ten year rule.
-In the previous year 0 people starved to death.
-In the previous year 5 people entered the kingdom.
-The population is now 100.
-We harvested 3000 bushels at 3 bushels per acre.
-Rats destroyed 200 bushels, leaving 2800 bushels in storage.
-The city owns 1000 acres of land.
-Land is currently worth 19 bushels per acre.
-
- -

The above summary represents the initial state, at the beginning of - the first year--that is, when you first take office, and before you do any of - the computations below). So, for example, the previous year (under a - different ruler) must have started with 95 people; none starved, and 5 - entered the kingdom, so as you enter office you rule 100 people.

- -

Here's what your playGame method needs to do each year, for up to 10 years:

- -
-

Ask the player the following questions. These questions should be asked in this order. Do not give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below:

-
-
int askHowManyAcresToBuy(int price, int bushels)
-
Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase.
-

- int askHowManyAcresToSell(int acresOwned)
-
Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have.
- Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn.
-

- int askHowMuchGrainToFeedPeople(int bushels)
-
Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You can feed them more than they need to survive.
-

- int askHowManyAcresToPlant(int acresOwned, int population, int bushels)
-
Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year.
-
-

For each - question, do "sanity checking"; that is, test whether the answer is - possible (you have enough grain, you have enough people to do the planting - etc.), and keep asking until you get a possible value. (For example, - O Great Hammurabi, surely you jest! We have only 3415 bushels left!)

- -

Then the method needs to determine:

- -
    -
  1. If there is a plague, and how many people die from it.
  2. -
  3. How many people starved.
  4. -
  5. How many people came to the city.
  6. -
  7. How good the harvest is.
  8. -
  9. If you have a problem with rats, and how much grain they eat.
  10. -
  11. How much land costs (for deciding what to do next).
  12. -
-

These can all be local variables of your playGame method.

-

Use the following methods, in this order, to make the necessary calculations:

-
-
int plagueDeaths(int population)
-
Each year, there is a 15% chance of a horrible plague. When this - happens, half your people die. Return the number of plague deaths (possibly zero).
-

- int starvationDeaths(int population, int bushelsFedToPeople)
-
Each person needs 20 bushels of grain to survive. If you feed them - more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero).
-

- boolean uprising(int population, int howManyPeopleStarved)
-
Return true if more than - 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.)
-

- int immigrants(int population, int acresOwned, int grainInStorage)
-
Nobody will come to the city if people are starving (so don't call this method). If everyone is - well fed, compute how many people come to the city as: (20 * number of acres you have + amount of grain you have in - storage) / (100 * population) + 1.
-

- int harvest(int acres, int bushelsUsedAsSeed)
-
Choose a random integer between 1 and 6, inclusive. Each acre that was planted - with seed will yield this many bushels of grain. (Example: if you planted - 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested.
-

- int grainEatenByRats(int bushels)
-
There is a 40% chance that you will have a rat infestation. When this - happens, rats will eat somewhere between 10% and 30% of your - grain. Return the amount of grain eaten by rats (possibly zero).
-

- int newCostOfLand()
-
The price of land is random, and ranges from 17 to 23 bushels per - acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell - land.)
-
-
-

Do these computations, in this order, for each of ten years. Each - computation should be done in a separate method, and none of these methods - should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it.

- -

When the computations are finished, call a method printSummary to print the - summary for the year. This method will take several parameters.

- - -

When the game ends , use a method finalSummary to print out a final summary, and to tell the - player how good a job he/she did. I'll leave the details up to you, but the - usual evaluation is based on how many people starved, and how many acres per - person you end up with.

-

Your playGame method will be quite long, but very straightforward; it does very little but call other methods.

-

All the required arithmetic in this program should be integer. You - do not need doubles.

- -

I suggest that you first get the simplest possible version of the program - running and tested out (that is, leave out things like rats, plagues, and - immigration), then add these things one at a time to a working - program, testing as you go.

- -

Things you need to know:

- -

Random numbers

- -

To get a random number generator, you first need to import - java.util.Random (or java.util.*). Then, you can - create a random number generator with a statement such as:

- -
-

static Random rand = new Random();

-
- -

To get a new random number in the range 0..n-1, where - n is an int, call rand.nextInt(n). - To get a new random number in the range min..max, use - the expression rand.nextInt(max - min + 1) + min. You - can use the rand method in statements such as

- -
-

myNewNumber = rand.nextInt(5);
- if (rand.nextInt(100) < 15) { ... }

-
- -

To do something that happens p percent of the time, use

- -
-

if (rand.nextInt(100) < p) { ...do something... - }

-
- -

Getting input

-

To get a number from the player, add this method to your program:

-
-/**
- * Prints the given message (which should ask the user for some integral
- * quantity), and returns the number entered by the user. If the user's
- * response isn't an integer, the question is repeated until the user
- * does give a integer response.
- * 
- * @param message The request to present to the user.
- * @return The user's numeric response.
- */
- int getNumber(String message) {
-    while (true) {
-        System.out.print(message);
-        try {
-            return scanner.nextInt();
-        }
-        catch (InputMismatchException e) {
-            System.out.println("\"" + scanner.next() + "\" isn't a number!");
-        }
-    }
-}
-
- -

Here is an example of how you can use this method:

- -
-

sell = getNumber("O great Hammurabi, how many acres shall you sell?");

-
- -

Structure of the assignment:

- -
    -
  • Project name: Hammurabi
  • - -
  • Package name: hammurabi
  • - -
  • Class names and method signatures: - -
      -
    • - class Hammurabi - -
        -
      • public static void main(String[] args)
      • - -
      • Numerous other methods, as described above.
      • -
      -
    • -
    -
  • - -
- -

The above are requirements. The methods that do calculations, not input/output, will be tested by my test methods, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument names are irrelevant). You may have additional methods if you wish.

- -

Due date:

- -

Thursday, October 21, before midnight. Turn in your zipped assignment via - Blackboard. Email submissions will incur the wrath of Hammurabi (and won't be graded).

- - - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md b/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md deleted file mode 100644 index 796d85c..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md +++ /dev/null @@ -1,6 +0,0 @@ -# Notes - -from the original Dave Matuszek course of 2010. - -https://www.cis.upenn.edu/~matuszek/cit591-2010/Assignments/06-hammurabi.html - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml b/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml deleted file mode 100644 index d789654..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - 4.0.0 - - io.zipcoder - MicroLabs-Loops - 1.0-SNAPSHOT - - - - - junit - junit - 4.13.2 - - - - - - 1.8 - 1.8 - - \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore deleted file mode 100644 index a1c2a23..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore +++ /dev/null @@ -1,23 +0,0 @@ -# Compiled class file -*.class - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE deleted file mode 100644 index 22474e4..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2022 Zip Code Wilmington Core - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md deleted file mode 100644 index e4672c9..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md +++ /dev/null @@ -1,228 +0,0 @@ -# hamurabi -an ancient (in more ways than one) computer game (text) - -## General idea of the lab - -*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. - -Here are the standard instructions for the game: - -> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** -> -> * **Each person needs at least 20 bushels of grain per year to survive** -> * **Each person can farm at most 10 acres of land** -> * **It takes 2 bushels of grain to farm an acre of land** -> * **The market price for land fluctuates yearly** -> -> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** - -### Maven - -There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. - -### Details - -Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): - -```java -package hammurabi; // package declaration -import java.util.Random; // imports go here -import java.util.Scanner; - -public class Hammurabi { // must save in a file named Hammurabi.java - Random rand = new Random(); // this is an instance variable - Scanner scanner = new Scanner(System.in); - - public static void main(String\[\] args) { // required in every Java program - new Hammurabi().playGame(); - } - - void playGame() { - // declare local variables here: grain, population, etc. - // statements go after the declations - } - - //other methods go here -} -``` - -### Playing the game - -Here is what you start the game with: - -* 100 people -* 2800 bushels of grain in storage -* 1000 acres of land -* Land value is 19 bushels/acre - - -Each year, print out a summary similar to the following: - - O great Hammurabi! - You are in year 1 of your ten year rule. - In the previous year 0 people starved to death. - In the previous year 5 people entered the kingdom. - The population is now 100. - We harvested 3000 bushels at 3 bushels per acre. - Rats destroyed 200 bushels, leaving 2800 bushels in storage. - The city owns 1000 acres of land. - Land is currently worth 19 bushels per acre. - -The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. - -Here's what your `playGame` method needs to do each year, for up to 10 years: - -> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: -> -> `int askHowManyAcresToBuy(int price, int bushels)` -> -> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. -> -> ` -> int askHowManyAcresToSell(int acresOwned)` -> -> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. -> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. -> -> ` -> int askHowMuchGrainToFeedPeople(int bushels)` -> -> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. -> -> ` -> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` -> -> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. -> -> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) -> -> Then the method needs to determine: -> -> 1. If there is a plague, and how many people die from it. -> 2. How many people starved. -> 3. How many people came to the city. -> 4. How good the harvest is. -> 5. If you have a problem with rats, and how much grain they eat. -> 6. How much land costs (for deciding what to do next). -> -> These can all be local variables of your `playGame` method. -> -> Use the following methods, **in this order,** to make the necessary calculations: -> -> `int plagueDeaths(int population)` -> -> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). -> -> ` -> int starvationDeaths(int population, int bushelsFedToPeople)` -> -> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). -> -> ` -> boolean uprising(int population, int howManyPeopleStarved)` -> -> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) -> -> ` -> int immigrants(int population, int acresOwned, int grainInStorage)` -> -> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. -> -> ` -> int harvest(int acres, int bushelsUsedAsSeed)` -> -> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. -> -> ` -> int grainEatenByRats(int bushels)` -> -> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). -> -> ` -> int newCostOfLand()` -> -> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) - -Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. - -When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. - -When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. - -Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. - -All the required arithmetic in this program should be **integer**. You do not need doubles. - -### Urgent! - -> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. - -### Things you need to know: - -#### Random numbers - -To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: - -> `static Random rand = new Random();` - -To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as - -> `myNewNumber = rand.nextInt(5); -> if (rand.nextInt(100) < 15) { ... }` - -To do something that happens `p` percent of the time, use - -> `if (rand.nextInt(100) < p) { _...do something..._ }` - -#### Getting input - -To get a number from the player, add this method to your program: - -```java - /** - * Prints the given message (which should ask the user for some integral - * quantity), and returns the number entered by the user. If the user's - * response isn't an integer, the question is repeated until the user - * does give a integer response. - * - * @param message The request to present to the user. - * @return The user's numeric response. - */ - int getNumber(String message) { - while (true) { - System.out.print(message); - try { - return scanner.nextInt(); - } - catch (InputMismatchException e) { - System.out.println("\"" + scanner.next() + "\" isn't a number!"); - } - } - } -``` - -Here is an example of how you can use this method: - -> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` - -### Structure of the solution - -* Project name: `Hammurabi` -* Package name: `hammurabi` -* Class names and method signatures: - * `class Hammurabi` - * `public static void main(String[] args)` - * Numerous other methods, as described above. - -The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. - -### Yo! Test it! - -You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! - -But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. - -### Credits - -Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html deleted file mode 100644 index 78bbf24..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html +++ /dev/null @@ -1,299 +0,0 @@ - - - - - - - CIT591 Hammurabi - - - - - -

CIT 591 Assignment 3: - Hammurabi
- Fall 2010, David Matuszek

- -

Purpose of this assignment

- -
    -
  • To get you started using Java.
  • -
- -

General idea of the assignment

- -

Hammurabi is a very old computer game. Your job is to bring it into the - 21st century by writing it in Java.

- -

Here are the standard instructions for the game:

- -
-

Congratulations, you are the newest ruler of - ancient Samaria, elected for a ten year term of office. Your duties are to - dispense food, direct farming, and buy and sell land as needed to support - your people. Watch out for rat infestiations and the plague! Grain is the - general currency, measured in bushels. The following will help you in your - decisions:

- -
    -
  • Each person needs at least 20 bushels of - grain per year to survive
  • - -
  • Each person can farm at most 10 acres of - land
  • - -
  • It takes 2 bushels of grain to farm an acre - of land
  • - -
  • The market price for land fluctuates - yearly
  • -
- -

Rule wisely and you will be showered with - appreciation at the end of your term. Rule poorly and you will be kicked - out of office!

-
- -

Details

- -

Define a single class named Hammurabi. Use the following skeleton (but leave out the // comments):

-
package hammurabi;               // package declaration
-
-import java.util.Random;         // imports go here
-import java.util.Scanner;
-
-/**
- * The Hammurabi game.
- * @author Your name goes here
- * @author Your partner's name goes here
- */
-public class Hammurabi {         // must save in a file named Hammurabi.java
-    Random rand = new Random();  // this is an instance variable
-    Scanner scanner = new Scanner(System.in);
-
-    public static void main(String[] args) { // required in every Java program
-        new Hammurabi().playGame();
-    }
-
-    void playGame() {
-        // declare local variables here: grain, population, etc.
-        // statements go after the declations
-    }
-
-    //other methods go here
-}
-

Playing the game

-

Here is what you start the game with: -

    -
  • 100 people
  • -
  • 2800 bushels of grain in storage
  • -
  • 1000 acres of land
  • -
  • Land value is 19 bushels/acre

    -
  • -
-

Each year, print out a summary similar to the following:

-
-O great Hammurabi!
-You are in year 1 of your ten year rule.
-In the previous year 0 people starved to death.
-In the previous year 5 people entered the kingdom.
-The population is now 100.
-We harvested 3000 bushels at 3 bushels per acre.
-Rats destroyed 200 bushels, leaving 2800 bushels in storage.
-The city owns 1000 acres of land.
-Land is currently worth 19 bushels per acre.
-
- -

The above summary represents the initial state, at the beginning of - the first year--that is, when you first take office, and before you do any of - the computations below). So, for example, the previous year (under a - different ruler) must have started with 95 people; none starved, and 5 - entered the kingdom, so as you enter office you rule 100 people.

- -

Here's what your playGame method needs to do each year, for up to 10 years:

- -
-

Ask the player the following questions. These questions should be asked in this order. Do not give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below:

-
-
int askHowManyAcresToBuy(int price, int bushels)
-
Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase.
-

- int askHowManyAcresToSell(int acresOwned)
-
Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have.
- Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn.
-

- int askHowMuchGrainToFeedPeople(int bushels)
-
Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You can feed them more than they need to survive.
-

- int askHowManyAcresToPlant(int acresOwned, int population, int bushels)
-
Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year.
-
-

For each - question, do "sanity checking"; that is, test whether the answer is - possible (you have enough grain, you have enough people to do the planting - etc.), and keep asking until you get a possible value. (For example, - O Great Hammurabi, surely you jest! We have only 3415 bushels left!)

- -

Then the method needs to determine:

- -
    -
  1. If there is a plague, and how many people die from it.
  2. -
  3. How many people starved.
  4. -
  5. How many people came to the city.
  6. -
  7. How good the harvest is.
  8. -
  9. If you have a problem with rats, and how much grain they eat.
  10. -
  11. How much land costs (for deciding what to do next).
  12. -
-

These can all be local variables of your playGame method.

-

Use the following methods, in this order, to make the necessary calculations:

-
-
int plagueDeaths(int population)
-
Each year, there is a 15% chance of a horrible plague. When this - happens, half your people die. Return the number of plague deaths (possibly zero).
-

- int starvationDeaths(int population, int bushelsFedToPeople)
-
Each person needs 20 bushels of grain to survive. If you feed them - more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero).
-

- boolean uprising(int population, int howManyPeopleStarved)
-
Return true if more than - 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.)
-

- int immigrants(int population, int acresOwned, int grainInStorage)
-
Nobody will come to the city if people are starving (so don't call this method). If everyone is - well fed, compute how many people come to the city as: (20 * number of acres you have + amount of grain you have in - storage) / (100 * population) + 1.
-

- int harvest(int acres, int bushelsUsedAsSeed)
-
Choose a random integer between 1 and 6, inclusive. Each acre that was planted - with seed will yield this many bushels of grain. (Example: if you planted - 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested.
-

- int grainEatenByRats(int bushels)
-
There is a 40% chance that you will have a rat infestation. When this - happens, rats will eat somewhere between 10% and 30% of your - grain. Return the amount of grain eaten by rats (possibly zero).
-

- int newCostOfLand()
-
The price of land is random, and ranges from 17 to 23 bushels per - acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell - land.)
-
-
-

Do these computations, in this order, for each of ten years. Each - computation should be done in a separate method, and none of these methods - should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it.

- -

When the computations are finished, call a method printSummary to print the - summary for the year. This method will take several parameters.

- - -

When the game ends , use a method finalSummary to print out a final summary, and to tell the - player how good a job he/she did. I'll leave the details up to you, but the - usual evaluation is based on how many people starved, and how many acres per - person you end up with.

-

Your playGame method will be quite long, but very straightforward; it does very little but call other methods.

-

All the required arithmetic in this program should be integer. You - do not need doubles.

- -

I suggest that you first get the simplest possible version of the program - running and tested out (that is, leave out things like rats, plagues, and - immigration), then add these things one at a time to a working - program, testing as you go.

- -

Things you need to know:

- -

Random numbers

- -

To get a random number generator, you first need to import - java.util.Random (or java.util.*). Then, you can - create a random number generator with a statement such as:

- -
-

static Random rand = new Random();

-
- -

To get a new random number in the range 0..n-1, where - n is an int, call rand.nextInt(n). - To get a new random number in the range min..max, use - the expression rand.nextInt(max - min + 1) + min. You - can use the rand method in statements such as

- -
-

myNewNumber = rand.nextInt(5);
- if (rand.nextInt(100) < 15) { ... }

-
- -

To do something that happens p percent of the time, use

- -
-

if (rand.nextInt(100) < p) { ...do something... - }

-
- -

Getting input

-

To get a number from the player, add this method to your program:

-
-/**
- * Prints the given message (which should ask the user for some integral
- * quantity), and returns the number entered by the user. If the user's
- * response isn't an integer, the question is repeated until the user
- * does give a integer response.
- * 
- * @param message The request to present to the user.
- * @return The user's numeric response.
- */
- int getNumber(String message) {
-    while (true) {
-        System.out.print(message);
-        try {
-            return scanner.nextInt();
-        }
-        catch (InputMismatchException e) {
-            System.out.println("\"" + scanner.next() + "\" isn't a number!");
-        }
-    }
-}
-
- -

Here is an example of how you can use this method:

- -
-

sell = getNumber("O great Hammurabi, how many acres shall you sell?");

-
- -

Structure of the assignment:

- -
    -
  • Project name: Hammurabi
  • - -
  • Package name: hammurabi
  • - -
  • Class names and method signatures: - -
      -
    • - class Hammurabi - -
        -
      • public static void main(String[] args)
      • - -
      • Numerous other methods, as described above.
      • -
      -
    • -
    -
  • - -
- -

The above are requirements. The methods that do calculations, not input/output, will be tested by my test methods, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument names are irrelevant). You may have additional methods if you wish.

- -

Due date:

- -

Thursday, October 21, before midnight. Turn in your zipped assignment via - Blackboard. Email submissions will incur the wrath of Hammurabi (and won't be graded).

- - - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md deleted file mode 100644 index 796d85c..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md +++ /dev/null @@ -1,6 +0,0 @@ -# Notes - -from the original Dave Matuszek course of 2010. - -https://www.cis.upenn.edu/~matuszek/cit591-2010/Assignments/06-hammurabi.html - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml deleted file mode 100644 index d789654..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - 4.0.0 - - io.zipcoder - MicroLabs-Loops - 1.0-SNAPSHOT - - - - - junit - junit - 4.13.2 - - - - - - 1.8 - 1.8 - - \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore deleted file mode 100644 index a1c2a23..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore +++ /dev/null @@ -1,23 +0,0 @@ -# Compiled class file -*.class - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE deleted file mode 100644 index 22474e4..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2022 Zip Code Wilmington Core - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md deleted file mode 100644 index e4672c9..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md +++ /dev/null @@ -1,228 +0,0 @@ -# hamurabi -an ancient (in more ways than one) computer game (text) - -## General idea of the lab - -*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. - -Here are the standard instructions for the game: - -> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** -> -> * **Each person needs at least 20 bushels of grain per year to survive** -> * **Each person can farm at most 10 acres of land** -> * **It takes 2 bushels of grain to farm an acre of land** -> * **The market price for land fluctuates yearly** -> -> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** - -### Maven - -There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. - -### Details - -Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): - -```java -package hammurabi; // package declaration -import java.util.Random; // imports go here -import java.util.Scanner; - -public class Hammurabi { // must save in a file named Hammurabi.java - Random rand = new Random(); // this is an instance variable - Scanner scanner = new Scanner(System.in); - - public static void main(String\[\] args) { // required in every Java program - new Hammurabi().playGame(); - } - - void playGame() { - // declare local variables here: grain, population, etc. - // statements go after the declations - } - - //other methods go here -} -``` - -### Playing the game - -Here is what you start the game with: - -* 100 people -* 2800 bushels of grain in storage -* 1000 acres of land -* Land value is 19 bushels/acre - - -Each year, print out a summary similar to the following: - - O great Hammurabi! - You are in year 1 of your ten year rule. - In the previous year 0 people starved to death. - In the previous year 5 people entered the kingdom. - The population is now 100. - We harvested 3000 bushels at 3 bushels per acre. - Rats destroyed 200 bushels, leaving 2800 bushels in storage. - The city owns 1000 acres of land. - Land is currently worth 19 bushels per acre. - -The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. - -Here's what your `playGame` method needs to do each year, for up to 10 years: - -> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: -> -> `int askHowManyAcresToBuy(int price, int bushels)` -> -> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. -> -> ` -> int askHowManyAcresToSell(int acresOwned)` -> -> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. -> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. -> -> ` -> int askHowMuchGrainToFeedPeople(int bushels)` -> -> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. -> -> ` -> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` -> -> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. -> -> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) -> -> Then the method needs to determine: -> -> 1. If there is a plague, and how many people die from it. -> 2. How many people starved. -> 3. How many people came to the city. -> 4. How good the harvest is. -> 5. If you have a problem with rats, and how much grain they eat. -> 6. How much land costs (for deciding what to do next). -> -> These can all be local variables of your `playGame` method. -> -> Use the following methods, **in this order,** to make the necessary calculations: -> -> `int plagueDeaths(int population)` -> -> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). -> -> ` -> int starvationDeaths(int population, int bushelsFedToPeople)` -> -> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). -> -> ` -> boolean uprising(int population, int howManyPeopleStarved)` -> -> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) -> -> ` -> int immigrants(int population, int acresOwned, int grainInStorage)` -> -> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. -> -> ` -> int harvest(int acres, int bushelsUsedAsSeed)` -> -> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. -> -> ` -> int grainEatenByRats(int bushels)` -> -> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). -> -> ` -> int newCostOfLand()` -> -> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) - -Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. - -When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. - -When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. - -Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. - -All the required arithmetic in this program should be **integer**. You do not need doubles. - -### Urgent! - -> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. - -### Things you need to know: - -#### Random numbers - -To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: - -> `static Random rand = new Random();` - -To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as - -> `myNewNumber = rand.nextInt(5); -> if (rand.nextInt(100) < 15) { ... }` - -To do something that happens `p` percent of the time, use - -> `if (rand.nextInt(100) < p) { _...do something..._ }` - -#### Getting input - -To get a number from the player, add this method to your program: - -```java - /** - * Prints the given message (which should ask the user for some integral - * quantity), and returns the number entered by the user. If the user's - * response isn't an integer, the question is repeated until the user - * does give a integer response. - * - * @param message The request to present to the user. - * @return The user's numeric response. - */ - int getNumber(String message) { - while (true) { - System.out.print(message); - try { - return scanner.nextInt(); - } - catch (InputMismatchException e) { - System.out.println("\"" + scanner.next() + "\" isn't a number!"); - } - } - } -``` - -Here is an example of how you can use this method: - -> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` - -### Structure of the solution - -* Project name: `Hammurabi` -* Package name: `hammurabi` -* Class names and method signatures: - * `class Hammurabi` - * `public static void main(String[] args)` - * Numerous other methods, as described above. - -The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. - -### Yo! Test it! - -You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! - -But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. - -### Credits - -Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html deleted file mode 100644 index 78bbf24..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html +++ /dev/null @@ -1,299 +0,0 @@ - - - - - - - CIT591 Hammurabi - - - - - -

CIT 591 Assignment 3: - Hammurabi
- Fall 2010, David Matuszek

- -

Purpose of this assignment

- -
    -
  • To get you started using Java.
  • -
- -

General idea of the assignment

- -

Hammurabi is a very old computer game. Your job is to bring it into the - 21st century by writing it in Java.

- -

Here are the standard instructions for the game:

- -
-

Congratulations, you are the newest ruler of - ancient Samaria, elected for a ten year term of office. Your duties are to - dispense food, direct farming, and buy and sell land as needed to support - your people. Watch out for rat infestiations and the plague! Grain is the - general currency, measured in bushels. The following will help you in your - decisions:

- -
    -
  • Each person needs at least 20 bushels of - grain per year to survive
  • - -
  • Each person can farm at most 10 acres of - land
  • - -
  • It takes 2 bushels of grain to farm an acre - of land
  • - -
  • The market price for land fluctuates - yearly
  • -
- -

Rule wisely and you will be showered with - appreciation at the end of your term. Rule poorly and you will be kicked - out of office!

-
- -

Details

- -

Define a single class named Hammurabi. Use the following skeleton (but leave out the // comments):

-
package hammurabi;               // package declaration
-
-import java.util.Random;         // imports go here
-import java.util.Scanner;
-
-/**
- * The Hammurabi game.
- * @author Your name goes here
- * @author Your partner's name goes here
- */
-public class Hammurabi {         // must save in a file named Hammurabi.java
-    Random rand = new Random();  // this is an instance variable
-    Scanner scanner = new Scanner(System.in);
-
-    public static void main(String[] args) { // required in every Java program
-        new Hammurabi().playGame();
-    }
-
-    void playGame() {
-        // declare local variables here: grain, population, etc.
-        // statements go after the declations
-    }
-
-    //other methods go here
-}
-

Playing the game

-

Here is what you start the game with: -

    -
  • 100 people
  • -
  • 2800 bushels of grain in storage
  • -
  • 1000 acres of land
  • -
  • Land value is 19 bushels/acre

    -
  • -
-

Each year, print out a summary similar to the following:

-
-O great Hammurabi!
-You are in year 1 of your ten year rule.
-In the previous year 0 people starved to death.
-In the previous year 5 people entered the kingdom.
-The population is now 100.
-We harvested 3000 bushels at 3 bushels per acre.
-Rats destroyed 200 bushels, leaving 2800 bushels in storage.
-The city owns 1000 acres of land.
-Land is currently worth 19 bushels per acre.
-
- -

The above summary represents the initial state, at the beginning of - the first year--that is, when you first take office, and before you do any of - the computations below). So, for example, the previous year (under a - different ruler) must have started with 95 people; none starved, and 5 - entered the kingdom, so as you enter office you rule 100 people.

- -

Here's what your playGame method needs to do each year, for up to 10 years:

- -
-

Ask the player the following questions. These questions should be asked in this order. Do not give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below:

-
-
int askHowManyAcresToBuy(int price, int bushels)
-
Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase.
-

- int askHowManyAcresToSell(int acresOwned)
-
Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have.
- Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn.
-

- int askHowMuchGrainToFeedPeople(int bushels)
-
Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You can feed them more than they need to survive.
-

- int askHowManyAcresToPlant(int acresOwned, int population, int bushels)
-
Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year.
-
-

For each - question, do "sanity checking"; that is, test whether the answer is - possible (you have enough grain, you have enough people to do the planting - etc.), and keep asking until you get a possible value. (For example, - O Great Hammurabi, surely you jest! We have only 3415 bushels left!)

- -

Then the method needs to determine:

- -
    -
  1. If there is a plague, and how many people die from it.
  2. -
  3. How many people starved.
  4. -
  5. How many people came to the city.
  6. -
  7. How good the harvest is.
  8. -
  9. If you have a problem with rats, and how much grain they eat.
  10. -
  11. How much land costs (for deciding what to do next).
  12. -
-

These can all be local variables of your playGame method.

-

Use the following methods, in this order, to make the necessary calculations:

-
-
int plagueDeaths(int population)
-
Each year, there is a 15% chance of a horrible plague. When this - happens, half your people die. Return the number of plague deaths (possibly zero).
-

- int starvationDeaths(int population, int bushelsFedToPeople)
-
Each person needs 20 bushels of grain to survive. If you feed them - more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero).
-

- boolean uprising(int population, int howManyPeopleStarved)
-
Return true if more than - 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.)
-

- int immigrants(int population, int acresOwned, int grainInStorage)
-
Nobody will come to the city if people are starving (so don't call this method). If everyone is - well fed, compute how many people come to the city as: (20 * number of acres you have + amount of grain you have in - storage) / (100 * population) + 1.
-

- int harvest(int acres, int bushelsUsedAsSeed)
-
Choose a random integer between 1 and 6, inclusive. Each acre that was planted - with seed will yield this many bushels of grain. (Example: if you planted - 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested.
-

- int grainEatenByRats(int bushels)
-
There is a 40% chance that you will have a rat infestation. When this - happens, rats will eat somewhere between 10% and 30% of your - grain. Return the amount of grain eaten by rats (possibly zero).
-

- int newCostOfLand()
-
The price of land is random, and ranges from 17 to 23 bushels per - acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell - land.)
-
-
-

Do these computations, in this order, for each of ten years. Each - computation should be done in a separate method, and none of these methods - should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it.

- -

When the computations are finished, call a method printSummary to print the - summary for the year. This method will take several parameters.

- - -

When the game ends , use a method finalSummary to print out a final summary, and to tell the - player how good a job he/she did. I'll leave the details up to you, but the - usual evaluation is based on how many people starved, and how many acres per - person you end up with.

-

Your playGame method will be quite long, but very straightforward; it does very little but call other methods.

-

All the required arithmetic in this program should be integer. You - do not need doubles.

- -

I suggest that you first get the simplest possible version of the program - running and tested out (that is, leave out things like rats, plagues, and - immigration), then add these things one at a time to a working - program, testing as you go.

- -

Things you need to know:

- -

Random numbers

- -

To get a random number generator, you first need to import - java.util.Random (or java.util.*). Then, you can - create a random number generator with a statement such as:

- -
-

static Random rand = new Random();

-
- -

To get a new random number in the range 0..n-1, where - n is an int, call rand.nextInt(n). - To get a new random number in the range min..max, use - the expression rand.nextInt(max - min + 1) + min. You - can use the rand method in statements such as

- -
-

myNewNumber = rand.nextInt(5);
- if (rand.nextInt(100) < 15) { ... }

-
- -

To do something that happens p percent of the time, use

- -
-

if (rand.nextInt(100) < p) { ...do something... - }

-
- -

Getting input

-

To get a number from the player, add this method to your program:

-
-/**
- * Prints the given message (which should ask the user for some integral
- * quantity), and returns the number entered by the user. If the user's
- * response isn't an integer, the question is repeated until the user
- * does give a integer response.
- * 
- * @param message The request to present to the user.
- * @return The user's numeric response.
- */
- int getNumber(String message) {
-    while (true) {
-        System.out.print(message);
-        try {
-            return scanner.nextInt();
-        }
-        catch (InputMismatchException e) {
-            System.out.println("\"" + scanner.next() + "\" isn't a number!");
-        }
-    }
-}
-
- -

Here is an example of how you can use this method:

- -
-

sell = getNumber("O great Hammurabi, how many acres shall you sell?");

-
- -

Structure of the assignment:

- -
    -
  • Project name: Hammurabi
  • - -
  • Package name: hammurabi
  • - -
  • Class names and method signatures: - -
      -
    • - class Hammurabi - -
        -
      • public static void main(String[] args)
      • - -
      • Numerous other methods, as described above.
      • -
      -
    • -
    -
  • - -
- -

The above are requirements. The methods that do calculations, not input/output, will be tested by my test methods, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument names are irrelevant). You may have additional methods if you wish.

- -

Due date:

- -

Thursday, October 21, before midnight. Turn in your zipped assignment via - Blackboard. Email submissions will incur the wrath of Hammurabi (and won't be graded).

- - - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md deleted file mode 100644 index 796d85c..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md +++ /dev/null @@ -1,6 +0,0 @@ -# Notes - -from the original Dave Matuszek course of 2010. - -https://www.cis.upenn.edu/~matuszek/cit591-2010/Assignments/06-hammurabi.html - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml deleted file mode 100644 index d789654..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - 4.0.0 - - io.zipcoder - MicroLabs-Loops - 1.0-SNAPSHOT - - - - - junit - junit - 4.13.2 - - - - - - 1.8 - 1.8 - - \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore deleted file mode 100644 index a1c2a23..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore +++ /dev/null @@ -1,23 +0,0 @@ -# Compiled class file -*.class - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE deleted file mode 100644 index 22474e4..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2022 Zip Code Wilmington Core - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md deleted file mode 100644 index e4672c9..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md +++ /dev/null @@ -1,228 +0,0 @@ -# hamurabi -an ancient (in more ways than one) computer game (text) - -## General idea of the lab - -*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. - -Here are the standard instructions for the game: - -> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** -> -> * **Each person needs at least 20 bushels of grain per year to survive** -> * **Each person can farm at most 10 acres of land** -> * **It takes 2 bushels of grain to farm an acre of land** -> * **The market price for land fluctuates yearly** -> -> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** - -### Maven - -There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. - -### Details - -Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): - -```java -package hammurabi; // package declaration -import java.util.Random; // imports go here -import java.util.Scanner; - -public class Hammurabi { // must save in a file named Hammurabi.java - Random rand = new Random(); // this is an instance variable - Scanner scanner = new Scanner(System.in); - - public static void main(String\[\] args) { // required in every Java program - new Hammurabi().playGame(); - } - - void playGame() { - // declare local variables here: grain, population, etc. - // statements go after the declations - } - - //other methods go here -} -``` - -### Playing the game - -Here is what you start the game with: - -* 100 people -* 2800 bushels of grain in storage -* 1000 acres of land -* Land value is 19 bushels/acre - - -Each year, print out a summary similar to the following: - - O great Hammurabi! - You are in year 1 of your ten year rule. - In the previous year 0 people starved to death. - In the previous year 5 people entered the kingdom. - The population is now 100. - We harvested 3000 bushels at 3 bushels per acre. - Rats destroyed 200 bushels, leaving 2800 bushels in storage. - The city owns 1000 acres of land. - Land is currently worth 19 bushels per acre. - -The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. - -Here's what your `playGame` method needs to do each year, for up to 10 years: - -> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: -> -> `int askHowManyAcresToBuy(int price, int bushels)` -> -> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. -> -> ` -> int askHowManyAcresToSell(int acresOwned)` -> -> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. -> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. -> -> ` -> int askHowMuchGrainToFeedPeople(int bushels)` -> -> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. -> -> ` -> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` -> -> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. -> -> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) -> -> Then the method needs to determine: -> -> 1. If there is a plague, and how many people die from it. -> 2. How many people starved. -> 3. How many people came to the city. -> 4. How good the harvest is. -> 5. If you have a problem with rats, and how much grain they eat. -> 6. How much land costs (for deciding what to do next). -> -> These can all be local variables of your `playGame` method. -> -> Use the following methods, **in this order,** to make the necessary calculations: -> -> `int plagueDeaths(int population)` -> -> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). -> -> ` -> int starvationDeaths(int population, int bushelsFedToPeople)` -> -> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). -> -> ` -> boolean uprising(int population, int howManyPeopleStarved)` -> -> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) -> -> ` -> int immigrants(int population, int acresOwned, int grainInStorage)` -> -> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. -> -> ` -> int harvest(int acres, int bushelsUsedAsSeed)` -> -> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. -> -> ` -> int grainEatenByRats(int bushels)` -> -> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). -> -> ` -> int newCostOfLand()` -> -> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) - -Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. - -When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. - -When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. - -Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. - -All the required arithmetic in this program should be **integer**. You do not need doubles. - -### Urgent! - -> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. - -### Things you need to know: - -#### Random numbers - -To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: - -> `static Random rand = new Random();` - -To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as - -> `myNewNumber = rand.nextInt(5); -> if (rand.nextInt(100) < 15) { ... }` - -To do something that happens `p` percent of the time, use - -> `if (rand.nextInt(100) < p) { _...do something..._ }` - -#### Getting input - -To get a number from the player, add this method to your program: - -```java - /** - * Prints the given message (which should ask the user for some integral - * quantity), and returns the number entered by the user. If the user's - * response isn't an integer, the question is repeated until the user - * does give a integer response. - * - * @param message The request to present to the user. - * @return The user's numeric response. - */ - int getNumber(String message) { - while (true) { - System.out.print(message); - try { - return scanner.nextInt(); - } - catch (InputMismatchException e) { - System.out.println("\"" + scanner.next() + "\" isn't a number!"); - } - } - } -``` - -Here is an example of how you can use this method: - -> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` - -### Structure of the solution - -* Project name: `Hammurabi` -* Package name: `hammurabi` -* Class names and method signatures: - * `class Hammurabi` - * `public static void main(String[] args)` - * Numerous other methods, as described above. - -The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. - -### Yo! Test it! - -You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! - -But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. - -### Credits - -Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html deleted file mode 100644 index 78bbf24..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html +++ /dev/null @@ -1,299 +0,0 @@ - - - - - - - CIT591 Hammurabi - - - - - -

CIT 591 Assignment 3: - Hammurabi
- Fall 2010, David Matuszek

- -

Purpose of this assignment

- -
    -
  • To get you started using Java.
  • -
- -

General idea of the assignment

- -

Hammurabi is a very old computer game. Your job is to bring it into the - 21st century by writing it in Java.

- -

Here are the standard instructions for the game:

- -
-

Congratulations, you are the newest ruler of - ancient Samaria, elected for a ten year term of office. Your duties are to - dispense food, direct farming, and buy and sell land as needed to support - your people. Watch out for rat infestiations and the plague! Grain is the - general currency, measured in bushels. The following will help you in your - decisions:

- -
    -
  • Each person needs at least 20 bushels of - grain per year to survive
  • - -
  • Each person can farm at most 10 acres of - land
  • - -
  • It takes 2 bushels of grain to farm an acre - of land
  • - -
  • The market price for land fluctuates - yearly
  • -
- -

Rule wisely and you will be showered with - appreciation at the end of your term. Rule poorly and you will be kicked - out of office!

-
- -

Details

- -

Define a single class named Hammurabi. Use the following skeleton (but leave out the // comments):

-
package hammurabi;               // package declaration
-
-import java.util.Random;         // imports go here
-import java.util.Scanner;
-
-/**
- * The Hammurabi game.
- * @author Your name goes here
- * @author Your partner's name goes here
- */
-public class Hammurabi {         // must save in a file named Hammurabi.java
-    Random rand = new Random();  // this is an instance variable
-    Scanner scanner = new Scanner(System.in);
-
-    public static void main(String[] args) { // required in every Java program
-        new Hammurabi().playGame();
-    }
-
-    void playGame() {
-        // declare local variables here: grain, population, etc.
-        // statements go after the declations
-    }
-
-    //other methods go here
-}
-

Playing the game

-

Here is what you start the game with: -

    -
  • 100 people
  • -
  • 2800 bushels of grain in storage
  • -
  • 1000 acres of land
  • -
  • Land value is 19 bushels/acre

    -
  • -
-

Each year, print out a summary similar to the following:

-
-O great Hammurabi!
-You are in year 1 of your ten year rule.
-In the previous year 0 people starved to death.
-In the previous year 5 people entered the kingdom.
-The population is now 100.
-We harvested 3000 bushels at 3 bushels per acre.
-Rats destroyed 200 bushels, leaving 2800 bushels in storage.
-The city owns 1000 acres of land.
-Land is currently worth 19 bushels per acre.
-
- -

The above summary represents the initial state, at the beginning of - the first year--that is, when you first take office, and before you do any of - the computations below). So, for example, the previous year (under a - different ruler) must have started with 95 people; none starved, and 5 - entered the kingdom, so as you enter office you rule 100 people.

- -

Here's what your playGame method needs to do each year, for up to 10 years:

- -
-

Ask the player the following questions. These questions should be asked in this order. Do not give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below:

-
-
int askHowManyAcresToBuy(int price, int bushels)
-
Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase.
-

- int askHowManyAcresToSell(int acresOwned)
-
Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have.
- Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn.
-

- int askHowMuchGrainToFeedPeople(int bushels)
-
Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You can feed them more than they need to survive.
-

- int askHowManyAcresToPlant(int acresOwned, int population, int bushels)
-
Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year.
-
-

For each - question, do "sanity checking"; that is, test whether the answer is - possible (you have enough grain, you have enough people to do the planting - etc.), and keep asking until you get a possible value. (For example, - O Great Hammurabi, surely you jest! We have only 3415 bushels left!)

- -

Then the method needs to determine:

- -
    -
  1. If there is a plague, and how many people die from it.
  2. -
  3. How many people starved.
  4. -
  5. How many people came to the city.
  6. -
  7. How good the harvest is.
  8. -
  9. If you have a problem with rats, and how much grain they eat.
  10. -
  11. How much land costs (for deciding what to do next).
  12. -
-

These can all be local variables of your playGame method.

-

Use the following methods, in this order, to make the necessary calculations:

-
-
int plagueDeaths(int population)
-
Each year, there is a 15% chance of a horrible plague. When this - happens, half your people die. Return the number of plague deaths (possibly zero).
-

- int starvationDeaths(int population, int bushelsFedToPeople)
-
Each person needs 20 bushels of grain to survive. If you feed them - more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero).
-

- boolean uprising(int population, int howManyPeopleStarved)
-
Return true if more than - 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.)
-

- int immigrants(int population, int acresOwned, int grainInStorage)
-
Nobody will come to the city if people are starving (so don't call this method). If everyone is - well fed, compute how many people come to the city as: (20 * number of acres you have + amount of grain you have in - storage) / (100 * population) + 1.
-

- int harvest(int acres, int bushelsUsedAsSeed)
-
Choose a random integer between 1 and 6, inclusive. Each acre that was planted - with seed will yield this many bushels of grain. (Example: if you planted - 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested.
-

- int grainEatenByRats(int bushels)
-
There is a 40% chance that you will have a rat infestation. When this - happens, rats will eat somewhere between 10% and 30% of your - grain. Return the amount of grain eaten by rats (possibly zero).
-

- int newCostOfLand()
-
The price of land is random, and ranges from 17 to 23 bushels per - acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell - land.)
-
-
-

Do these computations, in this order, for each of ten years. Each - computation should be done in a separate method, and none of these methods - should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it.

- -

When the computations are finished, call a method printSummary to print the - summary for the year. This method will take several parameters.

- - -

When the game ends , use a method finalSummary to print out a final summary, and to tell the - player how good a job he/she did. I'll leave the details up to you, but the - usual evaluation is based on how many people starved, and how many acres per - person you end up with.

-

Your playGame method will be quite long, but very straightforward; it does very little but call other methods.

-

All the required arithmetic in this program should be integer. You - do not need doubles.

- -

I suggest that you first get the simplest possible version of the program - running and tested out (that is, leave out things like rats, plagues, and - immigration), then add these things one at a time to a working - program, testing as you go.

- -

Things you need to know:

- -

Random numbers

- -

To get a random number generator, you first need to import - java.util.Random (or java.util.*). Then, you can - create a random number generator with a statement such as:

- -
-

static Random rand = new Random();

-
- -

To get a new random number in the range 0..n-1, where - n is an int, call rand.nextInt(n). - To get a new random number in the range min..max, use - the expression rand.nextInt(max - min + 1) + min. You - can use the rand method in statements such as

- -
-

myNewNumber = rand.nextInt(5);
- if (rand.nextInt(100) < 15) { ... }

-
- -

To do something that happens p percent of the time, use

- -
-

if (rand.nextInt(100) < p) { ...do something... - }

-
- -

Getting input

-

To get a number from the player, add this method to your program:

-
-/**
- * Prints the given message (which should ask the user for some integral
- * quantity), and returns the number entered by the user. If the user's
- * response isn't an integer, the question is repeated until the user
- * does give a integer response.
- * 
- * @param message The request to present to the user.
- * @return The user's numeric response.
- */
- int getNumber(String message) {
-    while (true) {
-        System.out.print(message);
-        try {
-            return scanner.nextInt();
-        }
-        catch (InputMismatchException e) {
-            System.out.println("\"" + scanner.next() + "\" isn't a number!");
-        }
-    }
-}
-
- -

Here is an example of how you can use this method:

- -
-

sell = getNumber("O great Hammurabi, how many acres shall you sell?");

-
- -

Structure of the assignment:

- -
    -
  • Project name: Hammurabi
  • - -
  • Package name: hammurabi
  • - -
  • Class names and method signatures: - -
      -
    • - class Hammurabi - -
        -
      • public static void main(String[] args)
      • - -
      • Numerous other methods, as described above.
      • -
      -
    • -
    -
  • - -
- -

The above are requirements. The methods that do calculations, not input/output, will be tested by my test methods, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument names are irrelevant). You may have additional methods if you wish.

- -

Due date:

- -

Thursday, October 21, before midnight. Turn in your zipped assignment via - Blackboard. Email submissions will incur the wrath of Hammurabi (and won't be graded).

- - - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md deleted file mode 100644 index 796d85c..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md +++ /dev/null @@ -1,6 +0,0 @@ -# Notes - -from the original Dave Matuszek course of 2010. - -https://www.cis.upenn.edu/~matuszek/cit591-2010/Assignments/06-hammurabi.html - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml deleted file mode 100644 index d789654..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - 4.0.0 - - io.zipcoder - MicroLabs-Loops - 1.0-SNAPSHOT - - - - - junit - junit - 4.13.2 - - - - - - 1.8 - 1.8 - - \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore deleted file mode 100644 index a1c2a23..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore +++ /dev/null @@ -1,23 +0,0 @@ -# Compiled class file -*.class - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE deleted file mode 100644 index 22474e4..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2022 Zip Code Wilmington Core - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md deleted file mode 100644 index e4672c9..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md +++ /dev/null @@ -1,228 +0,0 @@ -# hamurabi -an ancient (in more ways than one) computer game (text) - -## General idea of the lab - -*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. - -Here are the standard instructions for the game: - -> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** -> -> * **Each person needs at least 20 bushels of grain per year to survive** -> * **Each person can farm at most 10 acres of land** -> * **It takes 2 bushels of grain to farm an acre of land** -> * **The market price for land fluctuates yearly** -> -> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** - -### Maven - -There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. - -### Details - -Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): - -```java -package hammurabi; // package declaration -import java.util.Random; // imports go here -import java.util.Scanner; - -public class Hammurabi { // must save in a file named Hammurabi.java - Random rand = new Random(); // this is an instance variable - Scanner scanner = new Scanner(System.in); - - public static void main(String\[\] args) { // required in every Java program - new Hammurabi().playGame(); - } - - void playGame() { - // declare local variables here: grain, population, etc. - // statements go after the declations - } - - //other methods go here -} -``` - -### Playing the game - -Here is what you start the game with: - -* 100 people -* 2800 bushels of grain in storage -* 1000 acres of land -* Land value is 19 bushels/acre - - -Each year, print out a summary similar to the following: - - O great Hammurabi! - You are in year 1 of your ten year rule. - In the previous year 0 people starved to death. - In the previous year 5 people entered the kingdom. - The population is now 100. - We harvested 3000 bushels at 3 bushels per acre. - Rats destroyed 200 bushels, leaving 2800 bushels in storage. - The city owns 1000 acres of land. - Land is currently worth 19 bushels per acre. - -The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. - -Here's what your `playGame` method needs to do each year, for up to 10 years: - -> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: -> -> `int askHowManyAcresToBuy(int price, int bushels)` -> -> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. -> -> ` -> int askHowManyAcresToSell(int acresOwned)` -> -> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. -> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. -> -> ` -> int askHowMuchGrainToFeedPeople(int bushels)` -> -> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. -> -> ` -> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` -> -> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. -> -> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) -> -> Then the method needs to determine: -> -> 1. If there is a plague, and how many people die from it. -> 2. How many people starved. -> 3. How many people came to the city. -> 4. How good the harvest is. -> 5. If you have a problem with rats, and how much grain they eat. -> 6. How much land costs (for deciding what to do next). -> -> These can all be local variables of your `playGame` method. -> -> Use the following methods, **in this order,** to make the necessary calculations: -> -> `int plagueDeaths(int population)` -> -> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). -> -> ` -> int starvationDeaths(int population, int bushelsFedToPeople)` -> -> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). -> -> ` -> boolean uprising(int population, int howManyPeopleStarved)` -> -> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) -> -> ` -> int immigrants(int population, int acresOwned, int grainInStorage)` -> -> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. -> -> ` -> int harvest(int acres, int bushelsUsedAsSeed)` -> -> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. -> -> ` -> int grainEatenByRats(int bushels)` -> -> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). -> -> ` -> int newCostOfLand()` -> -> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) - -Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. - -When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. - -When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. - -Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. - -All the required arithmetic in this program should be **integer**. You do not need doubles. - -### Urgent! - -> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. - -### Things you need to know: - -#### Random numbers - -To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: - -> `static Random rand = new Random();` - -To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as - -> `myNewNumber = rand.nextInt(5); -> if (rand.nextInt(100) < 15) { ... }` - -To do something that happens `p` percent of the time, use - -> `if (rand.nextInt(100) < p) { _...do something..._ }` - -#### Getting input - -To get a number from the player, add this method to your program: - -```java - /** - * Prints the given message (which should ask the user for some integral - * quantity), and returns the number entered by the user. If the user's - * response isn't an integer, the question is repeated until the user - * does give a integer response. - * - * @param message The request to present to the user. - * @return The user's numeric response. - */ - int getNumber(String message) { - while (true) { - System.out.print(message); - try { - return scanner.nextInt(); - } - catch (InputMismatchException e) { - System.out.println("\"" + scanner.next() + "\" isn't a number!"); - } - } - } -``` - -Here is an example of how you can use this method: - -> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` - -### Structure of the solution - -* Project name: `Hammurabi` -* Package name: `hammurabi` -* Class names and method signatures: - * `class Hammurabi` - * `public static void main(String[] args)` - * Numerous other methods, as described above. - -The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. - -### Yo! Test it! - -You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! - -But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. - -### Credits - -Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html deleted file mode 100644 index 78bbf24..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html +++ /dev/null @@ -1,299 +0,0 @@ - - - - - - - CIT591 Hammurabi - - - - - -

CIT 591 Assignment 3: - Hammurabi
- Fall 2010, David Matuszek

- -

Purpose of this assignment

- -
    -
  • To get you started using Java.
  • -
- -

General idea of the assignment

- -

Hammurabi is a very old computer game. Your job is to bring it into the - 21st century by writing it in Java.

- -

Here are the standard instructions for the game:

- -
-

Congratulations, you are the newest ruler of - ancient Samaria, elected for a ten year term of office. Your duties are to - dispense food, direct farming, and buy and sell land as needed to support - your people. Watch out for rat infestiations and the plague! Grain is the - general currency, measured in bushels. The following will help you in your - decisions:

- -
    -
  • Each person needs at least 20 bushels of - grain per year to survive
  • - -
  • Each person can farm at most 10 acres of - land
  • - -
  • It takes 2 bushels of grain to farm an acre - of land
  • - -
  • The market price for land fluctuates - yearly
  • -
- -

Rule wisely and you will be showered with - appreciation at the end of your term. Rule poorly and you will be kicked - out of office!

-
- -

Details

- -

Define a single class named Hammurabi. Use the following skeleton (but leave out the // comments):

-
package hammurabi;               // package declaration
-
-import java.util.Random;         // imports go here
-import java.util.Scanner;
-
-/**
- * The Hammurabi game.
- * @author Your name goes here
- * @author Your partner's name goes here
- */
-public class Hammurabi {         // must save in a file named Hammurabi.java
-    Random rand = new Random();  // this is an instance variable
-    Scanner scanner = new Scanner(System.in);
-
-    public static void main(String[] args) { // required in every Java program
-        new Hammurabi().playGame();
-    }
-
-    void playGame() {
-        // declare local variables here: grain, population, etc.
-        // statements go after the declations
-    }
-
-    //other methods go here
-}
-

Playing the game

-

Here is what you start the game with: -

    -
  • 100 people
  • -
  • 2800 bushels of grain in storage
  • -
  • 1000 acres of land
  • -
  • Land value is 19 bushels/acre

    -
  • -
-

Each year, print out a summary similar to the following:

-
-O great Hammurabi!
-You are in year 1 of your ten year rule.
-In the previous year 0 people starved to death.
-In the previous year 5 people entered the kingdom.
-The population is now 100.
-We harvested 3000 bushels at 3 bushels per acre.
-Rats destroyed 200 bushels, leaving 2800 bushels in storage.
-The city owns 1000 acres of land.
-Land is currently worth 19 bushels per acre.
-
- -

The above summary represents the initial state, at the beginning of - the first year--that is, when you first take office, and before you do any of - the computations below). So, for example, the previous year (under a - different ruler) must have started with 95 people; none starved, and 5 - entered the kingdom, so as you enter office you rule 100 people.

- -

Here's what your playGame method needs to do each year, for up to 10 years:

- -
-

Ask the player the following questions. These questions should be asked in this order. Do not give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below:

-
-
int askHowManyAcresToBuy(int price, int bushels)
-
Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase.
-

- int askHowManyAcresToSell(int acresOwned)
-
Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have.
- Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn.
-

- int askHowMuchGrainToFeedPeople(int bushels)
-
Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You can feed them more than they need to survive.
-

- int askHowManyAcresToPlant(int acresOwned, int population, int bushels)
-
Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year.
-
-

For each - question, do "sanity checking"; that is, test whether the answer is - possible (you have enough grain, you have enough people to do the planting - etc.), and keep asking until you get a possible value. (For example, - O Great Hammurabi, surely you jest! We have only 3415 bushels left!)

- -

Then the method needs to determine:

- -
    -
  1. If there is a plague, and how many people die from it.
  2. -
  3. How many people starved.
  4. -
  5. How many people came to the city.
  6. -
  7. How good the harvest is.
  8. -
  9. If you have a problem with rats, and how much grain they eat.
  10. -
  11. How much land costs (for deciding what to do next).
  12. -
-

These can all be local variables of your playGame method.

-

Use the following methods, in this order, to make the necessary calculations:

-
-
int plagueDeaths(int population)
-
Each year, there is a 15% chance of a horrible plague. When this - happens, half your people die. Return the number of plague deaths (possibly zero).
-

- int starvationDeaths(int population, int bushelsFedToPeople)
-
Each person needs 20 bushels of grain to survive. If you feed them - more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero).
-

- boolean uprising(int population, int howManyPeopleStarved)
-
Return true if more than - 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.)
-

- int immigrants(int population, int acresOwned, int grainInStorage)
-
Nobody will come to the city if people are starving (so don't call this method). If everyone is - well fed, compute how many people come to the city as: (20 * number of acres you have + amount of grain you have in - storage) / (100 * population) + 1.
-

- int harvest(int acres, int bushelsUsedAsSeed)
-
Choose a random integer between 1 and 6, inclusive. Each acre that was planted - with seed will yield this many bushels of grain. (Example: if you planted - 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested.
-

- int grainEatenByRats(int bushels)
-
There is a 40% chance that you will have a rat infestation. When this - happens, rats will eat somewhere between 10% and 30% of your - grain. Return the amount of grain eaten by rats (possibly zero).
-

- int newCostOfLand()
-
The price of land is random, and ranges from 17 to 23 bushels per - acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell - land.)
-
-
-

Do these computations, in this order, for each of ten years. Each - computation should be done in a separate method, and none of these methods - should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it.

- -

When the computations are finished, call a method printSummary to print the - summary for the year. This method will take several parameters.

- - -

When the game ends , use a method finalSummary to print out a final summary, and to tell the - player how good a job he/she did. I'll leave the details up to you, but the - usual evaluation is based on how many people starved, and how many acres per - person you end up with.

-

Your playGame method will be quite long, but very straightforward; it does very little but call other methods.

-

All the required arithmetic in this program should be integer. You - do not need doubles.

- -

I suggest that you first get the simplest possible version of the program - running and tested out (that is, leave out things like rats, plagues, and - immigration), then add these things one at a time to a working - program, testing as you go.

- -

Things you need to know:

- -

Random numbers

- -

To get a random number generator, you first need to import - java.util.Random (or java.util.*). Then, you can - create a random number generator with a statement such as:

- -
-

static Random rand = new Random();

-
- -

To get a new random number in the range 0..n-1, where - n is an int, call rand.nextInt(n). - To get a new random number in the range min..max, use - the expression rand.nextInt(max - min + 1) + min. You - can use the rand method in statements such as

- -
-

myNewNumber = rand.nextInt(5);
- if (rand.nextInt(100) < 15) { ... }

-
- -

To do something that happens p percent of the time, use

- -
-

if (rand.nextInt(100) < p) { ...do something... - }

-
- -

Getting input

-

To get a number from the player, add this method to your program:

-
-/**
- * Prints the given message (which should ask the user for some integral
- * quantity), and returns the number entered by the user. If the user's
- * response isn't an integer, the question is repeated until the user
- * does give a integer response.
- * 
- * @param message The request to present to the user.
- * @return The user's numeric response.
- */
- int getNumber(String message) {
-    while (true) {
-        System.out.print(message);
-        try {
-            return scanner.nextInt();
-        }
-        catch (InputMismatchException e) {
-            System.out.println("\"" + scanner.next() + "\" isn't a number!");
-        }
-    }
-}
-
- -

Here is an example of how you can use this method:

- -
-

sell = getNumber("O great Hammurabi, how many acres shall you sell?");

-
- -

Structure of the assignment:

- -
    -
  • Project name: Hammurabi
  • - -
  • Package name: hammurabi
  • - -
  • Class names and method signatures: - -
      -
    • - class Hammurabi - -
        -
      • public static void main(String[] args)
      • - -
      • Numerous other methods, as described above.
      • -
      -
    • -
    -
  • - -
- -

The above are requirements. The methods that do calculations, not input/output, will be tested by my test methods, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument names are irrelevant). You may have additional methods if you wish.

- -

Due date:

- -

Thursday, October 21, before midnight. Turn in your zipped assignment via - Blackboard. Email submissions will incur the wrath of Hammurabi (and won't be graded).

- - - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md deleted file mode 100644 index 796d85c..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md +++ /dev/null @@ -1,6 +0,0 @@ -# Notes - -from the original Dave Matuszek course of 2010. - -https://www.cis.upenn.edu/~matuszek/cit591-2010/Assignments/06-hammurabi.html - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml deleted file mode 100644 index d789654..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - 4.0.0 - - io.zipcoder - MicroLabs-Loops - 1.0-SNAPSHOT - - - - - junit - junit - 4.13.2 - - - - - - 1.8 - 1.8 - - \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore deleted file mode 100644 index a1c2a23..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore +++ /dev/null @@ -1,23 +0,0 @@ -# Compiled class file -*.class - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE deleted file mode 100644 index 22474e4..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2022 Zip Code Wilmington Core - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md deleted file mode 100644 index e4672c9..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md +++ /dev/null @@ -1,228 +0,0 @@ -# hamurabi -an ancient (in more ways than one) computer game (text) - -## General idea of the lab - -*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. - -Here are the standard instructions for the game: - -> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** -> -> * **Each person needs at least 20 bushels of grain per year to survive** -> * **Each person can farm at most 10 acres of land** -> * **It takes 2 bushels of grain to farm an acre of land** -> * **The market price for land fluctuates yearly** -> -> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** - -### Maven - -There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. - -### Details - -Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): - -```java -package hammurabi; // package declaration -import java.util.Random; // imports go here -import java.util.Scanner; - -public class Hammurabi { // must save in a file named Hammurabi.java - Random rand = new Random(); // this is an instance variable - Scanner scanner = new Scanner(System.in); - - public static void main(String\[\] args) { // required in every Java program - new Hammurabi().playGame(); - } - - void playGame() { - // declare local variables here: grain, population, etc. - // statements go after the declations - } - - //other methods go here -} -``` - -### Playing the game - -Here is what you start the game with: - -* 100 people -* 2800 bushels of grain in storage -* 1000 acres of land -* Land value is 19 bushels/acre - - -Each year, print out a summary similar to the following: - - O great Hammurabi! - You are in year 1 of your ten year rule. - In the previous year 0 people starved to death. - In the previous year 5 people entered the kingdom. - The population is now 100. - We harvested 3000 bushels at 3 bushels per acre. - Rats destroyed 200 bushels, leaving 2800 bushels in storage. - The city owns 1000 acres of land. - Land is currently worth 19 bushels per acre. - -The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. - -Here's what your `playGame` method needs to do each year, for up to 10 years: - -> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: -> -> `int askHowManyAcresToBuy(int price, int bushels)` -> -> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. -> -> ` -> int askHowManyAcresToSell(int acresOwned)` -> -> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. -> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. -> -> ` -> int askHowMuchGrainToFeedPeople(int bushels)` -> -> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. -> -> ` -> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` -> -> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. -> -> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) -> -> Then the method needs to determine: -> -> 1. If there is a plague, and how many people die from it. -> 2. How many people starved. -> 3. How many people came to the city. -> 4. How good the harvest is. -> 5. If you have a problem with rats, and how much grain they eat. -> 6. How much land costs (for deciding what to do next). -> -> These can all be local variables of your `playGame` method. -> -> Use the following methods, **in this order,** to make the necessary calculations: -> -> `int plagueDeaths(int population)` -> -> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). -> -> ` -> int starvationDeaths(int population, int bushelsFedToPeople)` -> -> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). -> -> ` -> boolean uprising(int population, int howManyPeopleStarved)` -> -> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) -> -> ` -> int immigrants(int population, int acresOwned, int grainInStorage)` -> -> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. -> -> ` -> int harvest(int acres, int bushelsUsedAsSeed)` -> -> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. -> -> ` -> int grainEatenByRats(int bushels)` -> -> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). -> -> ` -> int newCostOfLand()` -> -> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) - -Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. - -When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. - -When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. - -Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. - -All the required arithmetic in this program should be **integer**. You do not need doubles. - -### Urgent! - -> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. - -### Things you need to know: - -#### Random numbers - -To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: - -> `static Random rand = new Random();` - -To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as - -> `myNewNumber = rand.nextInt(5); -> if (rand.nextInt(100) < 15) { ... }` - -To do something that happens `p` percent of the time, use - -> `if (rand.nextInt(100) < p) { _...do something..._ }` - -#### Getting input - -To get a number from the player, add this method to your program: - -```java - /** - * Prints the given message (which should ask the user for some integral - * quantity), and returns the number entered by the user. If the user's - * response isn't an integer, the question is repeated until the user - * does give a integer response. - * - * @param message The request to present to the user. - * @return The user's numeric response. - */ - int getNumber(String message) { - while (true) { - System.out.print(message); - try { - return scanner.nextInt(); - } - catch (InputMismatchException e) { - System.out.println("\"" + scanner.next() + "\" isn't a number!"); - } - } - } -``` - -Here is an example of how you can use this method: - -> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` - -### Structure of the solution - -* Project name: `Hammurabi` -* Package name: `hammurabi` -* Class names and method signatures: - * `class Hammurabi` - * `public static void main(String[] args)` - * Numerous other methods, as described above. - -The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. - -### Yo! Test it! - -You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! - -But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. - -### Credits - -Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html deleted file mode 100644 index 78bbf24..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html +++ /dev/null @@ -1,299 +0,0 @@ - - - - - - - CIT591 Hammurabi - - - - - -

CIT 591 Assignment 3: - Hammurabi
- Fall 2010, David Matuszek

- -

Purpose of this assignment

- -
    -
  • To get you started using Java.
  • -
- -

General idea of the assignment

- -

Hammurabi is a very old computer game. Your job is to bring it into the - 21st century by writing it in Java.

- -

Here are the standard instructions for the game:

- -
-

Congratulations, you are the newest ruler of - ancient Samaria, elected for a ten year term of office. Your duties are to - dispense food, direct farming, and buy and sell land as needed to support - your people. Watch out for rat infestiations and the plague! Grain is the - general currency, measured in bushels. The following will help you in your - decisions:

- -
    -
  • Each person needs at least 20 bushels of - grain per year to survive
  • - -
  • Each person can farm at most 10 acres of - land
  • - -
  • It takes 2 bushels of grain to farm an acre - of land
  • - -
  • The market price for land fluctuates - yearly
  • -
- -

Rule wisely and you will be showered with - appreciation at the end of your term. Rule poorly and you will be kicked - out of office!

-
- -

Details

- -

Define a single class named Hammurabi. Use the following skeleton (but leave out the // comments):

-
package hammurabi;               // package declaration
-
-import java.util.Random;         // imports go here
-import java.util.Scanner;
-
-/**
- * The Hammurabi game.
- * @author Your name goes here
- * @author Your partner's name goes here
- */
-public class Hammurabi {         // must save in a file named Hammurabi.java
-    Random rand = new Random();  // this is an instance variable
-    Scanner scanner = new Scanner(System.in);
-
-    public static void main(String[] args) { // required in every Java program
-        new Hammurabi().playGame();
-    }
-
-    void playGame() {
-        // declare local variables here: grain, population, etc.
-        // statements go after the declations
-    }
-
-    //other methods go here
-}
-

Playing the game

-

Here is what you start the game with: -

    -
  • 100 people
  • -
  • 2800 bushels of grain in storage
  • -
  • 1000 acres of land
  • -
  • Land value is 19 bushels/acre

    -
  • -
-

Each year, print out a summary similar to the following:

-
-O great Hammurabi!
-You are in year 1 of your ten year rule.
-In the previous year 0 people starved to death.
-In the previous year 5 people entered the kingdom.
-The population is now 100.
-We harvested 3000 bushels at 3 bushels per acre.
-Rats destroyed 200 bushels, leaving 2800 bushels in storage.
-The city owns 1000 acres of land.
-Land is currently worth 19 bushels per acre.
-
- -

The above summary represents the initial state, at the beginning of - the first year--that is, when you first take office, and before you do any of - the computations below). So, for example, the previous year (under a - different ruler) must have started with 95 people; none starved, and 5 - entered the kingdom, so as you enter office you rule 100 people.

- -

Here's what your playGame method needs to do each year, for up to 10 years:

- -
-

Ask the player the following questions. These questions should be asked in this order. Do not give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below:

-
-
int askHowManyAcresToBuy(int price, int bushels)
-
Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase.
-

- int askHowManyAcresToSell(int acresOwned)
-
Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have.
- Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn.
-

- int askHowMuchGrainToFeedPeople(int bushels)
-
Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You can feed them more than they need to survive.
-

- int askHowManyAcresToPlant(int acresOwned, int population, int bushels)
-
Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year.
-
-

For each - question, do "sanity checking"; that is, test whether the answer is - possible (you have enough grain, you have enough people to do the planting - etc.), and keep asking until you get a possible value. (For example, - O Great Hammurabi, surely you jest! We have only 3415 bushels left!)

- -

Then the method needs to determine:

- -
    -
  1. If there is a plague, and how many people die from it.
  2. -
  3. How many people starved.
  4. -
  5. How many people came to the city.
  6. -
  7. How good the harvest is.
  8. -
  9. If you have a problem with rats, and how much grain they eat.
  10. -
  11. How much land costs (for deciding what to do next).
  12. -
-

These can all be local variables of your playGame method.

-

Use the following methods, in this order, to make the necessary calculations:

-
-
int plagueDeaths(int population)
-
Each year, there is a 15% chance of a horrible plague. When this - happens, half your people die. Return the number of plague deaths (possibly zero).
-

- int starvationDeaths(int population, int bushelsFedToPeople)
-
Each person needs 20 bushels of grain to survive. If you feed them - more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero).
-

- boolean uprising(int population, int howManyPeopleStarved)
-
Return true if more than - 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.)
-

- int immigrants(int population, int acresOwned, int grainInStorage)
-
Nobody will come to the city if people are starving (so don't call this method). If everyone is - well fed, compute how many people come to the city as: (20 * number of acres you have + amount of grain you have in - storage) / (100 * population) + 1.
-

- int harvest(int acres, int bushelsUsedAsSeed)
-
Choose a random integer between 1 and 6, inclusive. Each acre that was planted - with seed will yield this many bushels of grain. (Example: if you planted - 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested.
-

- int grainEatenByRats(int bushels)
-
There is a 40% chance that you will have a rat infestation. When this - happens, rats will eat somewhere between 10% and 30% of your - grain. Return the amount of grain eaten by rats (possibly zero).
-

- int newCostOfLand()
-
The price of land is random, and ranges from 17 to 23 bushels per - acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell - land.)
-
-
-

Do these computations, in this order, for each of ten years. Each - computation should be done in a separate method, and none of these methods - should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it.

- -

When the computations are finished, call a method printSummary to print the - summary for the year. This method will take several parameters.

- - -

When the game ends , use a method finalSummary to print out a final summary, and to tell the - player how good a job he/she did. I'll leave the details up to you, but the - usual evaluation is based on how many people starved, and how many acres per - person you end up with.

-

Your playGame method will be quite long, but very straightforward; it does very little but call other methods.

-

All the required arithmetic in this program should be integer. You - do not need doubles.

- -

I suggest that you first get the simplest possible version of the program - running and tested out (that is, leave out things like rats, plagues, and - immigration), then add these things one at a time to a working - program, testing as you go.

- -

Things you need to know:

- -

Random numbers

- -

To get a random number generator, you first need to import - java.util.Random (or java.util.*). Then, you can - create a random number generator with a statement such as:

- -
-

static Random rand = new Random();

-
- -

To get a new random number in the range 0..n-1, where - n is an int, call rand.nextInt(n). - To get a new random number in the range min..max, use - the expression rand.nextInt(max - min + 1) + min. You - can use the rand method in statements such as

- -
-

myNewNumber = rand.nextInt(5);
- if (rand.nextInt(100) < 15) { ... }

-
- -

To do something that happens p percent of the time, use

- -
-

if (rand.nextInt(100) < p) { ...do something... - }

-
- -

Getting input

-

To get a number from the player, add this method to your program:

-
-/**
- * Prints the given message (which should ask the user for some integral
- * quantity), and returns the number entered by the user. If the user's
- * response isn't an integer, the question is repeated until the user
- * does give a integer response.
- * 
- * @param message The request to present to the user.
- * @return The user's numeric response.
- */
- int getNumber(String message) {
-    while (true) {
-        System.out.print(message);
-        try {
-            return scanner.nextInt();
-        }
-        catch (InputMismatchException e) {
-            System.out.println("\"" + scanner.next() + "\" isn't a number!");
-        }
-    }
-}
-
- -

Here is an example of how you can use this method:

- -
-

sell = getNumber("O great Hammurabi, how many acres shall you sell?");

-
- -

Structure of the assignment:

- -
    -
  • Project name: Hammurabi
  • - -
  • Package name: hammurabi
  • - -
  • Class names and method signatures: - -
      -
    • - class Hammurabi - -
        -
      • public static void main(String[] args)
      • - -
      • Numerous other methods, as described above.
      • -
      -
    • -
    -
  • - -
- -

The above are requirements. The methods that do calculations, not input/output, will be tested by my test methods, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument names are irrelevant). You may have additional methods if you wish.

- -

Due date:

- -

Thursday, October 21, before midnight. Turn in your zipped assignment via - Blackboard. Email submissions will incur the wrath of Hammurabi (and won't be graded).

- - - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md deleted file mode 100644 index 796d85c..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md +++ /dev/null @@ -1,6 +0,0 @@ -# Notes - -from the original Dave Matuszek course of 2010. - -https://www.cis.upenn.edu/~matuszek/cit591-2010/Assignments/06-hammurabi.html - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml deleted file mode 100644 index d789654..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - 4.0.0 - - io.zipcoder - MicroLabs-Loops - 1.0-SNAPSHOT - - - - - junit - junit - 4.13.2 - - - - - - 1.8 - 1.8 - - \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore deleted file mode 100644 index a1c2a23..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore +++ /dev/null @@ -1,23 +0,0 @@ -# Compiled class file -*.class - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE deleted file mode 100644 index 22474e4..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2022 Zip Code Wilmington Core - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md deleted file mode 100644 index e4672c9..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md +++ /dev/null @@ -1,228 +0,0 @@ -# hamurabi -an ancient (in more ways than one) computer game (text) - -## General idea of the lab - -*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. - -Here are the standard instructions for the game: - -> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** -> -> * **Each person needs at least 20 bushels of grain per year to survive** -> * **Each person can farm at most 10 acres of land** -> * **It takes 2 bushels of grain to farm an acre of land** -> * **The market price for land fluctuates yearly** -> -> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** - -### Maven - -There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. - -### Details - -Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): - -```java -package hammurabi; // package declaration -import java.util.Random; // imports go here -import java.util.Scanner; - -public class Hammurabi { // must save in a file named Hammurabi.java - Random rand = new Random(); // this is an instance variable - Scanner scanner = new Scanner(System.in); - - public static void main(String\[\] args) { // required in every Java program - new Hammurabi().playGame(); - } - - void playGame() { - // declare local variables here: grain, population, etc. - // statements go after the declations - } - - //other methods go here -} -``` - -### Playing the game - -Here is what you start the game with: - -* 100 people -* 2800 bushels of grain in storage -* 1000 acres of land -* Land value is 19 bushels/acre - - -Each year, print out a summary similar to the following: - - O great Hammurabi! - You are in year 1 of your ten year rule. - In the previous year 0 people starved to death. - In the previous year 5 people entered the kingdom. - The population is now 100. - We harvested 3000 bushels at 3 bushels per acre. - Rats destroyed 200 bushels, leaving 2800 bushels in storage. - The city owns 1000 acres of land. - Land is currently worth 19 bushels per acre. - -The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. - -Here's what your `playGame` method needs to do each year, for up to 10 years: - -> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: -> -> `int askHowManyAcresToBuy(int price, int bushels)` -> -> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. -> -> ` -> int askHowManyAcresToSell(int acresOwned)` -> -> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. -> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. -> -> ` -> int askHowMuchGrainToFeedPeople(int bushels)` -> -> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. -> -> ` -> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` -> -> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. -> -> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) -> -> Then the method needs to determine: -> -> 1. If there is a plague, and how many people die from it. -> 2. How many people starved. -> 3. How many people came to the city. -> 4. How good the harvest is. -> 5. If you have a problem with rats, and how much grain they eat. -> 6. How much land costs (for deciding what to do next). -> -> These can all be local variables of your `playGame` method. -> -> Use the following methods, **in this order,** to make the necessary calculations: -> -> `int plagueDeaths(int population)` -> -> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). -> -> ` -> int starvationDeaths(int population, int bushelsFedToPeople)` -> -> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). -> -> ` -> boolean uprising(int population, int howManyPeopleStarved)` -> -> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) -> -> ` -> int immigrants(int population, int acresOwned, int grainInStorage)` -> -> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. -> -> ` -> int harvest(int acres, int bushelsUsedAsSeed)` -> -> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. -> -> ` -> int grainEatenByRats(int bushels)` -> -> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). -> -> ` -> int newCostOfLand()` -> -> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) - -Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. - -When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. - -When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. - -Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. - -All the required arithmetic in this program should be **integer**. You do not need doubles. - -### Urgent! - -> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. - -### Things you need to know: - -#### Random numbers - -To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: - -> `static Random rand = new Random();` - -To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as - -> `myNewNumber = rand.nextInt(5); -> if (rand.nextInt(100) < 15) { ... }` - -To do something that happens `p` percent of the time, use - -> `if (rand.nextInt(100) < p) { _...do something..._ }` - -#### Getting input - -To get a number from the player, add this method to your program: - -```java - /** - * Prints the given message (which should ask the user for some integral - * quantity), and returns the number entered by the user. If the user's - * response isn't an integer, the question is repeated until the user - * does give a integer response. - * - * @param message The request to present to the user. - * @return The user's numeric response. - */ - int getNumber(String message) { - while (true) { - System.out.print(message); - try { - return scanner.nextInt(); - } - catch (InputMismatchException e) { - System.out.println("\"" + scanner.next() + "\" isn't a number!"); - } - } - } -``` - -Here is an example of how you can use this method: - -> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` - -### Structure of the solution - -* Project name: `Hammurabi` -* Package name: `hammurabi` -* Class names and method signatures: - * `class Hammurabi` - * `public static void main(String[] args)` - * Numerous other methods, as described above. - -The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. - -### Yo! Test it! - -You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! - -But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. - -### Credits - -Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html deleted file mode 100644 index 78bbf24..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html +++ /dev/null @@ -1,299 +0,0 @@ - - - - - - - CIT591 Hammurabi - - - - - -

CIT 591 Assignment 3: - Hammurabi
- Fall 2010, David Matuszek

- -

Purpose of this assignment

- -
    -
  • To get you started using Java.
  • -
- -

General idea of the assignment

- -

Hammurabi is a very old computer game. Your job is to bring it into the - 21st century by writing it in Java.

- -

Here are the standard instructions for the game:

- -
-

Congratulations, you are the newest ruler of - ancient Samaria, elected for a ten year term of office. Your duties are to - dispense food, direct farming, and buy and sell land as needed to support - your people. Watch out for rat infestiations and the plague! Grain is the - general currency, measured in bushels. The following will help you in your - decisions:

- -
    -
  • Each person needs at least 20 bushels of - grain per year to survive
  • - -
  • Each person can farm at most 10 acres of - land
  • - -
  • It takes 2 bushels of grain to farm an acre - of land
  • - -
  • The market price for land fluctuates - yearly
  • -
- -

Rule wisely and you will be showered with - appreciation at the end of your term. Rule poorly and you will be kicked - out of office!

-
- -

Details

- -

Define a single class named Hammurabi. Use the following skeleton (but leave out the // comments):

-
package hammurabi;               // package declaration
-
-import java.util.Random;         // imports go here
-import java.util.Scanner;
-
-/**
- * The Hammurabi game.
- * @author Your name goes here
- * @author Your partner's name goes here
- */
-public class Hammurabi {         // must save in a file named Hammurabi.java
-    Random rand = new Random();  // this is an instance variable
-    Scanner scanner = new Scanner(System.in);
-
-    public static void main(String[] args) { // required in every Java program
-        new Hammurabi().playGame();
-    }
-
-    void playGame() {
-        // declare local variables here: grain, population, etc.
-        // statements go after the declations
-    }
-
-    //other methods go here
-}
-

Playing the game

-

Here is what you start the game with: -

    -
  • 100 people
  • -
  • 2800 bushels of grain in storage
  • -
  • 1000 acres of land
  • -
  • Land value is 19 bushels/acre

    -
  • -
-

Each year, print out a summary similar to the following:

-
-O great Hammurabi!
-You are in year 1 of your ten year rule.
-In the previous year 0 people starved to death.
-In the previous year 5 people entered the kingdom.
-The population is now 100.
-We harvested 3000 bushels at 3 bushels per acre.
-Rats destroyed 200 bushels, leaving 2800 bushels in storage.
-The city owns 1000 acres of land.
-Land is currently worth 19 bushels per acre.
-
- -

The above summary represents the initial state, at the beginning of - the first year--that is, when you first take office, and before you do any of - the computations below). So, for example, the previous year (under a - different ruler) must have started with 95 people; none starved, and 5 - entered the kingdom, so as you enter office you rule 100 people.

- -

Here's what your playGame method needs to do each year, for up to 10 years:

- -
-

Ask the player the following questions. These questions should be asked in this order. Do not give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below:

-
-
int askHowManyAcresToBuy(int price, int bushels)
-
Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase.
-

- int askHowManyAcresToSell(int acresOwned)
-
Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have.
- Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn.
-

- int askHowMuchGrainToFeedPeople(int bushels)
-
Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You can feed them more than they need to survive.
-

- int askHowManyAcresToPlant(int acresOwned, int population, int bushels)
-
Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year.
-
-

For each - question, do "sanity checking"; that is, test whether the answer is - possible (you have enough grain, you have enough people to do the planting - etc.), and keep asking until you get a possible value. (For example, - O Great Hammurabi, surely you jest! We have only 3415 bushels left!)

- -

Then the method needs to determine:

- -
    -
  1. If there is a plague, and how many people die from it.
  2. -
  3. How many people starved.
  4. -
  5. How many people came to the city.
  6. -
  7. How good the harvest is.
  8. -
  9. If you have a problem with rats, and how much grain they eat.
  10. -
  11. How much land costs (for deciding what to do next).
  12. -
-

These can all be local variables of your playGame method.

-

Use the following methods, in this order, to make the necessary calculations:

-
-
int plagueDeaths(int population)
-
Each year, there is a 15% chance of a horrible plague. When this - happens, half your people die. Return the number of plague deaths (possibly zero).
-

- int starvationDeaths(int population, int bushelsFedToPeople)
-
Each person needs 20 bushels of grain to survive. If you feed them - more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero).
-

- boolean uprising(int population, int howManyPeopleStarved)
-
Return true if more than - 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.)
-

- int immigrants(int population, int acresOwned, int grainInStorage)
-
Nobody will come to the city if people are starving (so don't call this method). If everyone is - well fed, compute how many people come to the city as: (20 * number of acres you have + amount of grain you have in - storage) / (100 * population) + 1.
-

- int harvest(int acres, int bushelsUsedAsSeed)
-
Choose a random integer between 1 and 6, inclusive. Each acre that was planted - with seed will yield this many bushels of grain. (Example: if you planted - 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested.
-

- int grainEatenByRats(int bushels)
-
There is a 40% chance that you will have a rat infestation. When this - happens, rats will eat somewhere between 10% and 30% of your - grain. Return the amount of grain eaten by rats (possibly zero).
-

- int newCostOfLand()
-
The price of land is random, and ranges from 17 to 23 bushels per - acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell - land.)
-
-
-

Do these computations, in this order, for each of ten years. Each - computation should be done in a separate method, and none of these methods - should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it.

- -

When the computations are finished, call a method printSummary to print the - summary for the year. This method will take several parameters.

- - -

When the game ends , use a method finalSummary to print out a final summary, and to tell the - player how good a job he/she did. I'll leave the details up to you, but the - usual evaluation is based on how many people starved, and how many acres per - person you end up with.

-

Your playGame method will be quite long, but very straightforward; it does very little but call other methods.

-

All the required arithmetic in this program should be integer. You - do not need doubles.

- -

I suggest that you first get the simplest possible version of the program - running and tested out (that is, leave out things like rats, plagues, and - immigration), then add these things one at a time to a working - program, testing as you go.

- -

Things you need to know:

- -

Random numbers

- -

To get a random number generator, you first need to import - java.util.Random (or java.util.*). Then, you can - create a random number generator with a statement such as:

- -
-

static Random rand = new Random();

-
- -

To get a new random number in the range 0..n-1, where - n is an int, call rand.nextInt(n). - To get a new random number in the range min..max, use - the expression rand.nextInt(max - min + 1) + min. You - can use the rand method in statements such as

- -
-

myNewNumber = rand.nextInt(5);
- if (rand.nextInt(100) < 15) { ... }

-
- -

To do something that happens p percent of the time, use

- -
-

if (rand.nextInt(100) < p) { ...do something... - }

-
- -

Getting input

-

To get a number from the player, add this method to your program:

-
-/**
- * Prints the given message (which should ask the user for some integral
- * quantity), and returns the number entered by the user. If the user's
- * response isn't an integer, the question is repeated until the user
- * does give a integer response.
- * 
- * @param message The request to present to the user.
- * @return The user's numeric response.
- */
- int getNumber(String message) {
-    while (true) {
-        System.out.print(message);
-        try {
-            return scanner.nextInt();
-        }
-        catch (InputMismatchException e) {
-            System.out.println("\"" + scanner.next() + "\" isn't a number!");
-        }
-    }
-}
-
- -

Here is an example of how you can use this method:

- -
-

sell = getNumber("O great Hammurabi, how many acres shall you sell?");

-
- -

Structure of the assignment:

- -
    -
  • Project name: Hammurabi
  • - -
  • Package name: hammurabi
  • - -
  • Class names and method signatures: - -
      -
    • - class Hammurabi - -
        -
      • public static void main(String[] args)
      • - -
      • Numerous other methods, as described above.
      • -
      -
    • -
    -
  • - -
- -

The above are requirements. The methods that do calculations, not input/output, will be tested by my test methods, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument names are irrelevant). You may have additional methods if you wish.

- -

Due date:

- -

Thursday, October 21, before midnight. Turn in your zipped assignment via - Blackboard. Email submissions will incur the wrath of Hammurabi (and won't be graded).

- - - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md deleted file mode 100644 index 796d85c..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md +++ /dev/null @@ -1,6 +0,0 @@ -# Notes - -from the original Dave Matuszek course of 2010. - -https://www.cis.upenn.edu/~matuszek/cit591-2010/Assignments/06-hammurabi.html - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml deleted file mode 100644 index d789654..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - 4.0.0 - - io.zipcoder - MicroLabs-Loops - 1.0-SNAPSHOT - - - - - junit - junit - 4.13.2 - - - - - - 1.8 - 1.8 - - \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore deleted file mode 100644 index a1c2a23..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore +++ /dev/null @@ -1,23 +0,0 @@ -# Compiled class file -*.class - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE deleted file mode 100644 index 22474e4..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2022 Zip Code Wilmington Core - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md deleted file mode 100644 index e4672c9..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md +++ /dev/null @@ -1,228 +0,0 @@ -# hamurabi -an ancient (in more ways than one) computer game (text) - -## General idea of the lab - -*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. - -Here are the standard instructions for the game: - -> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** -> -> * **Each person needs at least 20 bushels of grain per year to survive** -> * **Each person can farm at most 10 acres of land** -> * **It takes 2 bushels of grain to farm an acre of land** -> * **The market price for land fluctuates yearly** -> -> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** - -### Maven - -There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. - -### Details - -Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): - -```java -package hammurabi; // package declaration -import java.util.Random; // imports go here -import java.util.Scanner; - -public class Hammurabi { // must save in a file named Hammurabi.java - Random rand = new Random(); // this is an instance variable - Scanner scanner = new Scanner(System.in); - - public static void main(String\[\] args) { // required in every Java program - new Hammurabi().playGame(); - } - - void playGame() { - // declare local variables here: grain, population, etc. - // statements go after the declations - } - - //other methods go here -} -``` - -### Playing the game - -Here is what you start the game with: - -* 100 people -* 2800 bushels of grain in storage -* 1000 acres of land -* Land value is 19 bushels/acre - - -Each year, print out a summary similar to the following: - - O great Hammurabi! - You are in year 1 of your ten year rule. - In the previous year 0 people starved to death. - In the previous year 5 people entered the kingdom. - The population is now 100. - We harvested 3000 bushels at 3 bushels per acre. - Rats destroyed 200 bushels, leaving 2800 bushels in storage. - The city owns 1000 acres of land. - Land is currently worth 19 bushels per acre. - -The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. - -Here's what your `playGame` method needs to do each year, for up to 10 years: - -> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: -> -> `int askHowManyAcresToBuy(int price, int bushels)` -> -> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. -> -> ` -> int askHowManyAcresToSell(int acresOwned)` -> -> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. -> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. -> -> ` -> int askHowMuchGrainToFeedPeople(int bushels)` -> -> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. -> -> ` -> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` -> -> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. -> -> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) -> -> Then the method needs to determine: -> -> 1. If there is a plague, and how many people die from it. -> 2. How many people starved. -> 3. How many people came to the city. -> 4. How good the harvest is. -> 5. If you have a problem with rats, and how much grain they eat. -> 6. How much land costs (for deciding what to do next). -> -> These can all be local variables of your `playGame` method. -> -> Use the following methods, **in this order,** to make the necessary calculations: -> -> `int plagueDeaths(int population)` -> -> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). -> -> ` -> int starvationDeaths(int population, int bushelsFedToPeople)` -> -> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). -> -> ` -> boolean uprising(int population, int howManyPeopleStarved)` -> -> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) -> -> ` -> int immigrants(int population, int acresOwned, int grainInStorage)` -> -> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. -> -> ` -> int harvest(int acres, int bushelsUsedAsSeed)` -> -> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. -> -> ` -> int grainEatenByRats(int bushels)` -> -> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). -> -> ` -> int newCostOfLand()` -> -> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) - -Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. - -When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. - -When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. - -Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. - -All the required arithmetic in this program should be **integer**. You do not need doubles. - -### Urgent! - -> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. - -### Things you need to know: - -#### Random numbers - -To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: - -> `static Random rand = new Random();` - -To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as - -> `myNewNumber = rand.nextInt(5); -> if (rand.nextInt(100) < 15) { ... }` - -To do something that happens `p` percent of the time, use - -> `if (rand.nextInt(100) < p) { _...do something..._ }` - -#### Getting input - -To get a number from the player, add this method to your program: - -```java - /** - * Prints the given message (which should ask the user for some integral - * quantity), and returns the number entered by the user. If the user's - * response isn't an integer, the question is repeated until the user - * does give a integer response. - * - * @param message The request to present to the user. - * @return The user's numeric response. - */ - int getNumber(String message) { - while (true) { - System.out.print(message); - try { - return scanner.nextInt(); - } - catch (InputMismatchException e) { - System.out.println("\"" + scanner.next() + "\" isn't a number!"); - } - } - } -``` - -Here is an example of how you can use this method: - -> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` - -### Structure of the solution - -* Project name: `Hammurabi` -* Package name: `hammurabi` -* Class names and method signatures: - * `class Hammurabi` - * `public static void main(String[] args)` - * Numerous other methods, as described above. - -The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. - -### Yo! Test it! - -You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! - -But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. - -### Credits - -Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html deleted file mode 100644 index 78bbf24..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html +++ /dev/null @@ -1,299 +0,0 @@ - - - - - - - CIT591 Hammurabi - - - - - -

CIT 591 Assignment 3: - Hammurabi
- Fall 2010, David Matuszek

- -

Purpose of this assignment

- -
    -
  • To get you started using Java.
  • -
- -

General idea of the assignment

- -

Hammurabi is a very old computer game. Your job is to bring it into the - 21st century by writing it in Java.

- -

Here are the standard instructions for the game:

- -
-

Congratulations, you are the newest ruler of - ancient Samaria, elected for a ten year term of office. Your duties are to - dispense food, direct farming, and buy and sell land as needed to support - your people. Watch out for rat infestiations and the plague! Grain is the - general currency, measured in bushels. The following will help you in your - decisions:

- -
    -
  • Each person needs at least 20 bushels of - grain per year to survive
  • - -
  • Each person can farm at most 10 acres of - land
  • - -
  • It takes 2 bushels of grain to farm an acre - of land
  • - -
  • The market price for land fluctuates - yearly
  • -
- -

Rule wisely and you will be showered with - appreciation at the end of your term. Rule poorly and you will be kicked - out of office!

-
- -

Details

- -

Define a single class named Hammurabi. Use the following skeleton (but leave out the // comments):

-
package hammurabi;               // package declaration
-
-import java.util.Random;         // imports go here
-import java.util.Scanner;
-
-/**
- * The Hammurabi game.
- * @author Your name goes here
- * @author Your partner's name goes here
- */
-public class Hammurabi {         // must save in a file named Hammurabi.java
-    Random rand = new Random();  // this is an instance variable
-    Scanner scanner = new Scanner(System.in);
-
-    public static void main(String[] args) { // required in every Java program
-        new Hammurabi().playGame();
-    }
-
-    void playGame() {
-        // declare local variables here: grain, population, etc.
-        // statements go after the declations
-    }
-
-    //other methods go here
-}
-

Playing the game

-

Here is what you start the game with: -

    -
  • 100 people
  • -
  • 2800 bushels of grain in storage
  • -
  • 1000 acres of land
  • -
  • Land value is 19 bushels/acre

    -
  • -
-

Each year, print out a summary similar to the following:

-
-O great Hammurabi!
-You are in year 1 of your ten year rule.
-In the previous year 0 people starved to death.
-In the previous year 5 people entered the kingdom.
-The population is now 100.
-We harvested 3000 bushels at 3 bushels per acre.
-Rats destroyed 200 bushels, leaving 2800 bushels in storage.
-The city owns 1000 acres of land.
-Land is currently worth 19 bushels per acre.
-
- -

The above summary represents the initial state, at the beginning of - the first year--that is, when you first take office, and before you do any of - the computations below). So, for example, the previous year (under a - different ruler) must have started with 95 people; none starved, and 5 - entered the kingdom, so as you enter office you rule 100 people.

- -

Here's what your playGame method needs to do each year, for up to 10 years:

- -
-

Ask the player the following questions. These questions should be asked in this order. Do not give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below:

-
-
int askHowManyAcresToBuy(int price, int bushels)
-
Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase.
-

- int askHowManyAcresToSell(int acresOwned)
-
Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have.
- Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn.
-

- int askHowMuchGrainToFeedPeople(int bushels)
-
Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You can feed them more than they need to survive.
-

- int askHowManyAcresToPlant(int acresOwned, int population, int bushels)
-
Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year.
-
-

For each - question, do "sanity checking"; that is, test whether the answer is - possible (you have enough grain, you have enough people to do the planting - etc.), and keep asking until you get a possible value. (For example, - O Great Hammurabi, surely you jest! We have only 3415 bushels left!)

- -

Then the method needs to determine:

- -
    -
  1. If there is a plague, and how many people die from it.
  2. -
  3. How many people starved.
  4. -
  5. How many people came to the city.
  6. -
  7. How good the harvest is.
  8. -
  9. If you have a problem with rats, and how much grain they eat.
  10. -
  11. How much land costs (for deciding what to do next).
  12. -
-

These can all be local variables of your playGame method.

-

Use the following methods, in this order, to make the necessary calculations:

-
-
int plagueDeaths(int population)
-
Each year, there is a 15% chance of a horrible plague. When this - happens, half your people die. Return the number of plague deaths (possibly zero).
-

- int starvationDeaths(int population, int bushelsFedToPeople)
-
Each person needs 20 bushels of grain to survive. If you feed them - more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero).
-

- boolean uprising(int population, int howManyPeopleStarved)
-
Return true if more than - 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.)
-

- int immigrants(int population, int acresOwned, int grainInStorage)
-
Nobody will come to the city if people are starving (so don't call this method). If everyone is - well fed, compute how many people come to the city as: (20 * number of acres you have + amount of grain you have in - storage) / (100 * population) + 1.
-

- int harvest(int acres, int bushelsUsedAsSeed)
-
Choose a random integer between 1 and 6, inclusive. Each acre that was planted - with seed will yield this many bushels of grain. (Example: if you planted - 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested.
-

- int grainEatenByRats(int bushels)
-
There is a 40% chance that you will have a rat infestation. When this - happens, rats will eat somewhere between 10% and 30% of your - grain. Return the amount of grain eaten by rats (possibly zero).
-

- int newCostOfLand()
-
The price of land is random, and ranges from 17 to 23 bushels per - acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell - land.)
-
-
-

Do these computations, in this order, for each of ten years. Each - computation should be done in a separate method, and none of these methods - should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it.

- -

When the computations are finished, call a method printSummary to print the - summary for the year. This method will take several parameters.

- - -

When the game ends , use a method finalSummary to print out a final summary, and to tell the - player how good a job he/she did. I'll leave the details up to you, but the - usual evaluation is based on how many people starved, and how many acres per - person you end up with.

-

Your playGame method will be quite long, but very straightforward; it does very little but call other methods.

-

All the required arithmetic in this program should be integer. You - do not need doubles.

- -

I suggest that you first get the simplest possible version of the program - running and tested out (that is, leave out things like rats, plagues, and - immigration), then add these things one at a time to a working - program, testing as you go.

- -

Things you need to know:

- -

Random numbers

- -

To get a random number generator, you first need to import - java.util.Random (or java.util.*). Then, you can - create a random number generator with a statement such as:

- -
-

static Random rand = new Random();

-
- -

To get a new random number in the range 0..n-1, where - n is an int, call rand.nextInt(n). - To get a new random number in the range min..max, use - the expression rand.nextInt(max - min + 1) + min. You - can use the rand method in statements such as

- -
-

myNewNumber = rand.nextInt(5);
- if (rand.nextInt(100) < 15) { ... }

-
- -

To do something that happens p percent of the time, use

- -
-

if (rand.nextInt(100) < p) { ...do something... - }

-
- -

Getting input

-

To get a number from the player, add this method to your program:

-
-/**
- * Prints the given message (which should ask the user for some integral
- * quantity), and returns the number entered by the user. If the user's
- * response isn't an integer, the question is repeated until the user
- * does give a integer response.
- * 
- * @param message The request to present to the user.
- * @return The user's numeric response.
- */
- int getNumber(String message) {
-    while (true) {
-        System.out.print(message);
-        try {
-            return scanner.nextInt();
-        }
-        catch (InputMismatchException e) {
-            System.out.println("\"" + scanner.next() + "\" isn't a number!");
-        }
-    }
-}
-
- -

Here is an example of how you can use this method:

- -
-

sell = getNumber("O great Hammurabi, how many acres shall you sell?");

-
- -

Structure of the assignment:

- -
    -
  • Project name: Hammurabi
  • - -
  • Package name: hammurabi
  • - -
  • Class names and method signatures: - -
      -
    • - class Hammurabi - -
        -
      • public static void main(String[] args)
      • - -
      • Numerous other methods, as described above.
      • -
      -
    • -
    -
  • - -
- -

The above are requirements. The methods that do calculations, not input/output, will be tested by my test methods, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument names are irrelevant). You may have additional methods if you wish.

- -

Due date:

- -

Thursday, October 21, before midnight. Turn in your zipped assignment via - Blackboard. Email submissions will incur the wrath of Hammurabi (and won't be graded).

- - - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md deleted file mode 100644 index 796d85c..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md +++ /dev/null @@ -1,6 +0,0 @@ -# Notes - -from the original Dave Matuszek course of 2010. - -https://www.cis.upenn.edu/~matuszek/cit591-2010/Assignments/06-hammurabi.html - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml deleted file mode 100644 index d789654..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - 4.0.0 - - io.zipcoder - MicroLabs-Loops - 1.0-SNAPSHOT - - - - - junit - junit - 4.13.2 - - - - - - 1.8 - 1.8 - - \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore deleted file mode 100644 index a1c2a23..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore +++ /dev/null @@ -1,23 +0,0 @@ -# Compiled class file -*.class - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE deleted file mode 100644 index 22474e4..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2022 Zip Code Wilmington Core - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md deleted file mode 100644 index e4672c9..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md +++ /dev/null @@ -1,228 +0,0 @@ -# hamurabi -an ancient (in more ways than one) computer game (text) - -## General idea of the lab - -*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. - -Here are the standard instructions for the game: - -> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** -> -> * **Each person needs at least 20 bushels of grain per year to survive** -> * **Each person can farm at most 10 acres of land** -> * **It takes 2 bushels of grain to farm an acre of land** -> * **The market price for land fluctuates yearly** -> -> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** - -### Maven - -There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. - -### Details - -Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): - -```java -package hammurabi; // package declaration -import java.util.Random; // imports go here -import java.util.Scanner; - -public class Hammurabi { // must save in a file named Hammurabi.java - Random rand = new Random(); // this is an instance variable - Scanner scanner = new Scanner(System.in); - - public static void main(String\[\] args) { // required in every Java program - new Hammurabi().playGame(); - } - - void playGame() { - // declare local variables here: grain, population, etc. - // statements go after the declations - } - - //other methods go here -} -``` - -### Playing the game - -Here is what you start the game with: - -* 100 people -* 2800 bushels of grain in storage -* 1000 acres of land -* Land value is 19 bushels/acre - - -Each year, print out a summary similar to the following: - - O great Hammurabi! - You are in year 1 of your ten year rule. - In the previous year 0 people starved to death. - In the previous year 5 people entered the kingdom. - The population is now 100. - We harvested 3000 bushels at 3 bushels per acre. - Rats destroyed 200 bushels, leaving 2800 bushels in storage. - The city owns 1000 acres of land. - Land is currently worth 19 bushels per acre. - -The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. - -Here's what your `playGame` method needs to do each year, for up to 10 years: - -> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: -> -> `int askHowManyAcresToBuy(int price, int bushels)` -> -> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. -> -> ` -> int askHowManyAcresToSell(int acresOwned)` -> -> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. -> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. -> -> ` -> int askHowMuchGrainToFeedPeople(int bushels)` -> -> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. -> -> ` -> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` -> -> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. -> -> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) -> -> Then the method needs to determine: -> -> 1. If there is a plague, and how many people die from it. -> 2. How many people starved. -> 3. How many people came to the city. -> 4. How good the harvest is. -> 5. If you have a problem with rats, and how much grain they eat. -> 6. How much land costs (for deciding what to do next). -> -> These can all be local variables of your `playGame` method. -> -> Use the following methods, **in this order,** to make the necessary calculations: -> -> `int plagueDeaths(int population)` -> -> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). -> -> ` -> int starvationDeaths(int population, int bushelsFedToPeople)` -> -> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). -> -> ` -> boolean uprising(int population, int howManyPeopleStarved)` -> -> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) -> -> ` -> int immigrants(int population, int acresOwned, int grainInStorage)` -> -> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. -> -> ` -> int harvest(int acres, int bushelsUsedAsSeed)` -> -> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. -> -> ` -> int grainEatenByRats(int bushels)` -> -> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). -> -> ` -> int newCostOfLand()` -> -> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) - -Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. - -When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. - -When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. - -Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. - -All the required arithmetic in this program should be **integer**. You do not need doubles. - -### Urgent! - -> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. - -### Things you need to know: - -#### Random numbers - -To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: - -> `static Random rand = new Random();` - -To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as - -> `myNewNumber = rand.nextInt(5); -> if (rand.nextInt(100) < 15) { ... }` - -To do something that happens `p` percent of the time, use - -> `if (rand.nextInt(100) < p) { _...do something..._ }` - -#### Getting input - -To get a number from the player, add this method to your program: - -```java - /** - * Prints the given message (which should ask the user for some integral - * quantity), and returns the number entered by the user. If the user's - * response isn't an integer, the question is repeated until the user - * does give a integer response. - * - * @param message The request to present to the user. - * @return The user's numeric response. - */ - int getNumber(String message) { - while (true) { - System.out.print(message); - try { - return scanner.nextInt(); - } - catch (InputMismatchException e) { - System.out.println("\"" + scanner.next() + "\" isn't a number!"); - } - } - } -``` - -Here is an example of how you can use this method: - -> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` - -### Structure of the solution - -* Project name: `Hammurabi` -* Package name: `hammurabi` -* Class names and method signatures: - * `class Hammurabi` - * `public static void main(String[] args)` - * Numerous other methods, as described above. - -The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. - -### Yo! Test it! - -You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! - -But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. - -### Credits - -Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html deleted file mode 100644 index 78bbf24..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html +++ /dev/null @@ -1,299 +0,0 @@ - - - - - - - CIT591 Hammurabi - - - - - -

CIT 591 Assignment 3: - Hammurabi
- Fall 2010, David Matuszek

- -

Purpose of this assignment

- -
    -
  • To get you started using Java.
  • -
- -

General idea of the assignment

- -

Hammurabi is a very old computer game. Your job is to bring it into the - 21st century by writing it in Java.

- -

Here are the standard instructions for the game:

- -
-

Congratulations, you are the newest ruler of - ancient Samaria, elected for a ten year term of office. Your duties are to - dispense food, direct farming, and buy and sell land as needed to support - your people. Watch out for rat infestiations and the plague! Grain is the - general currency, measured in bushels. The following will help you in your - decisions:

- -
    -
  • Each person needs at least 20 bushels of - grain per year to survive
  • - -
  • Each person can farm at most 10 acres of - land
  • - -
  • It takes 2 bushels of grain to farm an acre - of land
  • - -
  • The market price for land fluctuates - yearly
  • -
- -

Rule wisely and you will be showered with - appreciation at the end of your term. Rule poorly and you will be kicked - out of office!

-
- -

Details

- -

Define a single class named Hammurabi. Use the following skeleton (but leave out the // comments):

-
package hammurabi;               // package declaration
-
-import java.util.Random;         // imports go here
-import java.util.Scanner;
-
-/**
- * The Hammurabi game.
- * @author Your name goes here
- * @author Your partner's name goes here
- */
-public class Hammurabi {         // must save in a file named Hammurabi.java
-    Random rand = new Random();  // this is an instance variable
-    Scanner scanner = new Scanner(System.in);
-
-    public static void main(String[] args) { // required in every Java program
-        new Hammurabi().playGame();
-    }
-
-    void playGame() {
-        // declare local variables here: grain, population, etc.
-        // statements go after the declations
-    }
-
-    //other methods go here
-}
-

Playing the game

-

Here is what you start the game with: -

    -
  • 100 people
  • -
  • 2800 bushels of grain in storage
  • -
  • 1000 acres of land
  • -
  • Land value is 19 bushels/acre

    -
  • -
-

Each year, print out a summary similar to the following:

-
-O great Hammurabi!
-You are in year 1 of your ten year rule.
-In the previous year 0 people starved to death.
-In the previous year 5 people entered the kingdom.
-The population is now 100.
-We harvested 3000 bushels at 3 bushels per acre.
-Rats destroyed 200 bushels, leaving 2800 bushels in storage.
-The city owns 1000 acres of land.
-Land is currently worth 19 bushels per acre.
-
- -

The above summary represents the initial state, at the beginning of - the first year--that is, when you first take office, and before you do any of - the computations below). So, for example, the previous year (under a - different ruler) must have started with 95 people; none starved, and 5 - entered the kingdom, so as you enter office you rule 100 people.

- -

Here's what your playGame method needs to do each year, for up to 10 years:

- -
-

Ask the player the following questions. These questions should be asked in this order. Do not give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below:

-
-
int askHowManyAcresToBuy(int price, int bushels)
-
Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase.
-

- int askHowManyAcresToSell(int acresOwned)
-
Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have.
- Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn.
-

- int askHowMuchGrainToFeedPeople(int bushels)
-
Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You can feed them more than they need to survive.
-

- int askHowManyAcresToPlant(int acresOwned, int population, int bushels)
-
Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year.
-
-

For each - question, do "sanity checking"; that is, test whether the answer is - possible (you have enough grain, you have enough people to do the planting - etc.), and keep asking until you get a possible value. (For example, - O Great Hammurabi, surely you jest! We have only 3415 bushels left!)

- -

Then the method needs to determine:

- -
    -
  1. If there is a plague, and how many people die from it.
  2. -
  3. How many people starved.
  4. -
  5. How many people came to the city.
  6. -
  7. How good the harvest is.
  8. -
  9. If you have a problem with rats, and how much grain they eat.
  10. -
  11. How much land costs (for deciding what to do next).
  12. -
-

These can all be local variables of your playGame method.

-

Use the following methods, in this order, to make the necessary calculations:

-
-
int plagueDeaths(int population)
-
Each year, there is a 15% chance of a horrible plague. When this - happens, half your people die. Return the number of plague deaths (possibly zero).
-

- int starvationDeaths(int population, int bushelsFedToPeople)
-
Each person needs 20 bushels of grain to survive. If you feed them - more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero).
-

- boolean uprising(int population, int howManyPeopleStarved)
-
Return true if more than - 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.)
-

- int immigrants(int population, int acresOwned, int grainInStorage)
-
Nobody will come to the city if people are starving (so don't call this method). If everyone is - well fed, compute how many people come to the city as: (20 * number of acres you have + amount of grain you have in - storage) / (100 * population) + 1.
-

- int harvest(int acres, int bushelsUsedAsSeed)
-
Choose a random integer between 1 and 6, inclusive. Each acre that was planted - with seed will yield this many bushels of grain. (Example: if you planted - 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested.
-

- int grainEatenByRats(int bushels)
-
There is a 40% chance that you will have a rat infestation. When this - happens, rats will eat somewhere between 10% and 30% of your - grain. Return the amount of grain eaten by rats (possibly zero).
-

- int newCostOfLand()
-
The price of land is random, and ranges from 17 to 23 bushels per - acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell - land.)
-
-
-

Do these computations, in this order, for each of ten years. Each - computation should be done in a separate method, and none of these methods - should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it.

- -

When the computations are finished, call a method printSummary to print the - summary for the year. This method will take several parameters.

- - -

When the game ends , use a method finalSummary to print out a final summary, and to tell the - player how good a job he/she did. I'll leave the details up to you, but the - usual evaluation is based on how many people starved, and how many acres per - person you end up with.

-

Your playGame method will be quite long, but very straightforward; it does very little but call other methods.

-

All the required arithmetic in this program should be integer. You - do not need doubles.

- -

I suggest that you first get the simplest possible version of the program - running and tested out (that is, leave out things like rats, plagues, and - immigration), then add these things one at a time to a working - program, testing as you go.

- -

Things you need to know:

- -

Random numbers

- -

To get a random number generator, you first need to import - java.util.Random (or java.util.*). Then, you can - create a random number generator with a statement such as:

- -
-

static Random rand = new Random();

-
- -

To get a new random number in the range 0..n-1, where - n is an int, call rand.nextInt(n). - To get a new random number in the range min..max, use - the expression rand.nextInt(max - min + 1) + min. You - can use the rand method in statements such as

- -
-

myNewNumber = rand.nextInt(5);
- if (rand.nextInt(100) < 15) { ... }

-
- -

To do something that happens p percent of the time, use

- -
-

if (rand.nextInt(100) < p) { ...do something... - }

-
- -

Getting input

-

To get a number from the player, add this method to your program:

-
-/**
- * Prints the given message (which should ask the user for some integral
- * quantity), and returns the number entered by the user. If the user's
- * response isn't an integer, the question is repeated until the user
- * does give a integer response.
- * 
- * @param message The request to present to the user.
- * @return The user's numeric response.
- */
- int getNumber(String message) {
-    while (true) {
-        System.out.print(message);
-        try {
-            return scanner.nextInt();
-        }
-        catch (InputMismatchException e) {
-            System.out.println("\"" + scanner.next() + "\" isn't a number!");
-        }
-    }
-}
-
- -

Here is an example of how you can use this method:

- -
-

sell = getNumber("O great Hammurabi, how many acres shall you sell?");

-
- -

Structure of the assignment:

- -
    -
  • Project name: Hammurabi
  • - -
  • Package name: hammurabi
  • - -
  • Class names and method signatures: - -
      -
    • - class Hammurabi - -
        -
      • public static void main(String[] args)
      • - -
      • Numerous other methods, as described above.
      • -
      -
    • -
    -
  • - -
- -

The above are requirements. The methods that do calculations, not input/output, will be tested by my test methods, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument names are irrelevant). You may have additional methods if you wish.

- -

Due date:

- -

Thursday, October 21, before midnight. Turn in your zipped assignment via - Blackboard. Email submissions will incur the wrath of Hammurabi (and won't be graded).

- - - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md deleted file mode 100644 index 796d85c..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md +++ /dev/null @@ -1,6 +0,0 @@ -# Notes - -from the original Dave Matuszek course of 2010. - -https://www.cis.upenn.edu/~matuszek/cit591-2010/Assignments/06-hammurabi.html - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml deleted file mode 100644 index d789654..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - 4.0.0 - - io.zipcoder - MicroLabs-Loops - 1.0-SNAPSHOT - - - - - junit - junit - 4.13.2 - - - - - - 1.8 - 1.8 - - \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore deleted file mode 100644 index a1c2a23..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore +++ /dev/null @@ -1,23 +0,0 @@ -# Compiled class file -*.class - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE deleted file mode 100644 index 22474e4..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2022 Zip Code Wilmington Core - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md deleted file mode 100644 index e4672c9..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md +++ /dev/null @@ -1,228 +0,0 @@ -# hamurabi -an ancient (in more ways than one) computer game (text) - -## General idea of the lab - -*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. - -Here are the standard instructions for the game: - -> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** -> -> * **Each person needs at least 20 bushels of grain per year to survive** -> * **Each person can farm at most 10 acres of land** -> * **It takes 2 bushels of grain to farm an acre of land** -> * **The market price for land fluctuates yearly** -> -> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** - -### Maven - -There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. - -### Details - -Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): - -```java -package hammurabi; // package declaration -import java.util.Random; // imports go here -import java.util.Scanner; - -public class Hammurabi { // must save in a file named Hammurabi.java - Random rand = new Random(); // this is an instance variable - Scanner scanner = new Scanner(System.in); - - public static void main(String\[\] args) { // required in every Java program - new Hammurabi().playGame(); - } - - void playGame() { - // declare local variables here: grain, population, etc. - // statements go after the declations - } - - //other methods go here -} -``` - -### Playing the game - -Here is what you start the game with: - -* 100 people -* 2800 bushels of grain in storage -* 1000 acres of land -* Land value is 19 bushels/acre - - -Each year, print out a summary similar to the following: - - O great Hammurabi! - You are in year 1 of your ten year rule. - In the previous year 0 people starved to death. - In the previous year 5 people entered the kingdom. - The population is now 100. - We harvested 3000 bushels at 3 bushels per acre. - Rats destroyed 200 bushels, leaving 2800 bushels in storage. - The city owns 1000 acres of land. - Land is currently worth 19 bushels per acre. - -The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. - -Here's what your `playGame` method needs to do each year, for up to 10 years: - -> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: -> -> `int askHowManyAcresToBuy(int price, int bushels)` -> -> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. -> -> ` -> int askHowManyAcresToSell(int acresOwned)` -> -> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. -> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. -> -> ` -> int askHowMuchGrainToFeedPeople(int bushels)` -> -> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. -> -> ` -> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` -> -> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. -> -> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) -> -> Then the method needs to determine: -> -> 1. If there is a plague, and how many people die from it. -> 2. How many people starved. -> 3. How many people came to the city. -> 4. How good the harvest is. -> 5. If you have a problem with rats, and how much grain they eat. -> 6. How much land costs (for deciding what to do next). -> -> These can all be local variables of your `playGame` method. -> -> Use the following methods, **in this order,** to make the necessary calculations: -> -> `int plagueDeaths(int population)` -> -> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). -> -> ` -> int starvationDeaths(int population, int bushelsFedToPeople)` -> -> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). -> -> ` -> boolean uprising(int population, int howManyPeopleStarved)` -> -> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) -> -> ` -> int immigrants(int population, int acresOwned, int grainInStorage)` -> -> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. -> -> ` -> int harvest(int acres, int bushelsUsedAsSeed)` -> -> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. -> -> ` -> int grainEatenByRats(int bushels)` -> -> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). -> -> ` -> int newCostOfLand()` -> -> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) - -Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. - -When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. - -When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. - -Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. - -All the required arithmetic in this program should be **integer**. You do not need doubles. - -### Urgent! - -> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. - -### Things you need to know: - -#### Random numbers - -To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: - -> `static Random rand = new Random();` - -To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as - -> `myNewNumber = rand.nextInt(5); -> if (rand.nextInt(100) < 15) { ... }` - -To do something that happens `p` percent of the time, use - -> `if (rand.nextInt(100) < p) { _...do something..._ }` - -#### Getting input - -To get a number from the player, add this method to your program: - -```java - /** - * Prints the given message (which should ask the user for some integral - * quantity), and returns the number entered by the user. If the user's - * response isn't an integer, the question is repeated until the user - * does give a integer response. - * - * @param message The request to present to the user. - * @return The user's numeric response. - */ - int getNumber(String message) { - while (true) { - System.out.print(message); - try { - return scanner.nextInt(); - } - catch (InputMismatchException e) { - System.out.println("\"" + scanner.next() + "\" isn't a number!"); - } - } - } -``` - -Here is an example of how you can use this method: - -> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` - -### Structure of the solution - -* Project name: `Hammurabi` -* Package name: `hammurabi` -* Class names and method signatures: - * `class Hammurabi` - * `public static void main(String[] args)` - * Numerous other methods, as described above. - -The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. - -### Yo! Test it! - -You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! - -But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. - -### Credits - -Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html deleted file mode 100644 index 78bbf24..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html +++ /dev/null @@ -1,299 +0,0 @@ - - - - - - - CIT591 Hammurabi - - - - - -

CIT 591 Assignment 3: - Hammurabi
- Fall 2010, David Matuszek

- -

Purpose of this assignment

- -
    -
  • To get you started using Java.
  • -
- -

General idea of the assignment

- -

Hammurabi is a very old computer game. Your job is to bring it into the - 21st century by writing it in Java.

- -

Here are the standard instructions for the game:

- -
-

Congratulations, you are the newest ruler of - ancient Samaria, elected for a ten year term of office. Your duties are to - dispense food, direct farming, and buy and sell land as needed to support - your people. Watch out for rat infestiations and the plague! Grain is the - general currency, measured in bushels. The following will help you in your - decisions:

- -
    -
  • Each person needs at least 20 bushels of - grain per year to survive
  • - -
  • Each person can farm at most 10 acres of - land
  • - -
  • It takes 2 bushels of grain to farm an acre - of land
  • - -
  • The market price for land fluctuates - yearly
  • -
- -

Rule wisely and you will be showered with - appreciation at the end of your term. Rule poorly and you will be kicked - out of office!

-
- -

Details

- -

Define a single class named Hammurabi. Use the following skeleton (but leave out the // comments):

-
package hammurabi;               // package declaration
-
-import java.util.Random;         // imports go here
-import java.util.Scanner;
-
-/**
- * The Hammurabi game.
- * @author Your name goes here
- * @author Your partner's name goes here
- */
-public class Hammurabi {         // must save in a file named Hammurabi.java
-    Random rand = new Random();  // this is an instance variable
-    Scanner scanner = new Scanner(System.in);
-
-    public static void main(String[] args) { // required in every Java program
-        new Hammurabi().playGame();
-    }
-
-    void playGame() {
-        // declare local variables here: grain, population, etc.
-        // statements go after the declations
-    }
-
-    //other methods go here
-}
-

Playing the game

-

Here is what you start the game with: -

    -
  • 100 people
  • -
  • 2800 bushels of grain in storage
  • -
  • 1000 acres of land
  • -
  • Land value is 19 bushels/acre

    -
  • -
-

Each year, print out a summary similar to the following:

-
-O great Hammurabi!
-You are in year 1 of your ten year rule.
-In the previous year 0 people starved to death.
-In the previous year 5 people entered the kingdom.
-The population is now 100.
-We harvested 3000 bushels at 3 bushels per acre.
-Rats destroyed 200 bushels, leaving 2800 bushels in storage.
-The city owns 1000 acres of land.
-Land is currently worth 19 bushels per acre.
-
- -

The above summary represents the initial state, at the beginning of - the first year--that is, when you first take office, and before you do any of - the computations below). So, for example, the previous year (under a - different ruler) must have started with 95 people; none starved, and 5 - entered the kingdom, so as you enter office you rule 100 people.

- -

Here's what your playGame method needs to do each year, for up to 10 years:

- -
-

Ask the player the following questions. These questions should be asked in this order. Do not give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below:

-
-
int askHowManyAcresToBuy(int price, int bushels)
-
Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase.
-

- int askHowManyAcresToSell(int acresOwned)
-
Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have.
- Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn.
-

- int askHowMuchGrainToFeedPeople(int bushels)
-
Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You can feed them more than they need to survive.
-

- int askHowManyAcresToPlant(int acresOwned, int population, int bushels)
-
Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year.
-
-

For each - question, do "sanity checking"; that is, test whether the answer is - possible (you have enough grain, you have enough people to do the planting - etc.), and keep asking until you get a possible value. (For example, - O Great Hammurabi, surely you jest! We have only 3415 bushels left!)

- -

Then the method needs to determine:

- -
    -
  1. If there is a plague, and how many people die from it.
  2. -
  3. How many people starved.
  4. -
  5. How many people came to the city.
  6. -
  7. How good the harvest is.
  8. -
  9. If you have a problem with rats, and how much grain they eat.
  10. -
  11. How much land costs (for deciding what to do next).
  12. -
-

These can all be local variables of your playGame method.

-

Use the following methods, in this order, to make the necessary calculations:

-
-
int plagueDeaths(int population)
-
Each year, there is a 15% chance of a horrible plague. When this - happens, half your people die. Return the number of plague deaths (possibly zero).
-

- int starvationDeaths(int population, int bushelsFedToPeople)
-
Each person needs 20 bushels of grain to survive. If you feed them - more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero).
-

- boolean uprising(int population, int howManyPeopleStarved)
-
Return true if more than - 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.)
-

- int immigrants(int population, int acresOwned, int grainInStorage)
-
Nobody will come to the city if people are starving (so don't call this method). If everyone is - well fed, compute how many people come to the city as: (20 * number of acres you have + amount of grain you have in - storage) / (100 * population) + 1.
-

- int harvest(int acres, int bushelsUsedAsSeed)
-
Choose a random integer between 1 and 6, inclusive. Each acre that was planted - with seed will yield this many bushels of grain. (Example: if you planted - 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested.
-

- int grainEatenByRats(int bushels)
-
There is a 40% chance that you will have a rat infestation. When this - happens, rats will eat somewhere between 10% and 30% of your - grain. Return the amount of grain eaten by rats (possibly zero).
-

- int newCostOfLand()
-
The price of land is random, and ranges from 17 to 23 bushels per - acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell - land.)
-
-
-

Do these computations, in this order, for each of ten years. Each - computation should be done in a separate method, and none of these methods - should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it.

- -

When the computations are finished, call a method printSummary to print the - summary for the year. This method will take several parameters.

- - -

When the game ends , use a method finalSummary to print out a final summary, and to tell the - player how good a job he/she did. I'll leave the details up to you, but the - usual evaluation is based on how many people starved, and how many acres per - person you end up with.

-

Your playGame method will be quite long, but very straightforward; it does very little but call other methods.

-

All the required arithmetic in this program should be integer. You - do not need doubles.

- -

I suggest that you first get the simplest possible version of the program - running and tested out (that is, leave out things like rats, plagues, and - immigration), then add these things one at a time to a working - program, testing as you go.

- -

Things you need to know:

- -

Random numbers

- -

To get a random number generator, you first need to import - java.util.Random (or java.util.*). Then, you can - create a random number generator with a statement such as:

- -
-

static Random rand = new Random();

-
- -

To get a new random number in the range 0..n-1, where - n is an int, call rand.nextInt(n). - To get a new random number in the range min..max, use - the expression rand.nextInt(max - min + 1) + min. You - can use the rand method in statements such as

- -
-

myNewNumber = rand.nextInt(5);
- if (rand.nextInt(100) < 15) { ... }

-
- -

To do something that happens p percent of the time, use

- -
-

if (rand.nextInt(100) < p) { ...do something... - }

-
- -

Getting input

-

To get a number from the player, add this method to your program:

-
-/**
- * Prints the given message (which should ask the user for some integral
- * quantity), and returns the number entered by the user. If the user's
- * response isn't an integer, the question is repeated until the user
- * does give a integer response.
- * 
- * @param message The request to present to the user.
- * @return The user's numeric response.
- */
- int getNumber(String message) {
-    while (true) {
-        System.out.print(message);
-        try {
-            return scanner.nextInt();
-        }
-        catch (InputMismatchException e) {
-            System.out.println("\"" + scanner.next() + "\" isn't a number!");
-        }
-    }
-}
-
- -

Here is an example of how you can use this method:

- -
-

sell = getNumber("O great Hammurabi, how many acres shall you sell?");

-
- -

Structure of the assignment:

- -
    -
  • Project name: Hammurabi
  • - -
  • Package name: hammurabi
  • - -
  • Class names and method signatures: - -
      -
    • - class Hammurabi - -
        -
      • public static void main(String[] args)
      • - -
      • Numerous other methods, as described above.
      • -
      -
    • -
    -
  • - -
- -

The above are requirements. The methods that do calculations, not input/output, will be tested by my test methods, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument names are irrelevant). You may have additional methods if you wish.

- -

Due date:

- -

Thursday, October 21, before midnight. Turn in your zipped assignment via - Blackboard. Email submissions will incur the wrath of Hammurabi (and won't be graded).

- - - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md deleted file mode 100644 index 796d85c..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md +++ /dev/null @@ -1,6 +0,0 @@ -# Notes - -from the original Dave Matuszek course of 2010. - -https://www.cis.upenn.edu/~matuszek/cit591-2010/Assignments/06-hammurabi.html - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml deleted file mode 100644 index d789654..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - 4.0.0 - - io.zipcoder - MicroLabs-Loops - 1.0-SNAPSHOT - - - - - junit - junit - 4.13.2 - - - - - - 1.8 - 1.8 - - \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore deleted file mode 100644 index a1c2a23..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore +++ /dev/null @@ -1,23 +0,0 @@ -# Compiled class file -*.class - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE deleted file mode 100644 index 22474e4..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2022 Zip Code Wilmington Core - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md deleted file mode 100644 index e4672c9..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md +++ /dev/null @@ -1,228 +0,0 @@ -# hamurabi -an ancient (in more ways than one) computer game (text) - -## General idea of the lab - -*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. - -Here are the standard instructions for the game: - -> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** -> -> * **Each person needs at least 20 bushels of grain per year to survive** -> * **Each person can farm at most 10 acres of land** -> * **It takes 2 bushels of grain to farm an acre of land** -> * **The market price for land fluctuates yearly** -> -> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** - -### Maven - -There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. - -### Details - -Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): - -```java -package hammurabi; // package declaration -import java.util.Random; // imports go here -import java.util.Scanner; - -public class Hammurabi { // must save in a file named Hammurabi.java - Random rand = new Random(); // this is an instance variable - Scanner scanner = new Scanner(System.in); - - public static void main(String\[\] args) { // required in every Java program - new Hammurabi().playGame(); - } - - void playGame() { - // declare local variables here: grain, population, etc. - // statements go after the declations - } - - //other methods go here -} -``` - -### Playing the game - -Here is what you start the game with: - -* 100 people -* 2800 bushels of grain in storage -* 1000 acres of land -* Land value is 19 bushels/acre - - -Each year, print out a summary similar to the following: - - O great Hammurabi! - You are in year 1 of your ten year rule. - In the previous year 0 people starved to death. - In the previous year 5 people entered the kingdom. - The population is now 100. - We harvested 3000 bushels at 3 bushels per acre. - Rats destroyed 200 bushels, leaving 2800 bushels in storage. - The city owns 1000 acres of land. - Land is currently worth 19 bushels per acre. - -The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. - -Here's what your `playGame` method needs to do each year, for up to 10 years: - -> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: -> -> `int askHowManyAcresToBuy(int price, int bushels)` -> -> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. -> -> ` -> int askHowManyAcresToSell(int acresOwned)` -> -> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. -> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. -> -> ` -> int askHowMuchGrainToFeedPeople(int bushels)` -> -> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. -> -> ` -> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` -> -> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. -> -> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) -> -> Then the method needs to determine: -> -> 1. If there is a plague, and how many people die from it. -> 2. How many people starved. -> 3. How many people came to the city. -> 4. How good the harvest is. -> 5. If you have a problem with rats, and how much grain they eat. -> 6. How much land costs (for deciding what to do next). -> -> These can all be local variables of your `playGame` method. -> -> Use the following methods, **in this order,** to make the necessary calculations: -> -> `int plagueDeaths(int population)` -> -> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). -> -> ` -> int starvationDeaths(int population, int bushelsFedToPeople)` -> -> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). -> -> ` -> boolean uprising(int population, int howManyPeopleStarved)` -> -> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) -> -> ` -> int immigrants(int population, int acresOwned, int grainInStorage)` -> -> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. -> -> ` -> int harvest(int acres, int bushelsUsedAsSeed)` -> -> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. -> -> ` -> int grainEatenByRats(int bushels)` -> -> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). -> -> ` -> int newCostOfLand()` -> -> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) - -Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. - -When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. - -When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. - -Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. - -All the required arithmetic in this program should be **integer**. You do not need doubles. - -### Urgent! - -> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. - -### Things you need to know: - -#### Random numbers - -To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: - -> `static Random rand = new Random();` - -To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as - -> `myNewNumber = rand.nextInt(5); -> if (rand.nextInt(100) < 15) { ... }` - -To do something that happens `p` percent of the time, use - -> `if (rand.nextInt(100) < p) { _...do something..._ }` - -#### Getting input - -To get a number from the player, add this method to your program: - -```java - /** - * Prints the given message (which should ask the user for some integral - * quantity), and returns the number entered by the user. If the user's - * response isn't an integer, the question is repeated until the user - * does give a integer response. - * - * @param message The request to present to the user. - * @return The user's numeric response. - */ - int getNumber(String message) { - while (true) { - System.out.print(message); - try { - return scanner.nextInt(); - } - catch (InputMismatchException e) { - System.out.println("\"" + scanner.next() + "\" isn't a number!"); - } - } - } -``` - -Here is an example of how you can use this method: - -> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` - -### Structure of the solution - -* Project name: `Hammurabi` -* Package name: `hammurabi` -* Class names and method signatures: - * `class Hammurabi` - * `public static void main(String[] args)` - * Numerous other methods, as described above. - -The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. - -### Yo! Test it! - -You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! - -But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. - -### Credits - -Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html deleted file mode 100644 index 78bbf24..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html +++ /dev/null @@ -1,299 +0,0 @@ - - - - - - - CIT591 Hammurabi - - - - - -

CIT 591 Assignment 3: - Hammurabi
- Fall 2010, David Matuszek

- -

Purpose of this assignment

- -
    -
  • To get you started using Java.
  • -
- -

General idea of the assignment

- -

Hammurabi is a very old computer game. Your job is to bring it into the - 21st century by writing it in Java.

- -

Here are the standard instructions for the game:

- -
-

Congratulations, you are the newest ruler of - ancient Samaria, elected for a ten year term of office. Your duties are to - dispense food, direct farming, and buy and sell land as needed to support - your people. Watch out for rat infestiations and the plague! Grain is the - general currency, measured in bushels. The following will help you in your - decisions:

- -
    -
  • Each person needs at least 20 bushels of - grain per year to survive
  • - -
  • Each person can farm at most 10 acres of - land
  • - -
  • It takes 2 bushels of grain to farm an acre - of land
  • - -
  • The market price for land fluctuates - yearly
  • -
- -

Rule wisely and you will be showered with - appreciation at the end of your term. Rule poorly and you will be kicked - out of office!

-
- -

Details

- -

Define a single class named Hammurabi. Use the following skeleton (but leave out the // comments):

-
package hammurabi;               // package declaration
-
-import java.util.Random;         // imports go here
-import java.util.Scanner;
-
-/**
- * The Hammurabi game.
- * @author Your name goes here
- * @author Your partner's name goes here
- */
-public class Hammurabi {         // must save in a file named Hammurabi.java
-    Random rand = new Random();  // this is an instance variable
-    Scanner scanner = new Scanner(System.in);
-
-    public static void main(String[] args) { // required in every Java program
-        new Hammurabi().playGame();
-    }
-
-    void playGame() {
-        // declare local variables here: grain, population, etc.
-        // statements go after the declations
-    }
-
-    //other methods go here
-}
-

Playing the game

-

Here is what you start the game with: -

    -
  • 100 people
  • -
  • 2800 bushels of grain in storage
  • -
  • 1000 acres of land
  • -
  • Land value is 19 bushels/acre

    -
  • -
-

Each year, print out a summary similar to the following:

-
-O great Hammurabi!
-You are in year 1 of your ten year rule.
-In the previous year 0 people starved to death.
-In the previous year 5 people entered the kingdom.
-The population is now 100.
-We harvested 3000 bushels at 3 bushels per acre.
-Rats destroyed 200 bushels, leaving 2800 bushels in storage.
-The city owns 1000 acres of land.
-Land is currently worth 19 bushels per acre.
-
- -

The above summary represents the initial state, at the beginning of - the first year--that is, when you first take office, and before you do any of - the computations below). So, for example, the previous year (under a - different ruler) must have started with 95 people; none starved, and 5 - entered the kingdom, so as you enter office you rule 100 people.

- -

Here's what your playGame method needs to do each year, for up to 10 years:

- -
-

Ask the player the following questions. These questions should be asked in this order. Do not give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below:

-
-
int askHowManyAcresToBuy(int price, int bushels)
-
Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase.
-

- int askHowManyAcresToSell(int acresOwned)
-
Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have.
- Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn.
-

- int askHowMuchGrainToFeedPeople(int bushels)
-
Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You can feed them more than they need to survive.
-

- int askHowManyAcresToPlant(int acresOwned, int population, int bushels)
-
Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year.
-
-

For each - question, do "sanity checking"; that is, test whether the answer is - possible (you have enough grain, you have enough people to do the planting - etc.), and keep asking until you get a possible value. (For example, - O Great Hammurabi, surely you jest! We have only 3415 bushels left!)

- -

Then the method needs to determine:

- -
    -
  1. If there is a plague, and how many people die from it.
  2. -
  3. How many people starved.
  4. -
  5. How many people came to the city.
  6. -
  7. How good the harvest is.
  8. -
  9. If you have a problem with rats, and how much grain they eat.
  10. -
  11. How much land costs (for deciding what to do next).
  12. -
-

These can all be local variables of your playGame method.

-

Use the following methods, in this order, to make the necessary calculations:

-
-
int plagueDeaths(int population)
-
Each year, there is a 15% chance of a horrible plague. When this - happens, half your people die. Return the number of plague deaths (possibly zero).
-

- int starvationDeaths(int population, int bushelsFedToPeople)
-
Each person needs 20 bushels of grain to survive. If you feed them - more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero).
-

- boolean uprising(int population, int howManyPeopleStarved)
-
Return true if more than - 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.)
-

- int immigrants(int population, int acresOwned, int grainInStorage)
-
Nobody will come to the city if people are starving (so don't call this method). If everyone is - well fed, compute how many people come to the city as: (20 * number of acres you have + amount of grain you have in - storage) / (100 * population) + 1.
-

- int harvest(int acres, int bushelsUsedAsSeed)
-
Choose a random integer between 1 and 6, inclusive. Each acre that was planted - with seed will yield this many bushels of grain. (Example: if you planted - 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested.
-

- int grainEatenByRats(int bushels)
-
There is a 40% chance that you will have a rat infestation. When this - happens, rats will eat somewhere between 10% and 30% of your - grain. Return the amount of grain eaten by rats (possibly zero).
-

- int newCostOfLand()
-
The price of land is random, and ranges from 17 to 23 bushels per - acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell - land.)
-
-
-

Do these computations, in this order, for each of ten years. Each - computation should be done in a separate method, and none of these methods - should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it.

- -

When the computations are finished, call a method printSummary to print the - summary for the year. This method will take several parameters.

- - -

When the game ends , use a method finalSummary to print out a final summary, and to tell the - player how good a job he/she did. I'll leave the details up to you, but the - usual evaluation is based on how many people starved, and how many acres per - person you end up with.

-

Your playGame method will be quite long, but very straightforward; it does very little but call other methods.

-

All the required arithmetic in this program should be integer. You - do not need doubles.

- -

I suggest that you first get the simplest possible version of the program - running and tested out (that is, leave out things like rats, plagues, and - immigration), then add these things one at a time to a working - program, testing as you go.

- -

Things you need to know:

- -

Random numbers

- -

To get a random number generator, you first need to import - java.util.Random (or java.util.*). Then, you can - create a random number generator with a statement such as:

- -
-

static Random rand = new Random();

-
- -

To get a new random number in the range 0..n-1, where - n is an int, call rand.nextInt(n). - To get a new random number in the range min..max, use - the expression rand.nextInt(max - min + 1) + min. You - can use the rand method in statements such as

- -
-

myNewNumber = rand.nextInt(5);
- if (rand.nextInt(100) < 15) { ... }

-
- -

To do something that happens p percent of the time, use

- -
-

if (rand.nextInt(100) < p) { ...do something... - }

-
- -

Getting input

-

To get a number from the player, add this method to your program:

-
-/**
- * Prints the given message (which should ask the user for some integral
- * quantity), and returns the number entered by the user. If the user's
- * response isn't an integer, the question is repeated until the user
- * does give a integer response.
- * 
- * @param message The request to present to the user.
- * @return The user's numeric response.
- */
- int getNumber(String message) {
-    while (true) {
-        System.out.print(message);
-        try {
-            return scanner.nextInt();
-        }
-        catch (InputMismatchException e) {
-            System.out.println("\"" + scanner.next() + "\" isn't a number!");
-        }
-    }
-}
-
- -

Here is an example of how you can use this method:

- -
-

sell = getNumber("O great Hammurabi, how many acres shall you sell?");

-
- -

Structure of the assignment:

- -
    -
  • Project name: Hammurabi
  • - -
  • Package name: hammurabi
  • - -
  • Class names and method signatures: - -
      -
    • - class Hammurabi - -
        -
      • public static void main(String[] args)
      • - -
      • Numerous other methods, as described above.
      • -
      -
    • -
    -
  • - -
- -

The above are requirements. The methods that do calculations, not input/output, will be tested by my test methods, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument names are irrelevant). You may have additional methods if you wish.

- -

Due date:

- -

Thursday, October 21, before midnight. Turn in your zipped assignment via - Blackboard. Email submissions will incur the wrath of Hammurabi (and won't be graded).

- - - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md deleted file mode 100644 index 796d85c..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md +++ /dev/null @@ -1,6 +0,0 @@ -# Notes - -from the original Dave Matuszek course of 2010. - -https://www.cis.upenn.edu/~matuszek/cit591-2010/Assignments/06-hammurabi.html - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml deleted file mode 100644 index d789654..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - 4.0.0 - - io.zipcoder - MicroLabs-Loops - 1.0-SNAPSHOT - - - - - junit - junit - 4.13.2 - - - - - - 1.8 - 1.8 - - \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore deleted file mode 100644 index a1c2a23..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore +++ /dev/null @@ -1,23 +0,0 @@ -# Compiled class file -*.class - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE deleted file mode 100644 index 22474e4..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2022 Zip Code Wilmington Core - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md deleted file mode 100644 index e4672c9..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md +++ /dev/null @@ -1,228 +0,0 @@ -# hamurabi -an ancient (in more ways than one) computer game (text) - -## General idea of the lab - -*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. - -Here are the standard instructions for the game: - -> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** -> -> * **Each person needs at least 20 bushels of grain per year to survive** -> * **Each person can farm at most 10 acres of land** -> * **It takes 2 bushels of grain to farm an acre of land** -> * **The market price for land fluctuates yearly** -> -> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** - -### Maven - -There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. - -### Details - -Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): - -```java -package hammurabi; // package declaration -import java.util.Random; // imports go here -import java.util.Scanner; - -public class Hammurabi { // must save in a file named Hammurabi.java - Random rand = new Random(); // this is an instance variable - Scanner scanner = new Scanner(System.in); - - public static void main(String\[\] args) { // required in every Java program - new Hammurabi().playGame(); - } - - void playGame() { - // declare local variables here: grain, population, etc. - // statements go after the declations - } - - //other methods go here -} -``` - -### Playing the game - -Here is what you start the game with: - -* 100 people -* 2800 bushels of grain in storage -* 1000 acres of land -* Land value is 19 bushels/acre - - -Each year, print out a summary similar to the following: - - O great Hammurabi! - You are in year 1 of your ten year rule. - In the previous year 0 people starved to death. - In the previous year 5 people entered the kingdom. - The population is now 100. - We harvested 3000 bushels at 3 bushels per acre. - Rats destroyed 200 bushels, leaving 2800 bushels in storage. - The city owns 1000 acres of land. - Land is currently worth 19 bushels per acre. - -The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. - -Here's what your `playGame` method needs to do each year, for up to 10 years: - -> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: -> -> `int askHowManyAcresToBuy(int price, int bushels)` -> -> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. -> -> ` -> int askHowManyAcresToSell(int acresOwned)` -> -> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. -> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. -> -> ` -> int askHowMuchGrainToFeedPeople(int bushels)` -> -> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. -> -> ` -> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` -> -> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. -> -> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) -> -> Then the method needs to determine: -> -> 1. If there is a plague, and how many people die from it. -> 2. How many people starved. -> 3. How many people came to the city. -> 4. How good the harvest is. -> 5. If you have a problem with rats, and how much grain they eat. -> 6. How much land costs (for deciding what to do next). -> -> These can all be local variables of your `playGame` method. -> -> Use the following methods, **in this order,** to make the necessary calculations: -> -> `int plagueDeaths(int population)` -> -> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). -> -> ` -> int starvationDeaths(int population, int bushelsFedToPeople)` -> -> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). -> -> ` -> boolean uprising(int population, int howManyPeopleStarved)` -> -> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) -> -> ` -> int immigrants(int population, int acresOwned, int grainInStorage)` -> -> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. -> -> ` -> int harvest(int acres, int bushelsUsedAsSeed)` -> -> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. -> -> ` -> int grainEatenByRats(int bushels)` -> -> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). -> -> ` -> int newCostOfLand()` -> -> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) - -Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. - -When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. - -When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. - -Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. - -All the required arithmetic in this program should be **integer**. You do not need doubles. - -### Urgent! - -> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. - -### Things you need to know: - -#### Random numbers - -To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: - -> `static Random rand = new Random();` - -To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as - -> `myNewNumber = rand.nextInt(5); -> if (rand.nextInt(100) < 15) { ... }` - -To do something that happens `p` percent of the time, use - -> `if (rand.nextInt(100) < p) { _...do something..._ }` - -#### Getting input - -To get a number from the player, add this method to your program: - -```java - /** - * Prints the given message (which should ask the user for some integral - * quantity), and returns the number entered by the user. If the user's - * response isn't an integer, the question is repeated until the user - * does give a integer response. - * - * @param message The request to present to the user. - * @return The user's numeric response. - */ - int getNumber(String message) { - while (true) { - System.out.print(message); - try { - return scanner.nextInt(); - } - catch (InputMismatchException e) { - System.out.println("\"" + scanner.next() + "\" isn't a number!"); - } - } - } -``` - -Here is an example of how you can use this method: - -> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` - -### Structure of the solution - -* Project name: `Hammurabi` -* Package name: `hammurabi` -* Class names and method signatures: - * `class Hammurabi` - * `public static void main(String[] args)` - * Numerous other methods, as described above. - -The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. - -### Yo! Test it! - -You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! - -But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. - -### Credits - -Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html deleted file mode 100644 index 78bbf24..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html +++ /dev/null @@ -1,299 +0,0 @@ - - - - - - - CIT591 Hammurabi - - - - - -

CIT 591 Assignment 3: - Hammurabi
- Fall 2010, David Matuszek

- -

Purpose of this assignment

- -
    -
  • To get you started using Java.
  • -
- -

General idea of the assignment

- -

Hammurabi is a very old computer game. Your job is to bring it into the - 21st century by writing it in Java.

- -

Here are the standard instructions for the game:

- -
-

Congratulations, you are the newest ruler of - ancient Samaria, elected for a ten year term of office. Your duties are to - dispense food, direct farming, and buy and sell land as needed to support - your people. Watch out for rat infestiations and the plague! Grain is the - general currency, measured in bushels. The following will help you in your - decisions:

- -
    -
  • Each person needs at least 20 bushels of - grain per year to survive
  • - -
  • Each person can farm at most 10 acres of - land
  • - -
  • It takes 2 bushels of grain to farm an acre - of land
  • - -
  • The market price for land fluctuates - yearly
  • -
- -

Rule wisely and you will be showered with - appreciation at the end of your term. Rule poorly and you will be kicked - out of office!

-
- -

Details

- -

Define a single class named Hammurabi. Use the following skeleton (but leave out the // comments):

-
package hammurabi;               // package declaration
-
-import java.util.Random;         // imports go here
-import java.util.Scanner;
-
-/**
- * The Hammurabi game.
- * @author Your name goes here
- * @author Your partner's name goes here
- */
-public class Hammurabi {         // must save in a file named Hammurabi.java
-    Random rand = new Random();  // this is an instance variable
-    Scanner scanner = new Scanner(System.in);
-
-    public static void main(String[] args) { // required in every Java program
-        new Hammurabi().playGame();
-    }
-
-    void playGame() {
-        // declare local variables here: grain, population, etc.
-        // statements go after the declations
-    }
-
-    //other methods go here
-}
-

Playing the game

-

Here is what you start the game with: -

    -
  • 100 people
  • -
  • 2800 bushels of grain in storage
  • -
  • 1000 acres of land
  • -
  • Land value is 19 bushels/acre

    -
  • -
-

Each year, print out a summary similar to the following:

-
-O great Hammurabi!
-You are in year 1 of your ten year rule.
-In the previous year 0 people starved to death.
-In the previous year 5 people entered the kingdom.
-The population is now 100.
-We harvested 3000 bushels at 3 bushels per acre.
-Rats destroyed 200 bushels, leaving 2800 bushels in storage.
-The city owns 1000 acres of land.
-Land is currently worth 19 bushels per acre.
-
- -

The above summary represents the initial state, at the beginning of - the first year--that is, when you first take office, and before you do any of - the computations below). So, for example, the previous year (under a - different ruler) must have started with 95 people; none starved, and 5 - entered the kingdom, so as you enter office you rule 100 people.

- -

Here's what your playGame method needs to do each year, for up to 10 years:

- -
-

Ask the player the following questions. These questions should be asked in this order. Do not give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below:

-
-
int askHowManyAcresToBuy(int price, int bushels)
-
Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase.
-

- int askHowManyAcresToSell(int acresOwned)
-
Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have.
- Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn.
-

- int askHowMuchGrainToFeedPeople(int bushels)
-
Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You can feed them more than they need to survive.
-

- int askHowManyAcresToPlant(int acresOwned, int population, int bushels)
-
Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year.
-
-

For each - question, do "sanity checking"; that is, test whether the answer is - possible (you have enough grain, you have enough people to do the planting - etc.), and keep asking until you get a possible value. (For example, - O Great Hammurabi, surely you jest! We have only 3415 bushels left!)

- -

Then the method needs to determine:

- -
    -
  1. If there is a plague, and how many people die from it.
  2. -
  3. How many people starved.
  4. -
  5. How many people came to the city.
  6. -
  7. How good the harvest is.
  8. -
  9. If you have a problem with rats, and how much grain they eat.
  10. -
  11. How much land costs (for deciding what to do next).
  12. -
-

These can all be local variables of your playGame method.

-

Use the following methods, in this order, to make the necessary calculations:

-
-
int plagueDeaths(int population)
-
Each year, there is a 15% chance of a horrible plague. When this - happens, half your people die. Return the number of plague deaths (possibly zero).
-

- int starvationDeaths(int population, int bushelsFedToPeople)
-
Each person needs 20 bushels of grain to survive. If you feed them - more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero).
-

- boolean uprising(int population, int howManyPeopleStarved)
-
Return true if more than - 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.)
-

- int immigrants(int population, int acresOwned, int grainInStorage)
-
Nobody will come to the city if people are starving (so don't call this method). If everyone is - well fed, compute how many people come to the city as: (20 * number of acres you have + amount of grain you have in - storage) / (100 * population) + 1.
-

- int harvest(int acres, int bushelsUsedAsSeed)
-
Choose a random integer between 1 and 6, inclusive. Each acre that was planted - with seed will yield this many bushels of grain. (Example: if you planted - 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested.
-

- int grainEatenByRats(int bushels)
-
There is a 40% chance that you will have a rat infestation. When this - happens, rats will eat somewhere between 10% and 30% of your - grain. Return the amount of grain eaten by rats (possibly zero).
-

- int newCostOfLand()
-
The price of land is random, and ranges from 17 to 23 bushels per - acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell - land.)
-
-
-

Do these computations, in this order, for each of ten years. Each - computation should be done in a separate method, and none of these methods - should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it.

- -

When the computations are finished, call a method printSummary to print the - summary for the year. This method will take several parameters.

- - -

When the game ends , use a method finalSummary to print out a final summary, and to tell the - player how good a job he/she did. I'll leave the details up to you, but the - usual evaluation is based on how many people starved, and how many acres per - person you end up with.

-

Your playGame method will be quite long, but very straightforward; it does very little but call other methods.

-

All the required arithmetic in this program should be integer. You - do not need doubles.

- -

I suggest that you first get the simplest possible version of the program - running and tested out (that is, leave out things like rats, plagues, and - immigration), then add these things one at a time to a working - program, testing as you go.

- -

Things you need to know:

- -

Random numbers

- -

To get a random number generator, you first need to import - java.util.Random (or java.util.*). Then, you can - create a random number generator with a statement such as:

- -
-

static Random rand = new Random();

-
- -

To get a new random number in the range 0..n-1, where - n is an int, call rand.nextInt(n). - To get a new random number in the range min..max, use - the expression rand.nextInt(max - min + 1) + min. You - can use the rand method in statements such as

- -
-

myNewNumber = rand.nextInt(5);
- if (rand.nextInt(100) < 15) { ... }

-
- -

To do something that happens p percent of the time, use

- -
-

if (rand.nextInt(100) < p) { ...do something... - }

-
- -

Getting input

-

To get a number from the player, add this method to your program:

-
-/**
- * Prints the given message (which should ask the user for some integral
- * quantity), and returns the number entered by the user. If the user's
- * response isn't an integer, the question is repeated until the user
- * does give a integer response.
- * 
- * @param message The request to present to the user.
- * @return The user's numeric response.
- */
- int getNumber(String message) {
-    while (true) {
-        System.out.print(message);
-        try {
-            return scanner.nextInt();
-        }
-        catch (InputMismatchException e) {
-            System.out.println("\"" + scanner.next() + "\" isn't a number!");
-        }
-    }
-}
-
- -

Here is an example of how you can use this method:

- -
-

sell = getNumber("O great Hammurabi, how many acres shall you sell?");

-
- -

Structure of the assignment:

- -
    -
  • Project name: Hammurabi
  • - -
  • Package name: hammurabi
  • - -
  • Class names and method signatures: - -
      -
    • - class Hammurabi - -
        -
      • public static void main(String[] args)
      • - -
      • Numerous other methods, as described above.
      • -
      -
    • -
    -
  • - -
- -

The above are requirements. The methods that do calculations, not input/output, will be tested by my test methods, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument names are irrelevant). You may have additional methods if you wish.

- -

Due date:

- -

Thursday, October 21, before midnight. Turn in your zipped assignment via - Blackboard. Email submissions will incur the wrath of Hammurabi (and won't be graded).

- - - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md deleted file mode 100644 index 796d85c..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md +++ /dev/null @@ -1,6 +0,0 @@ -# Notes - -from the original Dave Matuszek course of 2010. - -https://www.cis.upenn.edu/~matuszek/cit591-2010/Assignments/06-hammurabi.html - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml deleted file mode 100644 index d789654..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - 4.0.0 - - io.zipcoder - MicroLabs-Loops - 1.0-SNAPSHOT - - - - - junit - junit - 4.13.2 - - - - - - 1.8 - 1.8 - - \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore deleted file mode 100644 index a1c2a23..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore +++ /dev/null @@ -1,23 +0,0 @@ -# Compiled class file -*.class - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE deleted file mode 100644 index 22474e4..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2022 Zip Code Wilmington Core - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md deleted file mode 100644 index e4672c9..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md +++ /dev/null @@ -1,228 +0,0 @@ -# hamurabi -an ancient (in more ways than one) computer game (text) - -## General idea of the lab - -*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. - -Here are the standard instructions for the game: - -> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** -> -> * **Each person needs at least 20 bushels of grain per year to survive** -> * **Each person can farm at most 10 acres of land** -> * **It takes 2 bushels of grain to farm an acre of land** -> * **The market price for land fluctuates yearly** -> -> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** - -### Maven - -There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. - -### Details - -Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): - -```java -package hammurabi; // package declaration -import java.util.Random; // imports go here -import java.util.Scanner; - -public class Hammurabi { // must save in a file named Hammurabi.java - Random rand = new Random(); // this is an instance variable - Scanner scanner = new Scanner(System.in); - - public static void main(String\[\] args) { // required in every Java program - new Hammurabi().playGame(); - } - - void playGame() { - // declare local variables here: grain, population, etc. - // statements go after the declations - } - - //other methods go here -} -``` - -### Playing the game - -Here is what you start the game with: - -* 100 people -* 2800 bushels of grain in storage -* 1000 acres of land -* Land value is 19 bushels/acre - - -Each year, print out a summary similar to the following: - - O great Hammurabi! - You are in year 1 of your ten year rule. - In the previous year 0 people starved to death. - In the previous year 5 people entered the kingdom. - The population is now 100. - We harvested 3000 bushels at 3 bushels per acre. - Rats destroyed 200 bushels, leaving 2800 bushels in storage. - The city owns 1000 acres of land. - Land is currently worth 19 bushels per acre. - -The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. - -Here's what your `playGame` method needs to do each year, for up to 10 years: - -> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: -> -> `int askHowManyAcresToBuy(int price, int bushels)` -> -> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. -> -> ` -> int askHowManyAcresToSell(int acresOwned)` -> -> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. -> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. -> -> ` -> int askHowMuchGrainToFeedPeople(int bushels)` -> -> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. -> -> ` -> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` -> -> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. -> -> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) -> -> Then the method needs to determine: -> -> 1. If there is a plague, and how many people die from it. -> 2. How many people starved. -> 3. How many people came to the city. -> 4. How good the harvest is. -> 5. If you have a problem with rats, and how much grain they eat. -> 6. How much land costs (for deciding what to do next). -> -> These can all be local variables of your `playGame` method. -> -> Use the following methods, **in this order,** to make the necessary calculations: -> -> `int plagueDeaths(int population)` -> -> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). -> -> ` -> int starvationDeaths(int population, int bushelsFedToPeople)` -> -> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). -> -> ` -> boolean uprising(int population, int howManyPeopleStarved)` -> -> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) -> -> ` -> int immigrants(int population, int acresOwned, int grainInStorage)` -> -> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. -> -> ` -> int harvest(int acres, int bushelsUsedAsSeed)` -> -> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. -> -> ` -> int grainEatenByRats(int bushels)` -> -> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). -> -> ` -> int newCostOfLand()` -> -> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) - -Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. - -When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. - -When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. - -Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. - -All the required arithmetic in this program should be **integer**. You do not need doubles. - -### Urgent! - -> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. - -### Things you need to know: - -#### Random numbers - -To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: - -> `static Random rand = new Random();` - -To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as - -> `myNewNumber = rand.nextInt(5); -> if (rand.nextInt(100) < 15) { ... }` - -To do something that happens `p` percent of the time, use - -> `if (rand.nextInt(100) < p) { _...do something..._ }` - -#### Getting input - -To get a number from the player, add this method to your program: - -```java - /** - * Prints the given message (which should ask the user for some integral - * quantity), and returns the number entered by the user. If the user's - * response isn't an integer, the question is repeated until the user - * does give a integer response. - * - * @param message The request to present to the user. - * @return The user's numeric response. - */ - int getNumber(String message) { - while (true) { - System.out.print(message); - try { - return scanner.nextInt(); - } - catch (InputMismatchException e) { - System.out.println("\"" + scanner.next() + "\" isn't a number!"); - } - } - } -``` - -Here is an example of how you can use this method: - -> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` - -### Structure of the solution - -* Project name: `Hammurabi` -* Package name: `hammurabi` -* Class names and method signatures: - * `class Hammurabi` - * `public static void main(String[] args)` - * Numerous other methods, as described above. - -The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. - -### Yo! Test it! - -You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! - -But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. - -### Credits - -Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html deleted file mode 100644 index 78bbf24..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html +++ /dev/null @@ -1,299 +0,0 @@ - - - - - - - CIT591 Hammurabi - - - - - -

CIT 591 Assignment 3: - Hammurabi
- Fall 2010, David Matuszek

- -

Purpose of this assignment

- -
    -
  • To get you started using Java.
  • -
- -

General idea of the assignment

- -

Hammurabi is a very old computer game. Your job is to bring it into the - 21st century by writing it in Java.

- -

Here are the standard instructions for the game:

- -
-

Congratulations, you are the newest ruler of - ancient Samaria, elected for a ten year term of office. Your duties are to - dispense food, direct farming, and buy and sell land as needed to support - your people. Watch out for rat infestiations and the plague! Grain is the - general currency, measured in bushels. The following will help you in your - decisions:

- -
    -
  • Each person needs at least 20 bushels of - grain per year to survive
  • - -
  • Each person can farm at most 10 acres of - land
  • - -
  • It takes 2 bushels of grain to farm an acre - of land
  • - -
  • The market price for land fluctuates - yearly
  • -
- -

Rule wisely and you will be showered with - appreciation at the end of your term. Rule poorly and you will be kicked - out of office!

-
- -

Details

- -

Define a single class named Hammurabi. Use the following skeleton (but leave out the // comments):

-
package hammurabi;               // package declaration
-
-import java.util.Random;         // imports go here
-import java.util.Scanner;
-
-/**
- * The Hammurabi game.
- * @author Your name goes here
- * @author Your partner's name goes here
- */
-public class Hammurabi {         // must save in a file named Hammurabi.java
-    Random rand = new Random();  // this is an instance variable
-    Scanner scanner = new Scanner(System.in);
-
-    public static void main(String[] args) { // required in every Java program
-        new Hammurabi().playGame();
-    }
-
-    void playGame() {
-        // declare local variables here: grain, population, etc.
-        // statements go after the declations
-    }
-
-    //other methods go here
-}
-

Playing the game

-

Here is what you start the game with: -

    -
  • 100 people
  • -
  • 2800 bushels of grain in storage
  • -
  • 1000 acres of land
  • -
  • Land value is 19 bushels/acre

    -
  • -
-

Each year, print out a summary similar to the following:

-
-O great Hammurabi!
-You are in year 1 of your ten year rule.
-In the previous year 0 people starved to death.
-In the previous year 5 people entered the kingdom.
-The population is now 100.
-We harvested 3000 bushels at 3 bushels per acre.
-Rats destroyed 200 bushels, leaving 2800 bushels in storage.
-The city owns 1000 acres of land.
-Land is currently worth 19 bushels per acre.
-
- -

The above summary represents the initial state, at the beginning of - the first year--that is, when you first take office, and before you do any of - the computations below). So, for example, the previous year (under a - different ruler) must have started with 95 people; none starved, and 5 - entered the kingdom, so as you enter office you rule 100 people.

- -

Here's what your playGame method needs to do each year, for up to 10 years:

- -
-

Ask the player the following questions. These questions should be asked in this order. Do not give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below:

-
-
int askHowManyAcresToBuy(int price, int bushels)
-
Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase.
-

- int askHowManyAcresToSell(int acresOwned)
-
Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have.
- Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn.
-

- int askHowMuchGrainToFeedPeople(int bushels)
-
Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You can feed them more than they need to survive.
-

- int askHowManyAcresToPlant(int acresOwned, int population, int bushels)
-
Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year.
-
-

For each - question, do "sanity checking"; that is, test whether the answer is - possible (you have enough grain, you have enough people to do the planting - etc.), and keep asking until you get a possible value. (For example, - O Great Hammurabi, surely you jest! We have only 3415 bushels left!)

- -

Then the method needs to determine:

- -
    -
  1. If there is a plague, and how many people die from it.
  2. -
  3. How many people starved.
  4. -
  5. How many people came to the city.
  6. -
  7. How good the harvest is.
  8. -
  9. If you have a problem with rats, and how much grain they eat.
  10. -
  11. How much land costs (for deciding what to do next).
  12. -
-

These can all be local variables of your playGame method.

-

Use the following methods, in this order, to make the necessary calculations:

-
-
int plagueDeaths(int population)
-
Each year, there is a 15% chance of a horrible plague. When this - happens, half your people die. Return the number of plague deaths (possibly zero).
-

- int starvationDeaths(int population, int bushelsFedToPeople)
-
Each person needs 20 bushels of grain to survive. If you feed them - more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero).
-

- boolean uprising(int population, int howManyPeopleStarved)
-
Return true if more than - 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.)
-

- int immigrants(int population, int acresOwned, int grainInStorage)
-
Nobody will come to the city if people are starving (so don't call this method). If everyone is - well fed, compute how many people come to the city as: (20 * number of acres you have + amount of grain you have in - storage) / (100 * population) + 1.
-

- int harvest(int acres, int bushelsUsedAsSeed)
-
Choose a random integer between 1 and 6, inclusive. Each acre that was planted - with seed will yield this many bushels of grain. (Example: if you planted - 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested.
-

- int grainEatenByRats(int bushels)
-
There is a 40% chance that you will have a rat infestation. When this - happens, rats will eat somewhere between 10% and 30% of your - grain. Return the amount of grain eaten by rats (possibly zero).
-

- int newCostOfLand()
-
The price of land is random, and ranges from 17 to 23 bushels per - acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell - land.)
-
-
-

Do these computations, in this order, for each of ten years. Each - computation should be done in a separate method, and none of these methods - should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it.

- -

When the computations are finished, call a method printSummary to print the - summary for the year. This method will take several parameters.

- - -

When the game ends , use a method finalSummary to print out a final summary, and to tell the - player how good a job he/she did. I'll leave the details up to you, but the - usual evaluation is based on how many people starved, and how many acres per - person you end up with.

-

Your playGame method will be quite long, but very straightforward; it does very little but call other methods.

-

All the required arithmetic in this program should be integer. You - do not need doubles.

- -

I suggest that you first get the simplest possible version of the program - running and tested out (that is, leave out things like rats, plagues, and - immigration), then add these things one at a time to a working - program, testing as you go.

- -

Things you need to know:

- -

Random numbers

- -

To get a random number generator, you first need to import - java.util.Random (or java.util.*). Then, you can - create a random number generator with a statement such as:

- -
-

static Random rand = new Random();

-
- -

To get a new random number in the range 0..n-1, where - n is an int, call rand.nextInt(n). - To get a new random number in the range min..max, use - the expression rand.nextInt(max - min + 1) + min. You - can use the rand method in statements such as

- -
-

myNewNumber = rand.nextInt(5);
- if (rand.nextInt(100) < 15) { ... }

-
- -

To do something that happens p percent of the time, use

- -
-

if (rand.nextInt(100) < p) { ...do something... - }

-
- -

Getting input

-

To get a number from the player, add this method to your program:

-
-/**
- * Prints the given message (which should ask the user for some integral
- * quantity), and returns the number entered by the user. If the user's
- * response isn't an integer, the question is repeated until the user
- * does give a integer response.
- * 
- * @param message The request to present to the user.
- * @return The user's numeric response.
- */
- int getNumber(String message) {
-    while (true) {
-        System.out.print(message);
-        try {
-            return scanner.nextInt();
-        }
-        catch (InputMismatchException e) {
-            System.out.println("\"" + scanner.next() + "\" isn't a number!");
-        }
-    }
-}
-
- -

Here is an example of how you can use this method:

- -
-

sell = getNumber("O great Hammurabi, how many acres shall you sell?");

-
- -

Structure of the assignment:

- -
    -
  • Project name: Hammurabi
  • - -
  • Package name: hammurabi
  • - -
  • Class names and method signatures: - -
      -
    • - class Hammurabi - -
        -
      • public static void main(String[] args)
      • - -
      • Numerous other methods, as described above.
      • -
      -
    • -
    -
  • - -
- -

The above are requirements. The methods that do calculations, not input/output, will be tested by my test methods, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument names are irrelevant). You may have additional methods if you wish.

- -

Due date:

- -

Thursday, October 21, before midnight. Turn in your zipped assignment via - Blackboard. Email submissions will incur the wrath of Hammurabi (and won't be graded).

- - - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md deleted file mode 100644 index 796d85c..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md +++ /dev/null @@ -1,6 +0,0 @@ -# Notes - -from the original Dave Matuszek course of 2010. - -https://www.cis.upenn.edu/~matuszek/cit591-2010/Assignments/06-hammurabi.html - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml deleted file mode 100644 index d789654..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - 4.0.0 - - io.zipcoder - MicroLabs-Loops - 1.0-SNAPSHOT - - - - - junit - junit - 4.13.2 - - - - - - 1.8 - 1.8 - - \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore deleted file mode 100644 index a1c2a23..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore +++ /dev/null @@ -1,23 +0,0 @@ -# Compiled class file -*.class - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE deleted file mode 100644 index 22474e4..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2022 Zip Code Wilmington Core - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md deleted file mode 100644 index e4672c9..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md +++ /dev/null @@ -1,228 +0,0 @@ -# hamurabi -an ancient (in more ways than one) computer game (text) - -## General idea of the lab - -*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. - -Here are the standard instructions for the game: - -> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** -> -> * **Each person needs at least 20 bushels of grain per year to survive** -> * **Each person can farm at most 10 acres of land** -> * **It takes 2 bushels of grain to farm an acre of land** -> * **The market price for land fluctuates yearly** -> -> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** - -### Maven - -There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. - -### Details - -Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): - -```java -package hammurabi; // package declaration -import java.util.Random; // imports go here -import java.util.Scanner; - -public class Hammurabi { // must save in a file named Hammurabi.java - Random rand = new Random(); // this is an instance variable - Scanner scanner = new Scanner(System.in); - - public static void main(String\[\] args) { // required in every Java program - new Hammurabi().playGame(); - } - - void playGame() { - // declare local variables here: grain, population, etc. - // statements go after the declations - } - - //other methods go here -} -``` - -### Playing the game - -Here is what you start the game with: - -* 100 people -* 2800 bushels of grain in storage -* 1000 acres of land -* Land value is 19 bushels/acre - - -Each year, print out a summary similar to the following: - - O great Hammurabi! - You are in year 1 of your ten year rule. - In the previous year 0 people starved to death. - In the previous year 5 people entered the kingdom. - The population is now 100. - We harvested 3000 bushels at 3 bushels per acre. - Rats destroyed 200 bushels, leaving 2800 bushels in storage. - The city owns 1000 acres of land. - Land is currently worth 19 bushels per acre. - -The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. - -Here's what your `playGame` method needs to do each year, for up to 10 years: - -> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: -> -> `int askHowManyAcresToBuy(int price, int bushels)` -> -> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. -> -> ` -> int askHowManyAcresToSell(int acresOwned)` -> -> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. -> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. -> -> ` -> int askHowMuchGrainToFeedPeople(int bushels)` -> -> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. -> -> ` -> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` -> -> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. -> -> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) -> -> Then the method needs to determine: -> -> 1. If there is a plague, and how many people die from it. -> 2. How many people starved. -> 3. How many people came to the city. -> 4. How good the harvest is. -> 5. If you have a problem with rats, and how much grain they eat. -> 6. How much land costs (for deciding what to do next). -> -> These can all be local variables of your `playGame` method. -> -> Use the following methods, **in this order,** to make the necessary calculations: -> -> `int plagueDeaths(int population)` -> -> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). -> -> ` -> int starvationDeaths(int population, int bushelsFedToPeople)` -> -> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). -> -> ` -> boolean uprising(int population, int howManyPeopleStarved)` -> -> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) -> -> ` -> int immigrants(int population, int acresOwned, int grainInStorage)` -> -> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. -> -> ` -> int harvest(int acres, int bushelsUsedAsSeed)` -> -> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. -> -> ` -> int grainEatenByRats(int bushels)` -> -> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). -> -> ` -> int newCostOfLand()` -> -> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) - -Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. - -When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. - -When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. - -Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. - -All the required arithmetic in this program should be **integer**. You do not need doubles. - -### Urgent! - -> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. - -### Things you need to know: - -#### Random numbers - -To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: - -> `static Random rand = new Random();` - -To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as - -> `myNewNumber = rand.nextInt(5); -> if (rand.nextInt(100) < 15) { ... }` - -To do something that happens `p` percent of the time, use - -> `if (rand.nextInt(100) < p) { _...do something..._ }` - -#### Getting input - -To get a number from the player, add this method to your program: - -```java - /** - * Prints the given message (which should ask the user for some integral - * quantity), and returns the number entered by the user. If the user's - * response isn't an integer, the question is repeated until the user - * does give a integer response. - * - * @param message The request to present to the user. - * @return The user's numeric response. - */ - int getNumber(String message) { - while (true) { - System.out.print(message); - try { - return scanner.nextInt(); - } - catch (InputMismatchException e) { - System.out.println("\"" + scanner.next() + "\" isn't a number!"); - } - } - } -``` - -Here is an example of how you can use this method: - -> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` - -### Structure of the solution - -* Project name: `Hammurabi` -* Package name: `hammurabi` -* Class names and method signatures: - * `class Hammurabi` - * `public static void main(String[] args)` - * Numerous other methods, as described above. - -The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. - -### Yo! Test it! - -You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! - -But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. - -### Credits - -Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html deleted file mode 100644 index 78bbf24..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html +++ /dev/null @@ -1,299 +0,0 @@ - - - - - - - CIT591 Hammurabi - - - - - -

CIT 591 Assignment 3: - Hammurabi
- Fall 2010, David Matuszek

- -

Purpose of this assignment

- -
    -
  • To get you started using Java.
  • -
- -

General idea of the assignment

- -

Hammurabi is a very old computer game. Your job is to bring it into the - 21st century by writing it in Java.

- -

Here are the standard instructions for the game:

- -
-

Congratulations, you are the newest ruler of - ancient Samaria, elected for a ten year term of office. Your duties are to - dispense food, direct farming, and buy and sell land as needed to support - your people. Watch out for rat infestiations and the plague! Grain is the - general currency, measured in bushels. The following will help you in your - decisions:

- -
    -
  • Each person needs at least 20 bushels of - grain per year to survive
  • - -
  • Each person can farm at most 10 acres of - land
  • - -
  • It takes 2 bushels of grain to farm an acre - of land
  • - -
  • The market price for land fluctuates - yearly
  • -
- -

Rule wisely and you will be showered with - appreciation at the end of your term. Rule poorly and you will be kicked - out of office!

-
- -

Details

- -

Define a single class named Hammurabi. Use the following skeleton (but leave out the // comments):

-
package hammurabi;               // package declaration
-
-import java.util.Random;         // imports go here
-import java.util.Scanner;
-
-/**
- * The Hammurabi game.
- * @author Your name goes here
- * @author Your partner's name goes here
- */
-public class Hammurabi {         // must save in a file named Hammurabi.java
-    Random rand = new Random();  // this is an instance variable
-    Scanner scanner = new Scanner(System.in);
-
-    public static void main(String[] args) { // required in every Java program
-        new Hammurabi().playGame();
-    }
-
-    void playGame() {
-        // declare local variables here: grain, population, etc.
-        // statements go after the declations
-    }
-
-    //other methods go here
-}
-

Playing the game

-

Here is what you start the game with: -

    -
  • 100 people
  • -
  • 2800 bushels of grain in storage
  • -
  • 1000 acres of land
  • -
  • Land value is 19 bushels/acre

    -
  • -
-

Each year, print out a summary similar to the following:

-
-O great Hammurabi!
-You are in year 1 of your ten year rule.
-In the previous year 0 people starved to death.
-In the previous year 5 people entered the kingdom.
-The population is now 100.
-We harvested 3000 bushels at 3 bushels per acre.
-Rats destroyed 200 bushels, leaving 2800 bushels in storage.
-The city owns 1000 acres of land.
-Land is currently worth 19 bushels per acre.
-
- -

The above summary represents the initial state, at the beginning of - the first year--that is, when you first take office, and before you do any of - the computations below). So, for example, the previous year (under a - different ruler) must have started with 95 people; none starved, and 5 - entered the kingdom, so as you enter office you rule 100 people.

- -

Here's what your playGame method needs to do each year, for up to 10 years:

- -
-

Ask the player the following questions. These questions should be asked in this order. Do not give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below:

-
-
int askHowManyAcresToBuy(int price, int bushels)
-
Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase.
-

- int askHowManyAcresToSell(int acresOwned)
-
Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have.
- Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn.
-

- int askHowMuchGrainToFeedPeople(int bushels)
-
Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You can feed them more than they need to survive.
-

- int askHowManyAcresToPlant(int acresOwned, int population, int bushels)
-
Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year.
-
-

For each - question, do "sanity checking"; that is, test whether the answer is - possible (you have enough grain, you have enough people to do the planting - etc.), and keep asking until you get a possible value. (For example, - O Great Hammurabi, surely you jest! We have only 3415 bushels left!)

- -

Then the method needs to determine:

- -
    -
  1. If there is a plague, and how many people die from it.
  2. -
  3. How many people starved.
  4. -
  5. How many people came to the city.
  6. -
  7. How good the harvest is.
  8. -
  9. If you have a problem with rats, and how much grain they eat.
  10. -
  11. How much land costs (for deciding what to do next).
  12. -
-

These can all be local variables of your playGame method.

-

Use the following methods, in this order, to make the necessary calculations:

-
-
int plagueDeaths(int population)
-
Each year, there is a 15% chance of a horrible plague. When this - happens, half your people die. Return the number of plague deaths (possibly zero).
-

- int starvationDeaths(int population, int bushelsFedToPeople)
-
Each person needs 20 bushels of grain to survive. If you feed them - more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero).
-

- boolean uprising(int population, int howManyPeopleStarved)
-
Return true if more than - 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.)
-

- int immigrants(int population, int acresOwned, int grainInStorage)
-
Nobody will come to the city if people are starving (so don't call this method). If everyone is - well fed, compute how many people come to the city as: (20 * number of acres you have + amount of grain you have in - storage) / (100 * population) + 1.
-

- int harvest(int acres, int bushelsUsedAsSeed)
-
Choose a random integer between 1 and 6, inclusive. Each acre that was planted - with seed will yield this many bushels of grain. (Example: if you planted - 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested.
-

- int grainEatenByRats(int bushels)
-
There is a 40% chance that you will have a rat infestation. When this - happens, rats will eat somewhere between 10% and 30% of your - grain. Return the amount of grain eaten by rats (possibly zero).
-

- int newCostOfLand()
-
The price of land is random, and ranges from 17 to 23 bushels per - acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell - land.)
-
-
-

Do these computations, in this order, for each of ten years. Each - computation should be done in a separate method, and none of these methods - should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it.

- -

When the computations are finished, call a method printSummary to print the - summary for the year. This method will take several parameters.

- - -

When the game ends , use a method finalSummary to print out a final summary, and to tell the - player how good a job he/she did. I'll leave the details up to you, but the - usual evaluation is based on how many people starved, and how many acres per - person you end up with.

-

Your playGame method will be quite long, but very straightforward; it does very little but call other methods.

-

All the required arithmetic in this program should be integer. You - do not need doubles.

- -

I suggest that you first get the simplest possible version of the program - running and tested out (that is, leave out things like rats, plagues, and - immigration), then add these things one at a time to a working - program, testing as you go.

- -

Things you need to know:

- -

Random numbers

- -

To get a random number generator, you first need to import - java.util.Random (or java.util.*). Then, you can - create a random number generator with a statement such as:

- -
-

static Random rand = new Random();

-
- -

To get a new random number in the range 0..n-1, where - n is an int, call rand.nextInt(n). - To get a new random number in the range min..max, use - the expression rand.nextInt(max - min + 1) + min. You - can use the rand method in statements such as

- -
-

myNewNumber = rand.nextInt(5);
- if (rand.nextInt(100) < 15) { ... }

-
- -

To do something that happens p percent of the time, use

- -
-

if (rand.nextInt(100) < p) { ...do something... - }

-
- -

Getting input

-

To get a number from the player, add this method to your program:

-
-/**
- * Prints the given message (which should ask the user for some integral
- * quantity), and returns the number entered by the user. If the user's
- * response isn't an integer, the question is repeated until the user
- * does give a integer response.
- * 
- * @param message The request to present to the user.
- * @return The user's numeric response.
- */
- int getNumber(String message) {
-    while (true) {
-        System.out.print(message);
-        try {
-            return scanner.nextInt();
-        }
-        catch (InputMismatchException e) {
-            System.out.println("\"" + scanner.next() + "\" isn't a number!");
-        }
-    }
-}
-
- -

Here is an example of how you can use this method:

- -
-

sell = getNumber("O great Hammurabi, how many acres shall you sell?");

-
- -

Structure of the assignment:

- -
    -
  • Project name: Hammurabi
  • - -
  • Package name: hammurabi
  • - -
  • Class names and method signatures: - -
      -
    • - class Hammurabi - -
        -
      • public static void main(String[] args)
      • - -
      • Numerous other methods, as described above.
      • -
      -
    • -
    -
  • - -
- -

The above are requirements. The methods that do calculations, not input/output, will be tested by my test methods, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument names are irrelevant). You may have additional methods if you wish.

- -

Due date:

- -

Thursday, October 21, before midnight. Turn in your zipped assignment via - Blackboard. Email submissions will incur the wrath of Hammurabi (and won't be graded).

- - - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md deleted file mode 100644 index 796d85c..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md +++ /dev/null @@ -1,6 +0,0 @@ -# Notes - -from the original Dave Matuszek course of 2010. - -https://www.cis.upenn.edu/~matuszek/cit591-2010/Assignments/06-hammurabi.html - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml deleted file mode 100644 index d789654..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - 4.0.0 - - io.zipcoder - MicroLabs-Loops - 1.0-SNAPSHOT - - - - - junit - junit - 4.13.2 - - - - - - 1.8 - 1.8 - - \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore deleted file mode 100644 index a1c2a23..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore +++ /dev/null @@ -1,23 +0,0 @@ -# Compiled class file -*.class - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE deleted file mode 100644 index 22474e4..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2022 Zip Code Wilmington Core - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md deleted file mode 100644 index e4672c9..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md +++ /dev/null @@ -1,228 +0,0 @@ -# hamurabi -an ancient (in more ways than one) computer game (text) - -## General idea of the lab - -*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. - -Here are the standard instructions for the game: - -> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** -> -> * **Each person needs at least 20 bushels of grain per year to survive** -> * **Each person can farm at most 10 acres of land** -> * **It takes 2 bushels of grain to farm an acre of land** -> * **The market price for land fluctuates yearly** -> -> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** - -### Maven - -There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. - -### Details - -Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): - -```java -package hammurabi; // package declaration -import java.util.Random; // imports go here -import java.util.Scanner; - -public class Hammurabi { // must save in a file named Hammurabi.java - Random rand = new Random(); // this is an instance variable - Scanner scanner = new Scanner(System.in); - - public static void main(String\[\] args) { // required in every Java program - new Hammurabi().playGame(); - } - - void playGame() { - // declare local variables here: grain, population, etc. - // statements go after the declations - } - - //other methods go here -} -``` - -### Playing the game - -Here is what you start the game with: - -* 100 people -* 2800 bushels of grain in storage -* 1000 acres of land -* Land value is 19 bushels/acre - - -Each year, print out a summary similar to the following: - - O great Hammurabi! - You are in year 1 of your ten year rule. - In the previous year 0 people starved to death. - In the previous year 5 people entered the kingdom. - The population is now 100. - We harvested 3000 bushels at 3 bushels per acre. - Rats destroyed 200 bushels, leaving 2800 bushels in storage. - The city owns 1000 acres of land. - Land is currently worth 19 bushels per acre. - -The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. - -Here's what your `playGame` method needs to do each year, for up to 10 years: - -> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: -> -> `int askHowManyAcresToBuy(int price, int bushels)` -> -> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. -> -> ` -> int askHowManyAcresToSell(int acresOwned)` -> -> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. -> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. -> -> ` -> int askHowMuchGrainToFeedPeople(int bushels)` -> -> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. -> -> ` -> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` -> -> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. -> -> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) -> -> Then the method needs to determine: -> -> 1. If there is a plague, and how many people die from it. -> 2. How many people starved. -> 3. How many people came to the city. -> 4. How good the harvest is. -> 5. If you have a problem with rats, and how much grain they eat. -> 6. How much land costs (for deciding what to do next). -> -> These can all be local variables of your `playGame` method. -> -> Use the following methods, **in this order,** to make the necessary calculations: -> -> `int plagueDeaths(int population)` -> -> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). -> -> ` -> int starvationDeaths(int population, int bushelsFedToPeople)` -> -> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). -> -> ` -> boolean uprising(int population, int howManyPeopleStarved)` -> -> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) -> -> ` -> int immigrants(int population, int acresOwned, int grainInStorage)` -> -> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. -> -> ` -> int harvest(int acres, int bushelsUsedAsSeed)` -> -> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. -> -> ` -> int grainEatenByRats(int bushels)` -> -> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). -> -> ` -> int newCostOfLand()` -> -> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) - -Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. - -When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. - -When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. - -Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. - -All the required arithmetic in this program should be **integer**. You do not need doubles. - -### Urgent! - -> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. - -### Things you need to know: - -#### Random numbers - -To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: - -> `static Random rand = new Random();` - -To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as - -> `myNewNumber = rand.nextInt(5); -> if (rand.nextInt(100) < 15) { ... }` - -To do something that happens `p` percent of the time, use - -> `if (rand.nextInt(100) < p) { _...do something..._ }` - -#### Getting input - -To get a number from the player, add this method to your program: - -```java - /** - * Prints the given message (which should ask the user for some integral - * quantity), and returns the number entered by the user. If the user's - * response isn't an integer, the question is repeated until the user - * does give a integer response. - * - * @param message The request to present to the user. - * @return The user's numeric response. - */ - int getNumber(String message) { - while (true) { - System.out.print(message); - try { - return scanner.nextInt(); - } - catch (InputMismatchException e) { - System.out.println("\"" + scanner.next() + "\" isn't a number!"); - } - } - } -``` - -Here is an example of how you can use this method: - -> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` - -### Structure of the solution - -* Project name: `Hammurabi` -* Package name: `hammurabi` -* Class names and method signatures: - * `class Hammurabi` - * `public static void main(String[] args)` - * Numerous other methods, as described above. - -The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. - -### Yo! Test it! - -You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! - -But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. - -### Credits - -Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html deleted file mode 100644 index 78bbf24..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html +++ /dev/null @@ -1,299 +0,0 @@ - - - - - - - CIT591 Hammurabi - - - - - -

CIT 591 Assignment 3: - Hammurabi
- Fall 2010, David Matuszek

- -

Purpose of this assignment

- -
    -
  • To get you started using Java.
  • -
- -

General idea of the assignment

- -

Hammurabi is a very old computer game. Your job is to bring it into the - 21st century by writing it in Java.

- -

Here are the standard instructions for the game:

- -
-

Congratulations, you are the newest ruler of - ancient Samaria, elected for a ten year term of office. Your duties are to - dispense food, direct farming, and buy and sell land as needed to support - your people. Watch out for rat infestiations and the plague! Grain is the - general currency, measured in bushels. The following will help you in your - decisions:

- -
    -
  • Each person needs at least 20 bushels of - grain per year to survive
  • - -
  • Each person can farm at most 10 acres of - land
  • - -
  • It takes 2 bushels of grain to farm an acre - of land
  • - -
  • The market price for land fluctuates - yearly
  • -
- -

Rule wisely and you will be showered with - appreciation at the end of your term. Rule poorly and you will be kicked - out of office!

-
- -

Details

- -

Define a single class named Hammurabi. Use the following skeleton (but leave out the // comments):

-
package hammurabi;               // package declaration
-
-import java.util.Random;         // imports go here
-import java.util.Scanner;
-
-/**
- * The Hammurabi game.
- * @author Your name goes here
- * @author Your partner's name goes here
- */
-public class Hammurabi {         // must save in a file named Hammurabi.java
-    Random rand = new Random();  // this is an instance variable
-    Scanner scanner = new Scanner(System.in);
-
-    public static void main(String[] args) { // required in every Java program
-        new Hammurabi().playGame();
-    }
-
-    void playGame() {
-        // declare local variables here: grain, population, etc.
-        // statements go after the declations
-    }
-
-    //other methods go here
-}
-

Playing the game

-

Here is what you start the game with: -

    -
  • 100 people
  • -
  • 2800 bushels of grain in storage
  • -
  • 1000 acres of land
  • -
  • Land value is 19 bushels/acre

    -
  • -
-

Each year, print out a summary similar to the following:

-
-O great Hammurabi!
-You are in year 1 of your ten year rule.
-In the previous year 0 people starved to death.
-In the previous year 5 people entered the kingdom.
-The population is now 100.
-We harvested 3000 bushels at 3 bushels per acre.
-Rats destroyed 200 bushels, leaving 2800 bushels in storage.
-The city owns 1000 acres of land.
-Land is currently worth 19 bushels per acre.
-
- -

The above summary represents the initial state, at the beginning of - the first year--that is, when you first take office, and before you do any of - the computations below). So, for example, the previous year (under a - different ruler) must have started with 95 people; none starved, and 5 - entered the kingdom, so as you enter office you rule 100 people.

- -

Here's what your playGame method needs to do each year, for up to 10 years:

- -
-

Ask the player the following questions. These questions should be asked in this order. Do not give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below:

-
-
int askHowManyAcresToBuy(int price, int bushels)
-
Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase.
-

- int askHowManyAcresToSell(int acresOwned)
-
Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have.
- Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn.
-

- int askHowMuchGrainToFeedPeople(int bushels)
-
Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You can feed them more than they need to survive.
-

- int askHowManyAcresToPlant(int acresOwned, int population, int bushels)
-
Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year.
-
-

For each - question, do "sanity checking"; that is, test whether the answer is - possible (you have enough grain, you have enough people to do the planting - etc.), and keep asking until you get a possible value. (For example, - O Great Hammurabi, surely you jest! We have only 3415 bushels left!)

- -

Then the method needs to determine:

- -
    -
  1. If there is a plague, and how many people die from it.
  2. -
  3. How many people starved.
  4. -
  5. How many people came to the city.
  6. -
  7. How good the harvest is.
  8. -
  9. If you have a problem with rats, and how much grain they eat.
  10. -
  11. How much land costs (for deciding what to do next).
  12. -
-

These can all be local variables of your playGame method.

-

Use the following methods, in this order, to make the necessary calculations:

-
-
int plagueDeaths(int population)
-
Each year, there is a 15% chance of a horrible plague. When this - happens, half your people die. Return the number of plague deaths (possibly zero).
-

- int starvationDeaths(int population, int bushelsFedToPeople)
-
Each person needs 20 bushels of grain to survive. If you feed them - more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero).
-

- boolean uprising(int population, int howManyPeopleStarved)
-
Return true if more than - 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.)
-

- int immigrants(int population, int acresOwned, int grainInStorage)
-
Nobody will come to the city if people are starving (so don't call this method). If everyone is - well fed, compute how many people come to the city as: (20 * number of acres you have + amount of grain you have in - storage) / (100 * population) + 1.
-

- int harvest(int acres, int bushelsUsedAsSeed)
-
Choose a random integer between 1 and 6, inclusive. Each acre that was planted - with seed will yield this many bushels of grain. (Example: if you planted - 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested.
-

- int grainEatenByRats(int bushels)
-
There is a 40% chance that you will have a rat infestation. When this - happens, rats will eat somewhere between 10% and 30% of your - grain. Return the amount of grain eaten by rats (possibly zero).
-

- int newCostOfLand()
-
The price of land is random, and ranges from 17 to 23 bushels per - acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell - land.)
-
-
-

Do these computations, in this order, for each of ten years. Each - computation should be done in a separate method, and none of these methods - should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it.

- -

When the computations are finished, call a method printSummary to print the - summary for the year. This method will take several parameters.

- - -

When the game ends , use a method finalSummary to print out a final summary, and to tell the - player how good a job he/she did. I'll leave the details up to you, but the - usual evaluation is based on how many people starved, and how many acres per - person you end up with.

-

Your playGame method will be quite long, but very straightforward; it does very little but call other methods.

-

All the required arithmetic in this program should be integer. You - do not need doubles.

- -

I suggest that you first get the simplest possible version of the program - running and tested out (that is, leave out things like rats, plagues, and - immigration), then add these things one at a time to a working - program, testing as you go.

- -

Things you need to know:

- -

Random numbers

- -

To get a random number generator, you first need to import - java.util.Random (or java.util.*). Then, you can - create a random number generator with a statement such as:

- -
-

static Random rand = new Random();

-
- -

To get a new random number in the range 0..n-1, where - n is an int, call rand.nextInt(n). - To get a new random number in the range min..max, use - the expression rand.nextInt(max - min + 1) + min. You - can use the rand method in statements such as

- -
-

myNewNumber = rand.nextInt(5);
- if (rand.nextInt(100) < 15) { ... }

-
- -

To do something that happens p percent of the time, use

- -
-

if (rand.nextInt(100) < p) { ...do something... - }

-
- -

Getting input

-

To get a number from the player, add this method to your program:

-
-/**
- * Prints the given message (which should ask the user for some integral
- * quantity), and returns the number entered by the user. If the user's
- * response isn't an integer, the question is repeated until the user
- * does give a integer response.
- * 
- * @param message The request to present to the user.
- * @return The user's numeric response.
- */
- int getNumber(String message) {
-    while (true) {
-        System.out.print(message);
-        try {
-            return scanner.nextInt();
-        }
-        catch (InputMismatchException e) {
-            System.out.println("\"" + scanner.next() + "\" isn't a number!");
-        }
-    }
-}
-
- -

Here is an example of how you can use this method:

- -
-

sell = getNumber("O great Hammurabi, how many acres shall you sell?");

-
- -

Structure of the assignment:

- -
    -
  • Project name: Hammurabi
  • - -
  • Package name: hammurabi
  • - -
  • Class names and method signatures: - -
      -
    • - class Hammurabi - -
        -
      • public static void main(String[] args)
      • - -
      • Numerous other methods, as described above.
      • -
      -
    • -
    -
  • - -
- -

The above are requirements. The methods that do calculations, not input/output, will be tested by my test methods, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument names are irrelevant). You may have additional methods if you wish.

- -

Due date:

- -

Thursday, October 21, before midnight. Turn in your zipped assignment via - Blackboard. Email submissions will incur the wrath of Hammurabi (and won't be graded).

- - - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md deleted file mode 100644 index 796d85c..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md +++ /dev/null @@ -1,6 +0,0 @@ -# Notes - -from the original Dave Matuszek course of 2010. - -https://www.cis.upenn.edu/~matuszek/cit591-2010/Assignments/06-hammurabi.html - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml deleted file mode 100644 index d789654..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - 4.0.0 - - io.zipcoder - MicroLabs-Loops - 1.0-SNAPSHOT - - - - - junit - junit - 4.13.2 - - - - - - 1.8 - 1.8 - - \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore deleted file mode 100644 index a1c2a23..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore +++ /dev/null @@ -1,23 +0,0 @@ -# Compiled class file -*.class - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE deleted file mode 100644 index 22474e4..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2022 Zip Code Wilmington Core - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md deleted file mode 100644 index e4672c9..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md +++ /dev/null @@ -1,228 +0,0 @@ -# hamurabi -an ancient (in more ways than one) computer game (text) - -## General idea of the lab - -*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. - -Here are the standard instructions for the game: - -> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** -> -> * **Each person needs at least 20 bushels of grain per year to survive** -> * **Each person can farm at most 10 acres of land** -> * **It takes 2 bushels of grain to farm an acre of land** -> * **The market price for land fluctuates yearly** -> -> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** - -### Maven - -There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. - -### Details - -Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): - -```java -package hammurabi; // package declaration -import java.util.Random; // imports go here -import java.util.Scanner; - -public class Hammurabi { // must save in a file named Hammurabi.java - Random rand = new Random(); // this is an instance variable - Scanner scanner = new Scanner(System.in); - - public static void main(String\[\] args) { // required in every Java program - new Hammurabi().playGame(); - } - - void playGame() { - // declare local variables here: grain, population, etc. - // statements go after the declations - } - - //other methods go here -} -``` - -### Playing the game - -Here is what you start the game with: - -* 100 people -* 2800 bushels of grain in storage -* 1000 acres of land -* Land value is 19 bushels/acre - - -Each year, print out a summary similar to the following: - - O great Hammurabi! - You are in year 1 of your ten year rule. - In the previous year 0 people starved to death. - In the previous year 5 people entered the kingdom. - The population is now 100. - We harvested 3000 bushels at 3 bushels per acre. - Rats destroyed 200 bushels, leaving 2800 bushels in storage. - The city owns 1000 acres of land. - Land is currently worth 19 bushels per acre. - -The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. - -Here's what your `playGame` method needs to do each year, for up to 10 years: - -> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: -> -> `int askHowManyAcresToBuy(int price, int bushels)` -> -> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. -> -> ` -> int askHowManyAcresToSell(int acresOwned)` -> -> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. -> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. -> -> ` -> int askHowMuchGrainToFeedPeople(int bushels)` -> -> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. -> -> ` -> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` -> -> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. -> -> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) -> -> Then the method needs to determine: -> -> 1. If there is a plague, and how many people die from it. -> 2. How many people starved. -> 3. How many people came to the city. -> 4. How good the harvest is. -> 5. If you have a problem with rats, and how much grain they eat. -> 6. How much land costs (for deciding what to do next). -> -> These can all be local variables of your `playGame` method. -> -> Use the following methods, **in this order,** to make the necessary calculations: -> -> `int plagueDeaths(int population)` -> -> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). -> -> ` -> int starvationDeaths(int population, int bushelsFedToPeople)` -> -> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). -> -> ` -> boolean uprising(int population, int howManyPeopleStarved)` -> -> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) -> -> ` -> int immigrants(int population, int acresOwned, int grainInStorage)` -> -> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. -> -> ` -> int harvest(int acres, int bushelsUsedAsSeed)` -> -> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. -> -> ` -> int grainEatenByRats(int bushels)` -> -> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). -> -> ` -> int newCostOfLand()` -> -> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) - -Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. - -When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. - -When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. - -Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. - -All the required arithmetic in this program should be **integer**. You do not need doubles. - -### Urgent! - -> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. - -### Things you need to know: - -#### Random numbers - -To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: - -> `static Random rand = new Random();` - -To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as - -> `myNewNumber = rand.nextInt(5); -> if (rand.nextInt(100) < 15) { ... }` - -To do something that happens `p` percent of the time, use - -> `if (rand.nextInt(100) < p) { _...do something..._ }` - -#### Getting input - -To get a number from the player, add this method to your program: - -```java - /** - * Prints the given message (which should ask the user for some integral - * quantity), and returns the number entered by the user. If the user's - * response isn't an integer, the question is repeated until the user - * does give a integer response. - * - * @param message The request to present to the user. - * @return The user's numeric response. - */ - int getNumber(String message) { - while (true) { - System.out.print(message); - try { - return scanner.nextInt(); - } - catch (InputMismatchException e) { - System.out.println("\"" + scanner.next() + "\" isn't a number!"); - } - } - } -``` - -Here is an example of how you can use this method: - -> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` - -### Structure of the solution - -* Project name: `Hammurabi` -* Package name: `hammurabi` -* Class names and method signatures: - * `class Hammurabi` - * `public static void main(String[] args)` - * Numerous other methods, as described above. - -The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. - -### Yo! Test it! - -You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! - -But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. - -### Credits - -Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html deleted file mode 100644 index 78bbf24..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html +++ /dev/null @@ -1,299 +0,0 @@ - - - - - - - CIT591 Hammurabi - - - - - -

CIT 591 Assignment 3: - Hammurabi
- Fall 2010, David Matuszek

- -

Purpose of this assignment

- -
    -
  • To get you started using Java.
  • -
- -

General idea of the assignment

- -

Hammurabi is a very old computer game. Your job is to bring it into the - 21st century by writing it in Java.

- -

Here are the standard instructions for the game:

- -
-

Congratulations, you are the newest ruler of - ancient Samaria, elected for a ten year term of office. Your duties are to - dispense food, direct farming, and buy and sell land as needed to support - your people. Watch out for rat infestiations and the plague! Grain is the - general currency, measured in bushels. The following will help you in your - decisions:

- -
    -
  • Each person needs at least 20 bushels of - grain per year to survive
  • - -
  • Each person can farm at most 10 acres of - land
  • - -
  • It takes 2 bushels of grain to farm an acre - of land
  • - -
  • The market price for land fluctuates - yearly
  • -
- -

Rule wisely and you will be showered with - appreciation at the end of your term. Rule poorly and you will be kicked - out of office!

-
- -

Details

- -

Define a single class named Hammurabi. Use the following skeleton (but leave out the // comments):

-
package hammurabi;               // package declaration
-
-import java.util.Random;         // imports go here
-import java.util.Scanner;
-
-/**
- * The Hammurabi game.
- * @author Your name goes here
- * @author Your partner's name goes here
- */
-public class Hammurabi {         // must save in a file named Hammurabi.java
-    Random rand = new Random();  // this is an instance variable
-    Scanner scanner = new Scanner(System.in);
-
-    public static void main(String[] args) { // required in every Java program
-        new Hammurabi().playGame();
-    }
-
-    void playGame() {
-        // declare local variables here: grain, population, etc.
-        // statements go after the declations
-    }
-
-    //other methods go here
-}
-

Playing the game

-

Here is what you start the game with: -

    -
  • 100 people
  • -
  • 2800 bushels of grain in storage
  • -
  • 1000 acres of land
  • -
  • Land value is 19 bushels/acre

    -
  • -
-

Each year, print out a summary similar to the following:

-
-O great Hammurabi!
-You are in year 1 of your ten year rule.
-In the previous year 0 people starved to death.
-In the previous year 5 people entered the kingdom.
-The population is now 100.
-We harvested 3000 bushels at 3 bushels per acre.
-Rats destroyed 200 bushels, leaving 2800 bushels in storage.
-The city owns 1000 acres of land.
-Land is currently worth 19 bushels per acre.
-
- -

The above summary represents the initial state, at the beginning of - the first year--that is, when you first take office, and before you do any of - the computations below). So, for example, the previous year (under a - different ruler) must have started with 95 people; none starved, and 5 - entered the kingdom, so as you enter office you rule 100 people.

- -

Here's what your playGame method needs to do each year, for up to 10 years:

- -
-

Ask the player the following questions. These questions should be asked in this order. Do not give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below:

-
-
int askHowManyAcresToBuy(int price, int bushels)
-
Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase.
-

- int askHowManyAcresToSell(int acresOwned)
-
Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have.
- Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn.
-

- int askHowMuchGrainToFeedPeople(int bushels)
-
Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You can feed them more than they need to survive.
-

- int askHowManyAcresToPlant(int acresOwned, int population, int bushels)
-
Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year.
-
-

For each - question, do "sanity checking"; that is, test whether the answer is - possible (you have enough grain, you have enough people to do the planting - etc.), and keep asking until you get a possible value. (For example, - O Great Hammurabi, surely you jest! We have only 3415 bushels left!)

- -

Then the method needs to determine:

- -
    -
  1. If there is a plague, and how many people die from it.
  2. -
  3. How many people starved.
  4. -
  5. How many people came to the city.
  6. -
  7. How good the harvest is.
  8. -
  9. If you have a problem with rats, and how much grain they eat.
  10. -
  11. How much land costs (for deciding what to do next).
  12. -
-

These can all be local variables of your playGame method.

-

Use the following methods, in this order, to make the necessary calculations:

-
-
int plagueDeaths(int population)
-
Each year, there is a 15% chance of a horrible plague. When this - happens, half your people die. Return the number of plague deaths (possibly zero).
-

- int starvationDeaths(int population, int bushelsFedToPeople)
-
Each person needs 20 bushels of grain to survive. If you feed them - more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero).
-

- boolean uprising(int population, int howManyPeopleStarved)
-
Return true if more than - 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.)
-

- int immigrants(int population, int acresOwned, int grainInStorage)
-
Nobody will come to the city if people are starving (so don't call this method). If everyone is - well fed, compute how many people come to the city as: (20 * number of acres you have + amount of grain you have in - storage) / (100 * population) + 1.
-

- int harvest(int acres, int bushelsUsedAsSeed)
-
Choose a random integer between 1 and 6, inclusive. Each acre that was planted - with seed will yield this many bushels of grain. (Example: if you planted - 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested.
-

- int grainEatenByRats(int bushels)
-
There is a 40% chance that you will have a rat infestation. When this - happens, rats will eat somewhere between 10% and 30% of your - grain. Return the amount of grain eaten by rats (possibly zero).
-

- int newCostOfLand()
-
The price of land is random, and ranges from 17 to 23 bushels per - acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell - land.)
-
-
-

Do these computations, in this order, for each of ten years. Each - computation should be done in a separate method, and none of these methods - should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it.

- -

When the computations are finished, call a method printSummary to print the - summary for the year. This method will take several parameters.

- - -

When the game ends , use a method finalSummary to print out a final summary, and to tell the - player how good a job he/she did. I'll leave the details up to you, but the - usual evaluation is based on how many people starved, and how many acres per - person you end up with.

-

Your playGame method will be quite long, but very straightforward; it does very little but call other methods.

-

All the required arithmetic in this program should be integer. You - do not need doubles.

- -

I suggest that you first get the simplest possible version of the program - running and tested out (that is, leave out things like rats, plagues, and - immigration), then add these things one at a time to a working - program, testing as you go.

- -

Things you need to know:

- -

Random numbers

- -

To get a random number generator, you first need to import - java.util.Random (or java.util.*). Then, you can - create a random number generator with a statement such as:

- -
-

static Random rand = new Random();

-
- -

To get a new random number in the range 0..n-1, where - n is an int, call rand.nextInt(n). - To get a new random number in the range min..max, use - the expression rand.nextInt(max - min + 1) + min. You - can use the rand method in statements such as

- -
-

myNewNumber = rand.nextInt(5);
- if (rand.nextInt(100) < 15) { ... }

-
- -

To do something that happens p percent of the time, use

- -
-

if (rand.nextInt(100) < p) { ...do something... - }

-
- -

Getting input

-

To get a number from the player, add this method to your program:

-
-/**
- * Prints the given message (which should ask the user for some integral
- * quantity), and returns the number entered by the user. If the user's
- * response isn't an integer, the question is repeated until the user
- * does give a integer response.
- * 
- * @param message The request to present to the user.
- * @return The user's numeric response.
- */
- int getNumber(String message) {
-    while (true) {
-        System.out.print(message);
-        try {
-            return scanner.nextInt();
-        }
-        catch (InputMismatchException e) {
-            System.out.println("\"" + scanner.next() + "\" isn't a number!");
-        }
-    }
-}
-
- -

Here is an example of how you can use this method:

- -
-

sell = getNumber("O great Hammurabi, how many acres shall you sell?");

-
- -

Structure of the assignment:

- -
    -
  • Project name: Hammurabi
  • - -
  • Package name: hammurabi
  • - -
  • Class names and method signatures: - -
      -
    • - class Hammurabi - -
        -
      • public static void main(String[] args)
      • - -
      • Numerous other methods, as described above.
      • -
      -
    • -
    -
  • - -
- -

The above are requirements. The methods that do calculations, not input/output, will be tested by my test methods, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument names are irrelevant). You may have additional methods if you wish.

- -

Due date:

- -

Thursday, October 21, before midnight. Turn in your zipped assignment via - Blackboard. Email submissions will incur the wrath of Hammurabi (and won't be graded).

- - - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md deleted file mode 100644 index 796d85c..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md +++ /dev/null @@ -1,6 +0,0 @@ -# Notes - -from the original Dave Matuszek course of 2010. - -https://www.cis.upenn.edu/~matuszek/cit591-2010/Assignments/06-hammurabi.html - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml deleted file mode 100644 index d789654..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - 4.0.0 - - io.zipcoder - MicroLabs-Loops - 1.0-SNAPSHOT - - - - - junit - junit - 4.13.2 - - - - - - 1.8 - 1.8 - - \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore deleted file mode 100644 index a1c2a23..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore +++ /dev/null @@ -1,23 +0,0 @@ -# Compiled class file -*.class - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE deleted file mode 100644 index 22474e4..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2022 Zip Code Wilmington Core - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md deleted file mode 100644 index e4672c9..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md +++ /dev/null @@ -1,228 +0,0 @@ -# hamurabi -an ancient (in more ways than one) computer game (text) - -## General idea of the lab - -*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. - -Here are the standard instructions for the game: - -> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** -> -> * **Each person needs at least 20 bushels of grain per year to survive** -> * **Each person can farm at most 10 acres of land** -> * **It takes 2 bushels of grain to farm an acre of land** -> * **The market price for land fluctuates yearly** -> -> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** - -### Maven - -There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. - -### Details - -Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): - -```java -package hammurabi; // package declaration -import java.util.Random; // imports go here -import java.util.Scanner; - -public class Hammurabi { // must save in a file named Hammurabi.java - Random rand = new Random(); // this is an instance variable - Scanner scanner = new Scanner(System.in); - - public static void main(String\[\] args) { // required in every Java program - new Hammurabi().playGame(); - } - - void playGame() { - // declare local variables here: grain, population, etc. - // statements go after the declations - } - - //other methods go here -} -``` - -### Playing the game - -Here is what you start the game with: - -* 100 people -* 2800 bushels of grain in storage -* 1000 acres of land -* Land value is 19 bushels/acre - - -Each year, print out a summary similar to the following: - - O great Hammurabi! - You are in year 1 of your ten year rule. - In the previous year 0 people starved to death. - In the previous year 5 people entered the kingdom. - The population is now 100. - We harvested 3000 bushels at 3 bushels per acre. - Rats destroyed 200 bushels, leaving 2800 bushels in storage. - The city owns 1000 acres of land. - Land is currently worth 19 bushels per acre. - -The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. - -Here's what your `playGame` method needs to do each year, for up to 10 years: - -> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: -> -> `int askHowManyAcresToBuy(int price, int bushels)` -> -> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. -> -> ` -> int askHowManyAcresToSell(int acresOwned)` -> -> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. -> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. -> -> ` -> int askHowMuchGrainToFeedPeople(int bushels)` -> -> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. -> -> ` -> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` -> -> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. -> -> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) -> -> Then the method needs to determine: -> -> 1. If there is a plague, and how many people die from it. -> 2. How many people starved. -> 3. How many people came to the city. -> 4. How good the harvest is. -> 5. If you have a problem with rats, and how much grain they eat. -> 6. How much land costs (for deciding what to do next). -> -> These can all be local variables of your `playGame` method. -> -> Use the following methods, **in this order,** to make the necessary calculations: -> -> `int plagueDeaths(int population)` -> -> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). -> -> ` -> int starvationDeaths(int population, int bushelsFedToPeople)` -> -> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). -> -> ` -> boolean uprising(int population, int howManyPeopleStarved)` -> -> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) -> -> ` -> int immigrants(int population, int acresOwned, int grainInStorage)` -> -> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. -> -> ` -> int harvest(int acres, int bushelsUsedAsSeed)` -> -> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. -> -> ` -> int grainEatenByRats(int bushels)` -> -> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). -> -> ` -> int newCostOfLand()` -> -> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) - -Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. - -When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. - -When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. - -Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. - -All the required arithmetic in this program should be **integer**. You do not need doubles. - -### Urgent! - -> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. - -### Things you need to know: - -#### Random numbers - -To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: - -> `static Random rand = new Random();` - -To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as - -> `myNewNumber = rand.nextInt(5); -> if (rand.nextInt(100) < 15) { ... }` - -To do something that happens `p` percent of the time, use - -> `if (rand.nextInt(100) < p) { _...do something..._ }` - -#### Getting input - -To get a number from the player, add this method to your program: - -```java - /** - * Prints the given message (which should ask the user for some integral - * quantity), and returns the number entered by the user. If the user's - * response isn't an integer, the question is repeated until the user - * does give a integer response. - * - * @param message The request to present to the user. - * @return The user's numeric response. - */ - int getNumber(String message) { - while (true) { - System.out.print(message); - try { - return scanner.nextInt(); - } - catch (InputMismatchException e) { - System.out.println("\"" + scanner.next() + "\" isn't a number!"); - } - } - } -``` - -Here is an example of how you can use this method: - -> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` - -### Structure of the solution - -* Project name: `Hammurabi` -* Package name: `hammurabi` -* Class names and method signatures: - * `class Hammurabi` - * `public static void main(String[] args)` - * Numerous other methods, as described above. - -The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. - -### Yo! Test it! - -You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! - -But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. - -### Credits - -Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html deleted file mode 100644 index 78bbf24..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html +++ /dev/null @@ -1,299 +0,0 @@ - - - - - - - CIT591 Hammurabi - - - - - -

CIT 591 Assignment 3: - Hammurabi
- Fall 2010, David Matuszek

- -

Purpose of this assignment

- -
    -
  • To get you started using Java.
  • -
- -

General idea of the assignment

- -

Hammurabi is a very old computer game. Your job is to bring it into the - 21st century by writing it in Java.

- -

Here are the standard instructions for the game:

- -
-

Congratulations, you are the newest ruler of - ancient Samaria, elected for a ten year term of office. Your duties are to - dispense food, direct farming, and buy and sell land as needed to support - your people. Watch out for rat infestiations and the plague! Grain is the - general currency, measured in bushels. The following will help you in your - decisions:

- -
    -
  • Each person needs at least 20 bushels of - grain per year to survive
  • - -
  • Each person can farm at most 10 acres of - land
  • - -
  • It takes 2 bushels of grain to farm an acre - of land
  • - -
  • The market price for land fluctuates - yearly
  • -
- -

Rule wisely and you will be showered with - appreciation at the end of your term. Rule poorly and you will be kicked - out of office!

-
- -

Details

- -

Define a single class named Hammurabi. Use the following skeleton (but leave out the // comments):

-
package hammurabi;               // package declaration
-
-import java.util.Random;         // imports go here
-import java.util.Scanner;
-
-/**
- * The Hammurabi game.
- * @author Your name goes here
- * @author Your partner's name goes here
- */
-public class Hammurabi {         // must save in a file named Hammurabi.java
-    Random rand = new Random();  // this is an instance variable
-    Scanner scanner = new Scanner(System.in);
-
-    public static void main(String[] args) { // required in every Java program
-        new Hammurabi().playGame();
-    }
-
-    void playGame() {
-        // declare local variables here: grain, population, etc.
-        // statements go after the declations
-    }
-
-    //other methods go here
-}
-

Playing the game

-

Here is what you start the game with: -

    -
  • 100 people
  • -
  • 2800 bushels of grain in storage
  • -
  • 1000 acres of land
  • -
  • Land value is 19 bushels/acre

    -
  • -
-

Each year, print out a summary similar to the following:

-
-O great Hammurabi!
-You are in year 1 of your ten year rule.
-In the previous year 0 people starved to death.
-In the previous year 5 people entered the kingdom.
-The population is now 100.
-We harvested 3000 bushels at 3 bushels per acre.
-Rats destroyed 200 bushels, leaving 2800 bushels in storage.
-The city owns 1000 acres of land.
-Land is currently worth 19 bushels per acre.
-
- -

The above summary represents the initial state, at the beginning of - the first year--that is, when you first take office, and before you do any of - the computations below). So, for example, the previous year (under a - different ruler) must have started with 95 people; none starved, and 5 - entered the kingdom, so as you enter office you rule 100 people.

- -

Here's what your playGame method needs to do each year, for up to 10 years:

- -
-

Ask the player the following questions. These questions should be asked in this order. Do not give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below:

-
-
int askHowManyAcresToBuy(int price, int bushels)
-
Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase.
-

- int askHowManyAcresToSell(int acresOwned)
-
Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have.
- Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn.
-

- int askHowMuchGrainToFeedPeople(int bushels)
-
Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You can feed them more than they need to survive.
-

- int askHowManyAcresToPlant(int acresOwned, int population, int bushels)
-
Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year.
-
-

For each - question, do "sanity checking"; that is, test whether the answer is - possible (you have enough grain, you have enough people to do the planting - etc.), and keep asking until you get a possible value. (For example, - O Great Hammurabi, surely you jest! We have only 3415 bushels left!)

- -

Then the method needs to determine:

- -
    -
  1. If there is a plague, and how many people die from it.
  2. -
  3. How many people starved.
  4. -
  5. How many people came to the city.
  6. -
  7. How good the harvest is.
  8. -
  9. If you have a problem with rats, and how much grain they eat.
  10. -
  11. How much land costs (for deciding what to do next).
  12. -
-

These can all be local variables of your playGame method.

-

Use the following methods, in this order, to make the necessary calculations:

-
-
int plagueDeaths(int population)
-
Each year, there is a 15% chance of a horrible plague. When this - happens, half your people die. Return the number of plague deaths (possibly zero).
-

- int starvationDeaths(int population, int bushelsFedToPeople)
-
Each person needs 20 bushels of grain to survive. If you feed them - more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero).
-

- boolean uprising(int population, int howManyPeopleStarved)
-
Return true if more than - 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.)
-

- int immigrants(int population, int acresOwned, int grainInStorage)
-
Nobody will come to the city if people are starving (so don't call this method). If everyone is - well fed, compute how many people come to the city as: (20 * number of acres you have + amount of grain you have in - storage) / (100 * population) + 1.
-

- int harvest(int acres, int bushelsUsedAsSeed)
-
Choose a random integer between 1 and 6, inclusive. Each acre that was planted - with seed will yield this many bushels of grain. (Example: if you planted - 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested.
-

- int grainEatenByRats(int bushels)
-
There is a 40% chance that you will have a rat infestation. When this - happens, rats will eat somewhere between 10% and 30% of your - grain. Return the amount of grain eaten by rats (possibly zero).
-

- int newCostOfLand()
-
The price of land is random, and ranges from 17 to 23 bushels per - acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell - land.)
-
-
-

Do these computations, in this order, for each of ten years. Each - computation should be done in a separate method, and none of these methods - should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it.

- -

When the computations are finished, call a method printSummary to print the - summary for the year. This method will take several parameters.

- - -

When the game ends , use a method finalSummary to print out a final summary, and to tell the - player how good a job he/she did. I'll leave the details up to you, but the - usual evaluation is based on how many people starved, and how many acres per - person you end up with.

-

Your playGame method will be quite long, but very straightforward; it does very little but call other methods.

-

All the required arithmetic in this program should be integer. You - do not need doubles.

- -

I suggest that you first get the simplest possible version of the program - running and tested out (that is, leave out things like rats, plagues, and - immigration), then add these things one at a time to a working - program, testing as you go.

- -

Things you need to know:

- -

Random numbers

- -

To get a random number generator, you first need to import - java.util.Random (or java.util.*). Then, you can - create a random number generator with a statement such as:

- -
-

static Random rand = new Random();

-
- -

To get a new random number in the range 0..n-1, where - n is an int, call rand.nextInt(n). - To get a new random number in the range min..max, use - the expression rand.nextInt(max - min + 1) + min. You - can use the rand method in statements such as

- -
-

myNewNumber = rand.nextInt(5);
- if (rand.nextInt(100) < 15) { ... }

-
- -

To do something that happens p percent of the time, use

- -
-

if (rand.nextInt(100) < p) { ...do something... - }

-
- -

Getting input

-

To get a number from the player, add this method to your program:

-
-/**
- * Prints the given message (which should ask the user for some integral
- * quantity), and returns the number entered by the user. If the user's
- * response isn't an integer, the question is repeated until the user
- * does give a integer response.
- * 
- * @param message The request to present to the user.
- * @return The user's numeric response.
- */
- int getNumber(String message) {
-    while (true) {
-        System.out.print(message);
-        try {
-            return scanner.nextInt();
-        }
-        catch (InputMismatchException e) {
-            System.out.println("\"" + scanner.next() + "\" isn't a number!");
-        }
-    }
-}
-
- -

Here is an example of how you can use this method:

- -
-

sell = getNumber("O great Hammurabi, how many acres shall you sell?");

-
- -

Structure of the assignment:

- -
    -
  • Project name: Hammurabi
  • - -
  • Package name: hammurabi
  • - -
  • Class names and method signatures: - -
      -
    • - class Hammurabi - -
        -
      • public static void main(String[] args)
      • - -
      • Numerous other methods, as described above.
      • -
      -
    • -
    -
  • - -
- -

The above are requirements. The methods that do calculations, not input/output, will be tested by my test methods, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument names are irrelevant). You may have additional methods if you wish.

- -

Due date:

- -

Thursday, October 21, before midnight. Turn in your zipped assignment via - Blackboard. Email submissions will incur the wrath of Hammurabi (and won't be graded).

- - - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md deleted file mode 100644 index 796d85c..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md +++ /dev/null @@ -1,6 +0,0 @@ -# Notes - -from the original Dave Matuszek course of 2010. - -https://www.cis.upenn.edu/~matuszek/cit591-2010/Assignments/06-hammurabi.html - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml deleted file mode 100644 index d789654..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - 4.0.0 - - io.zipcoder - MicroLabs-Loops - 1.0-SNAPSHOT - - - - - junit - junit - 4.13.2 - - - - - - 1.8 - 1.8 - - \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore deleted file mode 100644 index a1c2a23..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore +++ /dev/null @@ -1,23 +0,0 @@ -# Compiled class file -*.class - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE deleted file mode 100644 index 22474e4..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2022 Zip Code Wilmington Core - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md deleted file mode 100644 index e4672c9..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md +++ /dev/null @@ -1,228 +0,0 @@ -# hamurabi -an ancient (in more ways than one) computer game (text) - -## General idea of the lab - -*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. - -Here are the standard instructions for the game: - -> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** -> -> * **Each person needs at least 20 bushels of grain per year to survive** -> * **Each person can farm at most 10 acres of land** -> * **It takes 2 bushels of grain to farm an acre of land** -> * **The market price for land fluctuates yearly** -> -> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** - -### Maven - -There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. - -### Details - -Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): - -```java -package hammurabi; // package declaration -import java.util.Random; // imports go here -import java.util.Scanner; - -public class Hammurabi { // must save in a file named Hammurabi.java - Random rand = new Random(); // this is an instance variable - Scanner scanner = new Scanner(System.in); - - public static void main(String\[\] args) { // required in every Java program - new Hammurabi().playGame(); - } - - void playGame() { - // declare local variables here: grain, population, etc. - // statements go after the declations - } - - //other methods go here -} -``` - -### Playing the game - -Here is what you start the game with: - -* 100 people -* 2800 bushels of grain in storage -* 1000 acres of land -* Land value is 19 bushels/acre - - -Each year, print out a summary similar to the following: - - O great Hammurabi! - You are in year 1 of your ten year rule. - In the previous year 0 people starved to death. - In the previous year 5 people entered the kingdom. - The population is now 100. - We harvested 3000 bushels at 3 bushels per acre. - Rats destroyed 200 bushels, leaving 2800 bushels in storage. - The city owns 1000 acres of land. - Land is currently worth 19 bushels per acre. - -The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. - -Here's what your `playGame` method needs to do each year, for up to 10 years: - -> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: -> -> `int askHowManyAcresToBuy(int price, int bushels)` -> -> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. -> -> ` -> int askHowManyAcresToSell(int acresOwned)` -> -> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. -> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. -> -> ` -> int askHowMuchGrainToFeedPeople(int bushels)` -> -> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. -> -> ` -> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` -> -> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. -> -> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) -> -> Then the method needs to determine: -> -> 1. If there is a plague, and how many people die from it. -> 2. How many people starved. -> 3. How many people came to the city. -> 4. How good the harvest is. -> 5. If you have a problem with rats, and how much grain they eat. -> 6. How much land costs (for deciding what to do next). -> -> These can all be local variables of your `playGame` method. -> -> Use the following methods, **in this order,** to make the necessary calculations: -> -> `int plagueDeaths(int population)` -> -> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). -> -> ` -> int starvationDeaths(int population, int bushelsFedToPeople)` -> -> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). -> -> ` -> boolean uprising(int population, int howManyPeopleStarved)` -> -> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) -> -> ` -> int immigrants(int population, int acresOwned, int grainInStorage)` -> -> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. -> -> ` -> int harvest(int acres, int bushelsUsedAsSeed)` -> -> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. -> -> ` -> int grainEatenByRats(int bushels)` -> -> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). -> -> ` -> int newCostOfLand()` -> -> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) - -Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. - -When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. - -When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. - -Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. - -All the required arithmetic in this program should be **integer**. You do not need doubles. - -### Urgent! - -> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. - -### Things you need to know: - -#### Random numbers - -To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: - -> `static Random rand = new Random();` - -To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as - -> `myNewNumber = rand.nextInt(5); -> if (rand.nextInt(100) < 15) { ... }` - -To do something that happens `p` percent of the time, use - -> `if (rand.nextInt(100) < p) { _...do something..._ }` - -#### Getting input - -To get a number from the player, add this method to your program: - -```java - /** - * Prints the given message (which should ask the user for some integral - * quantity), and returns the number entered by the user. If the user's - * response isn't an integer, the question is repeated until the user - * does give a integer response. - * - * @param message The request to present to the user. - * @return The user's numeric response. - */ - int getNumber(String message) { - while (true) { - System.out.print(message); - try { - return scanner.nextInt(); - } - catch (InputMismatchException e) { - System.out.println("\"" + scanner.next() + "\" isn't a number!"); - } - } - } -``` - -Here is an example of how you can use this method: - -> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` - -### Structure of the solution - -* Project name: `Hammurabi` -* Package name: `hammurabi` -* Class names and method signatures: - * `class Hammurabi` - * `public static void main(String[] args)` - * Numerous other methods, as described above. - -The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. - -### Yo! Test it! - -You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! - -But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. - -### Credits - -Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html deleted file mode 100644 index 78bbf24..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html +++ /dev/null @@ -1,299 +0,0 @@ - - - - - - - CIT591 Hammurabi - - - - - -

CIT 591 Assignment 3: - Hammurabi
- Fall 2010, David Matuszek

- -

Purpose of this assignment

- -
    -
  • To get you started using Java.
  • -
- -

General idea of the assignment

- -

Hammurabi is a very old computer game. Your job is to bring it into the - 21st century by writing it in Java.

- -

Here are the standard instructions for the game:

- -
-

Congratulations, you are the newest ruler of - ancient Samaria, elected for a ten year term of office. Your duties are to - dispense food, direct farming, and buy and sell land as needed to support - your people. Watch out for rat infestiations and the plague! Grain is the - general currency, measured in bushels. The following will help you in your - decisions:

- -
    -
  • Each person needs at least 20 bushels of - grain per year to survive
  • - -
  • Each person can farm at most 10 acres of - land
  • - -
  • It takes 2 bushels of grain to farm an acre - of land
  • - -
  • The market price for land fluctuates - yearly
  • -
- -

Rule wisely and you will be showered with - appreciation at the end of your term. Rule poorly and you will be kicked - out of office!

-
- -

Details

- -

Define a single class named Hammurabi. Use the following skeleton (but leave out the // comments):

-
package hammurabi;               // package declaration
-
-import java.util.Random;         // imports go here
-import java.util.Scanner;
-
-/**
- * The Hammurabi game.
- * @author Your name goes here
- * @author Your partner's name goes here
- */
-public class Hammurabi {         // must save in a file named Hammurabi.java
-    Random rand = new Random();  // this is an instance variable
-    Scanner scanner = new Scanner(System.in);
-
-    public static void main(String[] args) { // required in every Java program
-        new Hammurabi().playGame();
-    }
-
-    void playGame() {
-        // declare local variables here: grain, population, etc.
-        // statements go after the declations
-    }
-
-    //other methods go here
-}
-

Playing the game

-

Here is what you start the game with: -

    -
  • 100 people
  • -
  • 2800 bushels of grain in storage
  • -
  • 1000 acres of land
  • -
  • Land value is 19 bushels/acre

    -
  • -
-

Each year, print out a summary similar to the following:

-
-O great Hammurabi!
-You are in year 1 of your ten year rule.
-In the previous year 0 people starved to death.
-In the previous year 5 people entered the kingdom.
-The population is now 100.
-We harvested 3000 bushels at 3 bushels per acre.
-Rats destroyed 200 bushels, leaving 2800 bushels in storage.
-The city owns 1000 acres of land.
-Land is currently worth 19 bushels per acre.
-
- -

The above summary represents the initial state, at the beginning of - the first year--that is, when you first take office, and before you do any of - the computations below). So, for example, the previous year (under a - different ruler) must have started with 95 people; none starved, and 5 - entered the kingdom, so as you enter office you rule 100 people.

- -

Here's what your playGame method needs to do each year, for up to 10 years:

- -
-

Ask the player the following questions. These questions should be asked in this order. Do not give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below:

-
-
int askHowManyAcresToBuy(int price, int bushels)
-
Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase.
-

- int askHowManyAcresToSell(int acresOwned)
-
Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have.
- Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn.
-

- int askHowMuchGrainToFeedPeople(int bushels)
-
Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You can feed them more than they need to survive.
-

- int askHowManyAcresToPlant(int acresOwned, int population, int bushels)
-
Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year.
-
-

For each - question, do "sanity checking"; that is, test whether the answer is - possible (you have enough grain, you have enough people to do the planting - etc.), and keep asking until you get a possible value. (For example, - O Great Hammurabi, surely you jest! We have only 3415 bushels left!)

- -

Then the method needs to determine:

- -
    -
  1. If there is a plague, and how many people die from it.
  2. -
  3. How many people starved.
  4. -
  5. How many people came to the city.
  6. -
  7. How good the harvest is.
  8. -
  9. If you have a problem with rats, and how much grain they eat.
  10. -
  11. How much land costs (for deciding what to do next).
  12. -
-

These can all be local variables of your playGame method.

-

Use the following methods, in this order, to make the necessary calculations:

-
-
int plagueDeaths(int population)
-
Each year, there is a 15% chance of a horrible plague. When this - happens, half your people die. Return the number of plague deaths (possibly zero).
-

- int starvationDeaths(int population, int bushelsFedToPeople)
-
Each person needs 20 bushels of grain to survive. If you feed them - more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero).
-

- boolean uprising(int population, int howManyPeopleStarved)
-
Return true if more than - 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.)
-

- int immigrants(int population, int acresOwned, int grainInStorage)
-
Nobody will come to the city if people are starving (so don't call this method). If everyone is - well fed, compute how many people come to the city as: (20 * number of acres you have + amount of grain you have in - storage) / (100 * population) + 1.
-

- int harvest(int acres, int bushelsUsedAsSeed)
-
Choose a random integer between 1 and 6, inclusive. Each acre that was planted - with seed will yield this many bushels of grain. (Example: if you planted - 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested.
-

- int grainEatenByRats(int bushels)
-
There is a 40% chance that you will have a rat infestation. When this - happens, rats will eat somewhere between 10% and 30% of your - grain. Return the amount of grain eaten by rats (possibly zero).
-

- int newCostOfLand()
-
The price of land is random, and ranges from 17 to 23 bushels per - acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell - land.)
-
-
-

Do these computations, in this order, for each of ten years. Each - computation should be done in a separate method, and none of these methods - should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it.

- -

When the computations are finished, call a method printSummary to print the - summary for the year. This method will take several parameters.

- - -

When the game ends , use a method finalSummary to print out a final summary, and to tell the - player how good a job he/she did. I'll leave the details up to you, but the - usual evaluation is based on how many people starved, and how many acres per - person you end up with.

-

Your playGame method will be quite long, but very straightforward; it does very little but call other methods.

-

All the required arithmetic in this program should be integer. You - do not need doubles.

- -

I suggest that you first get the simplest possible version of the program - running and tested out (that is, leave out things like rats, plagues, and - immigration), then add these things one at a time to a working - program, testing as you go.

- -

Things you need to know:

- -

Random numbers

- -

To get a random number generator, you first need to import - java.util.Random (or java.util.*). Then, you can - create a random number generator with a statement such as:

- -
-

static Random rand = new Random();

-
- -

To get a new random number in the range 0..n-1, where - n is an int, call rand.nextInt(n). - To get a new random number in the range min..max, use - the expression rand.nextInt(max - min + 1) + min. You - can use the rand method in statements such as

- -
-

myNewNumber = rand.nextInt(5);
- if (rand.nextInt(100) < 15) { ... }

-
- -

To do something that happens p percent of the time, use

- -
-

if (rand.nextInt(100) < p) { ...do something... - }

-
- -

Getting input

-

To get a number from the player, add this method to your program:

-
-/**
- * Prints the given message (which should ask the user for some integral
- * quantity), and returns the number entered by the user. If the user's
- * response isn't an integer, the question is repeated until the user
- * does give a integer response.
- * 
- * @param message The request to present to the user.
- * @return The user's numeric response.
- */
- int getNumber(String message) {
-    while (true) {
-        System.out.print(message);
-        try {
-            return scanner.nextInt();
-        }
-        catch (InputMismatchException e) {
-            System.out.println("\"" + scanner.next() + "\" isn't a number!");
-        }
-    }
-}
-
- -

Here is an example of how you can use this method:

- -
-

sell = getNumber("O great Hammurabi, how many acres shall you sell?");

-
- -

Structure of the assignment:

- -
    -
  • Project name: Hammurabi
  • - -
  • Package name: hammurabi
  • - -
  • Class names and method signatures: - -
      -
    • - class Hammurabi - -
        -
      • public static void main(String[] args)
      • - -
      • Numerous other methods, as described above.
      • -
      -
    • -
    -
  • - -
- -

The above are requirements. The methods that do calculations, not input/output, will be tested by my test methods, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument names are irrelevant). You may have additional methods if you wish.

- -

Due date:

- -

Thursday, October 21, before midnight. Turn in your zipped assignment via - Blackboard. Email submissions will incur the wrath of Hammurabi (and won't be graded).

- - - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md deleted file mode 100644 index 796d85c..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md +++ /dev/null @@ -1,6 +0,0 @@ -# Notes - -from the original Dave Matuszek course of 2010. - -https://www.cis.upenn.edu/~matuszek/cit591-2010/Assignments/06-hammurabi.html - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml deleted file mode 100644 index d789654..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - 4.0.0 - - io.zipcoder - MicroLabs-Loops - 1.0-SNAPSHOT - - - - - junit - junit - 4.13.2 - - - - - - 1.8 - 1.8 - - \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore deleted file mode 100644 index a1c2a23..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore +++ /dev/null @@ -1,23 +0,0 @@ -# Compiled class file -*.class - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE deleted file mode 100644 index 22474e4..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2022 Zip Code Wilmington Core - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md deleted file mode 100644 index e4672c9..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md +++ /dev/null @@ -1,228 +0,0 @@ -# hamurabi -an ancient (in more ways than one) computer game (text) - -## General idea of the lab - -*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. - -Here are the standard instructions for the game: - -> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** -> -> * **Each person needs at least 20 bushels of grain per year to survive** -> * **Each person can farm at most 10 acres of land** -> * **It takes 2 bushels of grain to farm an acre of land** -> * **The market price for land fluctuates yearly** -> -> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** - -### Maven - -There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. - -### Details - -Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): - -```java -package hammurabi; // package declaration -import java.util.Random; // imports go here -import java.util.Scanner; - -public class Hammurabi { // must save in a file named Hammurabi.java - Random rand = new Random(); // this is an instance variable - Scanner scanner = new Scanner(System.in); - - public static void main(String\[\] args) { // required in every Java program - new Hammurabi().playGame(); - } - - void playGame() { - // declare local variables here: grain, population, etc. - // statements go after the declations - } - - //other methods go here -} -``` - -### Playing the game - -Here is what you start the game with: - -* 100 people -* 2800 bushels of grain in storage -* 1000 acres of land -* Land value is 19 bushels/acre - - -Each year, print out a summary similar to the following: - - O great Hammurabi! - You are in year 1 of your ten year rule. - In the previous year 0 people starved to death. - In the previous year 5 people entered the kingdom. - The population is now 100. - We harvested 3000 bushels at 3 bushels per acre. - Rats destroyed 200 bushels, leaving 2800 bushels in storage. - The city owns 1000 acres of land. - Land is currently worth 19 bushels per acre. - -The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. - -Here's what your `playGame` method needs to do each year, for up to 10 years: - -> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: -> -> `int askHowManyAcresToBuy(int price, int bushels)` -> -> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. -> -> ` -> int askHowManyAcresToSell(int acresOwned)` -> -> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. -> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. -> -> ` -> int askHowMuchGrainToFeedPeople(int bushels)` -> -> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. -> -> ` -> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` -> -> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. -> -> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) -> -> Then the method needs to determine: -> -> 1. If there is a plague, and how many people die from it. -> 2. How many people starved. -> 3. How many people came to the city. -> 4. How good the harvest is. -> 5. If you have a problem with rats, and how much grain they eat. -> 6. How much land costs (for deciding what to do next). -> -> These can all be local variables of your `playGame` method. -> -> Use the following methods, **in this order,** to make the necessary calculations: -> -> `int plagueDeaths(int population)` -> -> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). -> -> ` -> int starvationDeaths(int population, int bushelsFedToPeople)` -> -> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). -> -> ` -> boolean uprising(int population, int howManyPeopleStarved)` -> -> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) -> -> ` -> int immigrants(int population, int acresOwned, int grainInStorage)` -> -> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. -> -> ` -> int harvest(int acres, int bushelsUsedAsSeed)` -> -> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. -> -> ` -> int grainEatenByRats(int bushels)` -> -> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). -> -> ` -> int newCostOfLand()` -> -> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) - -Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. - -When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. - -When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. - -Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. - -All the required arithmetic in this program should be **integer**. You do not need doubles. - -### Urgent! - -> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. - -### Things you need to know: - -#### Random numbers - -To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: - -> `static Random rand = new Random();` - -To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as - -> `myNewNumber = rand.nextInt(5); -> if (rand.nextInt(100) < 15) { ... }` - -To do something that happens `p` percent of the time, use - -> `if (rand.nextInt(100) < p) { _...do something..._ }` - -#### Getting input - -To get a number from the player, add this method to your program: - -```java - /** - * Prints the given message (which should ask the user for some integral - * quantity), and returns the number entered by the user. If the user's - * response isn't an integer, the question is repeated until the user - * does give a integer response. - * - * @param message The request to present to the user. - * @return The user's numeric response. - */ - int getNumber(String message) { - while (true) { - System.out.print(message); - try { - return scanner.nextInt(); - } - catch (InputMismatchException e) { - System.out.println("\"" + scanner.next() + "\" isn't a number!"); - } - } - } -``` - -Here is an example of how you can use this method: - -> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` - -### Structure of the solution - -* Project name: `Hammurabi` -* Package name: `hammurabi` -* Class names and method signatures: - * `class Hammurabi` - * `public static void main(String[] args)` - * Numerous other methods, as described above. - -The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. - -### Yo! Test it! - -You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! - -But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. - -### Credits - -Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html deleted file mode 100644 index 78bbf24..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html +++ /dev/null @@ -1,299 +0,0 @@ - - - - - - - CIT591 Hammurabi - - - - - -

CIT 591 Assignment 3: - Hammurabi
- Fall 2010, David Matuszek

- -

Purpose of this assignment

- -
    -
  • To get you started using Java.
  • -
- -

General idea of the assignment

- -

Hammurabi is a very old computer game. Your job is to bring it into the - 21st century by writing it in Java.

- -

Here are the standard instructions for the game:

- -
-

Congratulations, you are the newest ruler of - ancient Samaria, elected for a ten year term of office. Your duties are to - dispense food, direct farming, and buy and sell land as needed to support - your people. Watch out for rat infestiations and the plague! Grain is the - general currency, measured in bushels. The following will help you in your - decisions:

- -
    -
  • Each person needs at least 20 bushels of - grain per year to survive
  • - -
  • Each person can farm at most 10 acres of - land
  • - -
  • It takes 2 bushels of grain to farm an acre - of land
  • - -
  • The market price for land fluctuates - yearly
  • -
- -

Rule wisely and you will be showered with - appreciation at the end of your term. Rule poorly and you will be kicked - out of office!

-
- -

Details

- -

Define a single class named Hammurabi. Use the following skeleton (but leave out the // comments):

-
package hammurabi;               // package declaration
-
-import java.util.Random;         // imports go here
-import java.util.Scanner;
-
-/**
- * The Hammurabi game.
- * @author Your name goes here
- * @author Your partner's name goes here
- */
-public class Hammurabi {         // must save in a file named Hammurabi.java
-    Random rand = new Random();  // this is an instance variable
-    Scanner scanner = new Scanner(System.in);
-
-    public static void main(String[] args) { // required in every Java program
-        new Hammurabi().playGame();
-    }
-
-    void playGame() {
-        // declare local variables here: grain, population, etc.
-        // statements go after the declations
-    }
-
-    //other methods go here
-}
-

Playing the game

-

Here is what you start the game with: -

    -
  • 100 people
  • -
  • 2800 bushels of grain in storage
  • -
  • 1000 acres of land
  • -
  • Land value is 19 bushels/acre

    -
  • -
-

Each year, print out a summary similar to the following:

-
-O great Hammurabi!
-You are in year 1 of your ten year rule.
-In the previous year 0 people starved to death.
-In the previous year 5 people entered the kingdom.
-The population is now 100.
-We harvested 3000 bushels at 3 bushels per acre.
-Rats destroyed 200 bushels, leaving 2800 bushels in storage.
-The city owns 1000 acres of land.
-Land is currently worth 19 bushels per acre.
-
- -

The above summary represents the initial state, at the beginning of - the first year--that is, when you first take office, and before you do any of - the computations below). So, for example, the previous year (under a - different ruler) must have started with 95 people; none starved, and 5 - entered the kingdom, so as you enter office you rule 100 people.

- -

Here's what your playGame method needs to do each year, for up to 10 years:

- -
-

Ask the player the following questions. These questions should be asked in this order. Do not give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below:

-
-
int askHowManyAcresToBuy(int price, int bushels)
-
Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase.
-

- int askHowManyAcresToSell(int acresOwned)
-
Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have.
- Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn.
-

- int askHowMuchGrainToFeedPeople(int bushels)
-
Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You can feed them more than they need to survive.
-

- int askHowManyAcresToPlant(int acresOwned, int population, int bushels)
-
Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year.
-
-

For each - question, do "sanity checking"; that is, test whether the answer is - possible (you have enough grain, you have enough people to do the planting - etc.), and keep asking until you get a possible value. (For example, - O Great Hammurabi, surely you jest! We have only 3415 bushels left!)

- -

Then the method needs to determine:

- -
    -
  1. If there is a plague, and how many people die from it.
  2. -
  3. How many people starved.
  4. -
  5. How many people came to the city.
  6. -
  7. How good the harvest is.
  8. -
  9. If you have a problem with rats, and how much grain they eat.
  10. -
  11. How much land costs (for deciding what to do next).
  12. -
-

These can all be local variables of your playGame method.

-

Use the following methods, in this order, to make the necessary calculations:

-
-
int plagueDeaths(int population)
-
Each year, there is a 15% chance of a horrible plague. When this - happens, half your people die. Return the number of plague deaths (possibly zero).
-

- int starvationDeaths(int population, int bushelsFedToPeople)
-
Each person needs 20 bushels of grain to survive. If you feed them - more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero).
-

- boolean uprising(int population, int howManyPeopleStarved)
-
Return true if more than - 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.)
-

- int immigrants(int population, int acresOwned, int grainInStorage)
-
Nobody will come to the city if people are starving (so don't call this method). If everyone is - well fed, compute how many people come to the city as: (20 * number of acres you have + amount of grain you have in - storage) / (100 * population) + 1.
-

- int harvest(int acres, int bushelsUsedAsSeed)
-
Choose a random integer between 1 and 6, inclusive. Each acre that was planted - with seed will yield this many bushels of grain. (Example: if you planted - 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested.
-

- int grainEatenByRats(int bushels)
-
There is a 40% chance that you will have a rat infestation. When this - happens, rats will eat somewhere between 10% and 30% of your - grain. Return the amount of grain eaten by rats (possibly zero).
-

- int newCostOfLand()
-
The price of land is random, and ranges from 17 to 23 bushels per - acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell - land.)
-
-
-

Do these computations, in this order, for each of ten years. Each - computation should be done in a separate method, and none of these methods - should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it.

- -

When the computations are finished, call a method printSummary to print the - summary for the year. This method will take several parameters.

- - -

When the game ends , use a method finalSummary to print out a final summary, and to tell the - player how good a job he/she did. I'll leave the details up to you, but the - usual evaluation is based on how many people starved, and how many acres per - person you end up with.

-

Your playGame method will be quite long, but very straightforward; it does very little but call other methods.

-

All the required arithmetic in this program should be integer. You - do not need doubles.

- -

I suggest that you first get the simplest possible version of the program - running and tested out (that is, leave out things like rats, plagues, and - immigration), then add these things one at a time to a working - program, testing as you go.

- -

Things you need to know:

- -

Random numbers

- -

To get a random number generator, you first need to import - java.util.Random (or java.util.*). Then, you can - create a random number generator with a statement such as:

- -
-

static Random rand = new Random();

-
- -

To get a new random number in the range 0..n-1, where - n is an int, call rand.nextInt(n). - To get a new random number in the range min..max, use - the expression rand.nextInt(max - min + 1) + min. You - can use the rand method in statements such as

- -
-

myNewNumber = rand.nextInt(5);
- if (rand.nextInt(100) < 15) { ... }

-
- -

To do something that happens p percent of the time, use

- -
-

if (rand.nextInt(100) < p) { ...do something... - }

-
- -

Getting input

-

To get a number from the player, add this method to your program:

-
-/**
- * Prints the given message (which should ask the user for some integral
- * quantity), and returns the number entered by the user. If the user's
- * response isn't an integer, the question is repeated until the user
- * does give a integer response.
- * 
- * @param message The request to present to the user.
- * @return The user's numeric response.
- */
- int getNumber(String message) {
-    while (true) {
-        System.out.print(message);
-        try {
-            return scanner.nextInt();
-        }
-        catch (InputMismatchException e) {
-            System.out.println("\"" + scanner.next() + "\" isn't a number!");
-        }
-    }
-}
-
- -

Here is an example of how you can use this method:

- -
-

sell = getNumber("O great Hammurabi, how many acres shall you sell?");

-
- -

Structure of the assignment:

- -
    -
  • Project name: Hammurabi
  • - -
  • Package name: hammurabi
  • - -
  • Class names and method signatures: - -
      -
    • - class Hammurabi - -
        -
      • public static void main(String[] args)
      • - -
      • Numerous other methods, as described above.
      • -
      -
    • -
    -
  • - -
- -

The above are requirements. The methods that do calculations, not input/output, will be tested by my test methods, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument names are irrelevant). You may have additional methods if you wish.

- -

Due date:

- -

Thursday, October 21, before midnight. Turn in your zipped assignment via - Blackboard. Email submissions will incur the wrath of Hammurabi (and won't be graded).

- - - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md deleted file mode 100644 index 796d85c..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md +++ /dev/null @@ -1,6 +0,0 @@ -# Notes - -from the original Dave Matuszek course of 2010. - -https://www.cis.upenn.edu/~matuszek/cit591-2010/Assignments/06-hammurabi.html - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml deleted file mode 100644 index d789654..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - 4.0.0 - - io.zipcoder - MicroLabs-Loops - 1.0-SNAPSHOT - - - - - junit - junit - 4.13.2 - - - - - - 1.8 - 1.8 - - \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore deleted file mode 100644 index a1c2a23..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore +++ /dev/null @@ -1,23 +0,0 @@ -# Compiled class file -*.class - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE deleted file mode 100644 index 22474e4..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2022 Zip Code Wilmington Core - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md deleted file mode 100644 index e4672c9..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md +++ /dev/null @@ -1,228 +0,0 @@ -# hamurabi -an ancient (in more ways than one) computer game (text) - -## General idea of the lab - -*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. - -Here are the standard instructions for the game: - -> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** -> -> * **Each person needs at least 20 bushels of grain per year to survive** -> * **Each person can farm at most 10 acres of land** -> * **It takes 2 bushels of grain to farm an acre of land** -> * **The market price for land fluctuates yearly** -> -> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** - -### Maven - -There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. - -### Details - -Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): - -```java -package hammurabi; // package declaration -import java.util.Random; // imports go here -import java.util.Scanner; - -public class Hammurabi { // must save in a file named Hammurabi.java - Random rand = new Random(); // this is an instance variable - Scanner scanner = new Scanner(System.in); - - public static void main(String\[\] args) { // required in every Java program - new Hammurabi().playGame(); - } - - void playGame() { - // declare local variables here: grain, population, etc. - // statements go after the declations - } - - //other methods go here -} -``` - -### Playing the game - -Here is what you start the game with: - -* 100 people -* 2800 bushels of grain in storage -* 1000 acres of land -* Land value is 19 bushels/acre - - -Each year, print out a summary similar to the following: - - O great Hammurabi! - You are in year 1 of your ten year rule. - In the previous year 0 people starved to death. - In the previous year 5 people entered the kingdom. - The population is now 100. - We harvested 3000 bushels at 3 bushels per acre. - Rats destroyed 200 bushels, leaving 2800 bushels in storage. - The city owns 1000 acres of land. - Land is currently worth 19 bushels per acre. - -The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. - -Here's what your `playGame` method needs to do each year, for up to 10 years: - -> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: -> -> `int askHowManyAcresToBuy(int price, int bushels)` -> -> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. -> -> ` -> int askHowManyAcresToSell(int acresOwned)` -> -> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. -> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. -> -> ` -> int askHowMuchGrainToFeedPeople(int bushels)` -> -> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. -> -> ` -> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` -> -> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. -> -> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) -> -> Then the method needs to determine: -> -> 1. If there is a plague, and how many people die from it. -> 2. How many people starved. -> 3. How many people came to the city. -> 4. How good the harvest is. -> 5. If you have a problem with rats, and how much grain they eat. -> 6. How much land costs (for deciding what to do next). -> -> These can all be local variables of your `playGame` method. -> -> Use the following methods, **in this order,** to make the necessary calculations: -> -> `int plagueDeaths(int population)` -> -> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). -> -> ` -> int starvationDeaths(int population, int bushelsFedToPeople)` -> -> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). -> -> ` -> boolean uprising(int population, int howManyPeopleStarved)` -> -> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) -> -> ` -> int immigrants(int population, int acresOwned, int grainInStorage)` -> -> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. -> -> ` -> int harvest(int acres, int bushelsUsedAsSeed)` -> -> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. -> -> ` -> int grainEatenByRats(int bushels)` -> -> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). -> -> ` -> int newCostOfLand()` -> -> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) - -Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. - -When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. - -When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. - -Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. - -All the required arithmetic in this program should be **integer**. You do not need doubles. - -### Urgent! - -> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. - -### Things you need to know: - -#### Random numbers - -To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: - -> `static Random rand = new Random();` - -To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as - -> `myNewNumber = rand.nextInt(5); -> if (rand.nextInt(100) < 15) { ... }` - -To do something that happens `p` percent of the time, use - -> `if (rand.nextInt(100) < p) { _...do something..._ }` - -#### Getting input - -To get a number from the player, add this method to your program: - -```java - /** - * Prints the given message (which should ask the user for some integral - * quantity), and returns the number entered by the user. If the user's - * response isn't an integer, the question is repeated until the user - * does give a integer response. - * - * @param message The request to present to the user. - * @return The user's numeric response. - */ - int getNumber(String message) { - while (true) { - System.out.print(message); - try { - return scanner.nextInt(); - } - catch (InputMismatchException e) { - System.out.println("\"" + scanner.next() + "\" isn't a number!"); - } - } - } -``` - -Here is an example of how you can use this method: - -> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` - -### Structure of the solution - -* Project name: `Hammurabi` -* Package name: `hammurabi` -* Class names and method signatures: - * `class Hammurabi` - * `public static void main(String[] args)` - * Numerous other methods, as described above. - -The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. - -### Yo! Test it! - -You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! - -But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. - -### Credits - -Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html deleted file mode 100644 index 78bbf24..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/06-hammurabi.html +++ /dev/null @@ -1,299 +0,0 @@ - - - - - - - CIT591 Hammurabi - - - - - -

CIT 591 Assignment 3: - Hammurabi
- Fall 2010, David Matuszek

- -

Purpose of this assignment

- -
    -
  • To get you started using Java.
  • -
- -

General idea of the assignment

- -

Hammurabi is a very old computer game. Your job is to bring it into the - 21st century by writing it in Java.

- -

Here are the standard instructions for the game:

- -
-

Congratulations, you are the newest ruler of - ancient Samaria, elected for a ten year term of office. Your duties are to - dispense food, direct farming, and buy and sell land as needed to support - your people. Watch out for rat infestiations and the plague! Grain is the - general currency, measured in bushels. The following will help you in your - decisions:

- -
    -
  • Each person needs at least 20 bushels of - grain per year to survive
  • - -
  • Each person can farm at most 10 acres of - land
  • - -
  • It takes 2 bushels of grain to farm an acre - of land
  • - -
  • The market price for land fluctuates - yearly
  • -
- -

Rule wisely and you will be showered with - appreciation at the end of your term. Rule poorly and you will be kicked - out of office!

-
- -

Details

- -

Define a single class named Hammurabi. Use the following skeleton (but leave out the // comments):

-
package hammurabi;               // package declaration
-
-import java.util.Random;         // imports go here
-import java.util.Scanner;
-
-/**
- * The Hammurabi game.
- * @author Your name goes here
- * @author Your partner's name goes here
- */
-public class Hammurabi {         // must save in a file named Hammurabi.java
-    Random rand = new Random();  // this is an instance variable
-    Scanner scanner = new Scanner(System.in);
-
-    public static void main(String[] args) { // required in every Java program
-        new Hammurabi().playGame();
-    }
-
-    void playGame() {
-        // declare local variables here: grain, population, etc.
-        // statements go after the declations
-    }
-
-    //other methods go here
-}
-

Playing the game

-

Here is what you start the game with: -

    -
  • 100 people
  • -
  • 2800 bushels of grain in storage
  • -
  • 1000 acres of land
  • -
  • Land value is 19 bushels/acre

    -
  • -
-

Each year, print out a summary similar to the following:

-
-O great Hammurabi!
-You are in year 1 of your ten year rule.
-In the previous year 0 people starved to death.
-In the previous year 5 people entered the kingdom.
-The population is now 100.
-We harvested 3000 bushels at 3 bushels per acre.
-Rats destroyed 200 bushels, leaving 2800 bushels in storage.
-The city owns 1000 acres of land.
-Land is currently worth 19 bushels per acre.
-
- -

The above summary represents the initial state, at the beginning of - the first year--that is, when you first take office, and before you do any of - the computations below). So, for example, the previous year (under a - different ruler) must have started with 95 people; none starved, and 5 - entered the kingdom, so as you enter office you rule 100 people.

- -

Here's what your playGame method needs to do each year, for up to 10 years:

- -
-

Ask the player the following questions. These questions should be asked in this order. Do not give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below:

-
-
int askHowManyAcresToBuy(int price, int bushels)
-
Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase.
-

- int askHowManyAcresToSell(int acresOwned)
-
Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have.
- Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn.
-

- int askHowMuchGrainToFeedPeople(int bushels)
-
Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You can feed them more than they need to survive.
-

- int askHowManyAcresToPlant(int acresOwned, int population, int bushels)
-
Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year.
-
-

For each - question, do "sanity checking"; that is, test whether the answer is - possible (you have enough grain, you have enough people to do the planting - etc.), and keep asking until you get a possible value. (For example, - O Great Hammurabi, surely you jest! We have only 3415 bushels left!)

- -

Then the method needs to determine:

- -
    -
  1. If there is a plague, and how many people die from it.
  2. -
  3. How many people starved.
  4. -
  5. How many people came to the city.
  6. -
  7. How good the harvest is.
  8. -
  9. If you have a problem with rats, and how much grain they eat.
  10. -
  11. How much land costs (for deciding what to do next).
  12. -
-

These can all be local variables of your playGame method.

-

Use the following methods, in this order, to make the necessary calculations:

-
-
int plagueDeaths(int population)
-
Each year, there is a 15% chance of a horrible plague. When this - happens, half your people die. Return the number of plague deaths (possibly zero).
-

- int starvationDeaths(int population, int bushelsFedToPeople)
-
Each person needs 20 bushels of grain to survive. If you feed them - more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero).
-

- boolean uprising(int population, int howManyPeopleStarved)
-
Return true if more than - 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.)
-

- int immigrants(int population, int acresOwned, int grainInStorage)
-
Nobody will come to the city if people are starving (so don't call this method). If everyone is - well fed, compute how many people come to the city as: (20 * number of acres you have + amount of grain you have in - storage) / (100 * population) + 1.
-

- int harvest(int acres, int bushelsUsedAsSeed)
-
Choose a random integer between 1 and 6, inclusive. Each acre that was planted - with seed will yield this many bushels of grain. (Example: if you planted - 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested.
-

- int grainEatenByRats(int bushels)
-
There is a 40% chance that you will have a rat infestation. When this - happens, rats will eat somewhere between 10% and 30% of your - grain. Return the amount of grain eaten by rats (possibly zero).
-

- int newCostOfLand()
-
The price of land is random, and ranges from 17 to 23 bushels per - acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell - land.)
-
-
-

Do these computations, in this order, for each of ten years. Each - computation should be done in a separate method, and none of these methods - should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it.

- -

When the computations are finished, call a method printSummary to print the - summary for the year. This method will take several parameters.

- - -

When the game ends , use a method finalSummary to print out a final summary, and to tell the - player how good a job he/she did. I'll leave the details up to you, but the - usual evaluation is based on how many people starved, and how many acres per - person you end up with.

-

Your playGame method will be quite long, but very straightforward; it does very little but call other methods.

-

All the required arithmetic in this program should be integer. You - do not need doubles.

- -

I suggest that you first get the simplest possible version of the program - running and tested out (that is, leave out things like rats, plagues, and - immigration), then add these things one at a time to a working - program, testing as you go.

- -

Things you need to know:

- -

Random numbers

- -

To get a random number generator, you first need to import - java.util.Random (or java.util.*). Then, you can - create a random number generator with a statement such as:

- -
-

static Random rand = new Random();

-
- -

To get a new random number in the range 0..n-1, where - n is an int, call rand.nextInt(n). - To get a new random number in the range min..max, use - the expression rand.nextInt(max - min + 1) + min. You - can use the rand method in statements such as

- -
-

myNewNumber = rand.nextInt(5);
- if (rand.nextInt(100) < 15) { ... }

-
- -

To do something that happens p percent of the time, use

- -
-

if (rand.nextInt(100) < p) { ...do something... - }

-
- -

Getting input

-

To get a number from the player, add this method to your program:

-
-/**
- * Prints the given message (which should ask the user for some integral
- * quantity), and returns the number entered by the user. If the user's
- * response isn't an integer, the question is repeated until the user
- * does give a integer response.
- * 
- * @param message The request to present to the user.
- * @return The user's numeric response.
- */
- int getNumber(String message) {
-    while (true) {
-        System.out.print(message);
-        try {
-            return scanner.nextInt();
-        }
-        catch (InputMismatchException e) {
-            System.out.println("\"" + scanner.next() + "\" isn't a number!");
-        }
-    }
-}
-
- -

Here is an example of how you can use this method:

- -
-

sell = getNumber("O great Hammurabi, how many acres shall you sell?");

-
- -

Structure of the assignment:

- -
    -
  • Project name: Hammurabi
  • - -
  • Package name: hammurabi
  • - -
  • Class names and method signatures: - -
      -
    • - class Hammurabi - -
        -
      • public static void main(String[] args)
      • - -
      • Numerous other methods, as described above.
      • -
      -
    • -
    -
  • - -
- -

The above are requirements. The methods that do calculations, not input/output, will be tested by my test methods, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument names are irrelevant). You may have additional methods if you wish.

- -

Due date:

- -

Thursday, October 21, before midnight. Turn in your zipped assignment via - Blackboard. Email submissions will incur the wrath of Hammurabi (and won't be graded).

- - - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md deleted file mode 100644 index 796d85c..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/docs/matuszek/README..md +++ /dev/null @@ -1,6 +0,0 @@ -# Notes - -from the original Dave Matuszek course of 2010. - -https://www.cis.upenn.edu/~matuszek/cit591-2010/Assignments/06-hammurabi.html - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml deleted file mode 100644 index d789654..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - 4.0.0 - - io.zipcoder - MicroLabs-Loops - 1.0-SNAPSHOT - - - - - junit - junit - 4.13.2 - - - - - - 1.8 - 1.8 - - \ No newline at end of file From f8127d1f7abca13889db5ca12db7e9f2e754cc1f Mon Sep 17 00:00:00 2001 From: Yingjie Yang <102939225+Tiffany678@users.noreply.github.com> Date: Sat, 12 Nov 2022 18:05:01 -0500 Subject: [PATCH 14/19] change method plagueDeath method --- docs/matuszek/Hammurabi.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/matuszek/Hammurabi.java b/docs/matuszek/Hammurabi.java index 4a7aa1c..9d3e1e6 100644 --- a/docs/matuszek/Hammurabi.java +++ b/docs/matuszek/Hammurabi.java @@ -94,10 +94,13 @@ int askHowManyAcresToPlant(int acresOwned, int population, int bushels){ // You must have enough acres, enough grain, and enough people to do the planting. // Any grain left over goes into storage for next year. int plagueDeaths(int population){ - - return population/2; + int plaDea = rand.nextInt(100)+1; + if(plaDea<=15) { + return population / 2; + }else return 0; } + // Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. // Return the number of plague deaths (possibly zero). int starvationDeaths(int population, int bushelsFedToPeople){ From 637bc5eeb76ad13e9637ed944ca2a6e4e400d8e3 Mon Sep 17 00:00:00 2001 From: Yingjie <52tiffany.yang@gmail.com> Date: Sun, 13 Nov 2022 00:23:47 -0500 Subject: [PATCH 15/19] Hammurabi completed --- .idea/misc.xml | 2 +- docs/matuszek/Hammurabi.java | 289 +++++++++++++----- target/classes/.idea/misc.xml | 2 +- target/classes/target/classes/.gitignore | 23 ++ target/classes/target/classes/LICENSE | 21 ++ target/classes/target/classes/README.md | 228 ++++++++++++++ target/classes/target/classes/pom.xml | 25 ++ .../target/classes/target/classes/.gitignore | 23 ++ .../target/classes/target/classes/LICENSE | 21 ++ .../target/classes/target/classes/README.md | 228 ++++++++++++++ .../target/classes/target/classes/pom.xml | 25 ++ .../target/classes/target/classes/.gitignore | 23 ++ .../target/classes/target/classes/LICENSE | 21 ++ .../target/classes/target/classes/README.md | 228 ++++++++++++++ .../target/classes/target/classes/pom.xml | 25 ++ .../target/classes/target/classes/.gitignore | 23 ++ .../target/classes/target/classes/LICENSE | 21 ++ .../target/classes/target/classes/README.md | 228 ++++++++++++++ .../target/classes/target/classes/pom.xml | 25 ++ .../target/classes/target/classes/.gitignore | 23 ++ .../target/classes/target/classes/LICENSE | 21 ++ .../target/classes/target/classes/README.md | 228 ++++++++++++++ .../target/classes/target/classes/pom.xml | 25 ++ .../target/classes/target/classes/.gitignore | 23 ++ .../target/classes/target/classes/LICENSE | 21 ++ .../target/classes/target/classes/README.md | 228 ++++++++++++++ .../target/classes/target/classes/pom.xml | 25 ++ .../target/classes/target/classes/.gitignore | 23 ++ .../target/classes/target/classes/LICENSE | 21 ++ .../target/classes/target/classes/README.md | 228 ++++++++++++++ .../target/classes/target/classes/pom.xml | 25 ++ .../target/classes/target/classes/.gitignore | 23 ++ .../target/classes/target/classes/LICENSE | 21 ++ .../target/classes/target/classes/README.md | 228 ++++++++++++++ .../target/classes/target/classes/pom.xml | 25 ++ .../target/classes/target/classes/.gitignore | 23 ++ .../target/classes/target/classes/LICENSE | 21 ++ .../target/classes/target/classes/README.md | 228 ++++++++++++++ .../target/classes/target/classes/pom.xml | 25 ++ 39 files changed, 2880 insertions(+), 86 deletions(-) create mode 100644 target/classes/target/classes/.gitignore create mode 100644 target/classes/target/classes/LICENSE create mode 100644 target/classes/target/classes/README.md create mode 100644 target/classes/target/classes/pom.xml create mode 100644 target/classes/target/classes/target/classes/.gitignore create mode 100644 target/classes/target/classes/target/classes/LICENSE create mode 100644 target/classes/target/classes/target/classes/README.md create mode 100644 target/classes/target/classes/target/classes/pom.xml create mode 100644 target/classes/target/classes/target/classes/target/classes/.gitignore create mode 100644 target/classes/target/classes/target/classes/target/classes/LICENSE create mode 100644 target/classes/target/classes/target/classes/target/classes/README.md create mode 100644 target/classes/target/classes/target/classes/target/classes/pom.xml create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/README.md create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml diff --git a/.idea/misc.xml b/.idea/misc.xml index bcd41e5..213cea6 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -7,7 +7,7 @@
- + \ No newline at end of file diff --git a/docs/matuszek/Hammurabi.java b/docs/matuszek/Hammurabi.java index efde624..21e9292 100644 --- a/docs/matuszek/Hammurabi.java +++ b/docs/matuszek/Hammurabi.java @@ -12,72 +12,125 @@ public class Hammurabi { // must save in a file named Hammurabi.java int ratEaten = 0; int starving = 0; int immigrants = 0; - public int people; - public int bushelsOfGrain; - public int acres; - public int landValue; - - - public Hammurabi(int peo,int bus, int acr, int lan){ - this.people=peo; - this.bushelsOfGrain=bus; - this.acres=acr; - this.landValue=lan; + int people; + int bushelsOfGrain; + int acres; + int landValue; + int bushelsPerAcre; + + + public Hammurabi(int peo, int bus, int acr, int lan) { + this.people = peo; + this.bushelsOfGrain = bus; + this.acres = acr; + this.landValue = lan; } -//* 100 people -//* 2800 bushels of grain in storage -//* 1000 acres of land -//* Land value is 19 bushels/acre + public static void main(String[] args) { // required in every Java program - // - Hammurabi h = new Hammurabi(100,2800,1000,19); + + new Hammurabi(100, 2800, 1000, 19).playGame(); } + void playGame() { // declare local variables here: grain, population, etc. // statements go after the declations - int people=100; - int bushelsOfGrain =2800; - int acres=1000; - int landValue=19; + int people = 100; + int bushelsOfGrain = 2800; + int acres = 1000; + int landValue = 19; + int acresToBuy =0; + int acresToSell =0; + int grainToFeed =0; + int acresToPlant = 0; + int plaguePeopleDeath =0; + int starvationPeopleDeath=0; + boolean uprisingPeople =false; + int immigrantsPeople = 0; + int harvestPeople = 0; + int grainEatenByRatsPeople =0; + int newCostOfLandPeople =0; + + + for (int i = 1; i < 11; i++) { + System.out.println("O great Hammurabi!"); + System.out.println("You are in year " + i + " of your ten year rule."); + System.out.println("In the previous year " + starvationPeopleDeath + " people starved to death."); + System.out.println("the previous year " + this.getImmigrants() + " people entered the kingdom."); + System.out.println("The population is now "+this.getPeople()+" ."); + System.out.println("We harvested "+this.getHarvest()+ " bushels at "+this.getBushelsPerAcre()+ " bushels per acre."); + System.out.println("Rats destroyed "+ this.getRatEaten()+" bushels, leaving "+this.getBushelsOfGrain()+" bushels in storage."); + System.out.println("The city owns "+this.getAcres()+ " acres of land."); + System.out.println("Land is currently worth "+ this.getLandValue()+" bushels per acre.\n"); + + acresToBuy=this.askHowManyAcresToBuy(this.getLandValue(), this.getBushelsOfGrain()); + if(acresToBuy==0){ + acresToSell=this.askHowManyAcresToSell(this.getAcres()); + + } + grainToFeed=askHowMuchGrainToFeedPeople(this.bushelsOfGrain); + acresToPlant=askHowManyAcresToPlant(this.acres,this.people, this.bushelsOfGrain); + plaguePeopleDeath = plagueDeaths(this.people); + starvationPeopleDeath = starvationDeaths(this.people, grainToFeed); + uprisingPeople = uprising(this.people, starvationPeopleDeath); + if (uprisingPeople) { + System.out.println("Too many people starved to death. Game Over!"); + break; + } + if(starvationPeopleDeath>0){ + immigrantsPeople = immigrants(this.people, this.acres, this.bushelsOfGrain); + } + harvestPeople = harvest(acresToPlant, this.bushelsOfGrain); + grainEatenByRatsPeople =grainEatenByRats(this.bushelsOfGrain); + newCostOfLandPeople =newCostOfLand(); + + } + } + //other methods go here - int askHowManyAcresToBuy(int price, int bushels){ + int askHowManyAcresToBuy(int price, int bushels) { System.out.println("How many acres do you wish to buy?"); - int in=scanner.nextInt(); - while(in*price>bushels || in <=0){ - System.out.println("Hammurabi: Thank again. You have only "+ bushels+" of grain. "); + int in = scanner.nextInt(); + while (in * price > bushels) { + System.out.println("Hammurabi: Think again. You have only " + bushels + " of grain. "); System.out.println("Re-enter the numbers of acres you wish to buy"); - in=scanner.nextInt(); + in = scanner.nextInt(); } - return in; + this.bushelsOfGrain-=in*price; + this.acres+=in; + return in; } //Asks the player how many acres of land to buy, and returns that number. // You must have enough grain to pay for your purchase. - int askHowManyAcresToSell(int acresOwned){ + int askHowManyAcresToSell(int acresOwned) { System.out.println("How many acres do you wish to sell?"); - int in=scanner.nextInt(); - while(in>acresOwned){ - System.out.println("Hammurabi: Thank again. You have only "+ acresOwned+" of grain. "); + int in = scanner.nextInt(); + while (in > acresOwned) { + System.out.println("Hammurabi: Thank again. You have only " + acresOwned + " of grain. "); System.out.println("Re-enter the numbers of acres you wish to sell: "); - in=scanner.nextInt(); + in = scanner.nextInt(); } + this.bushelsOfGrain+=in*this.landValue; + this.acres-=in; return in; } //Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. //Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. - int askHowMuchGrainToFeedPeople(int bushels){ + int askHowMuchGrainToFeedPeople(int bushels) { System.out.println("How many bushels do you wish to feed your people?"); - int in=scanner.nextInt(); - while(in>bushels){ - System.out.println("Hammurabi: Think again. You have only "+ bushelsOfGrain+" of grain. "); - System.out.println("Re-enter the numbers of acres you wish to sell: "); - in=scanner.nextInt(); + int in = scanner.nextInt(); + while (in > bushels ) { + System.out.println("Hammurabi: Think again. You have only " + bushelsOfGrain + " of grain."); + System.out.println("Re-enter the numbers of bushels you wish to feed people: "); + in = scanner.nextInt(); } + this.bushelsOfGrain-=in; + return in; } @@ -85,65 +138,66 @@ int askHowMuchGrainToFeedPeople(int bushels){ // and returns that number. You can't feed them more grain than you have. // You can feed them more than they need to survive. - int askHowManyAcresToPlant(int acresOwned, int population, int bushels){ + int askHowManyAcresToPlant(int acresOwned, int population, int bushels) { System.out.println("How many acres do you wish to plant with seed?"); - int in=scanner.nextInt(); - while(in>acresOwned || in>(bushels-population*20)){ - System.out.println("Hammurabi: Think again. You have only "+ bushelsOfGrain+" of grain. "); + int in = scanner.nextInt(); + while (in > acresOwned || in > bushels || in>population*10) { + System.out.println("Hammurabi: Think again. You have only " + bushelsOfGrain + " of grain. "); System.out.println("Re-enter the numbers of acres you wish to plant with seed: "); - in=scanner.nextInt(); + in = scanner.nextInt(); } - bushels-=in; + this.bushelsOfGrain-= in; return in; } //Ask the player how many acres to plant with grain, and returns that number. // You must have enough acres, enough grain, and enough people to do the planting. // Any grain left over goes into storage for next year. - int plagueDeaths(int population){ - int plaDea = rand.nextInt(100)+1; - if(plaDea<=15) { + int plagueDeaths(int population) { + int plaDea = rand.nextInt(100) + 1; + if (plaDea <= 15) { return population / 2; - }else return 0; + } else return 0; } - // Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. - // Return the number of plague deaths (possibly zero). - int starvationDeaths(int population, int bushelsFedToPeople){ - int numberOfStar=bushelsFedToPeople/20-population; - if(numberOfStar>=0) { + // Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. + // Return the number of plague deaths (possibly zero). + int starvationDeaths(int population, int bushelsFedToPeople) { + int numberOfStar = bushelsFedToPeople / 20 - population; + if (numberOfStar >= 0) { return 0; - }else return Math.abs(numberOfStar); + } else { + this.people -= Math.abs(numberOfStar); + return Math.abs(numberOfStar); + } } - // Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, + // Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, // but the grain is still gone. You don't get any benefit from having happy subjects. // Return the number of deaths from starvation (possibly zero). - boolean uprising(int population, int howManyPeopleStarved){ + boolean uprising(int population, int howManyPeopleStarved) { double starvingRate = (double) howManyPeopleStarved / population; - if(starvingRate > 0.450){ + if (starvingRate > 0.450) { this.gameOver = true; } else if (starvingRate <= 0.450) { this.gameOver = false; } - return this.gameOver; - - - + return this.gameOver; - } - // Return true if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) + } - int immigrants(int population, int acresOwned, int grainInStorage){ + // Return true if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) - if(starving == 0){ - this.immigrants = (20 * acresOwned + grainInStorage) / (100 * population) + 1; - } + int immigrants(int population, int acresOwned, int grainInStorage) { + if (starving == 0) { + this.immigrants = (20 * acresOwned + grainInStorage) / (100 * population) + 1; + } + this.people +=immigrants; return immigrants; /* if(starvationDeaths(population,grainInStorage)>0){ @@ -153,35 +207,32 @@ int immigrants(int population, int acresOwned, int grainInStorage){ } */ - } + } //Nobody will come to the city if people are starving (so don't call this method). // If everyone is well fed, compute how many people come to the city as: // (20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1. - int harvest(int acres, int bushelsUsedAsSeed){ + int harvest(int acres, int bushelsUsedAsSeed) { - int fertilizer = rand.nextInt(7 - 1) + 1; - this.harvest = bushelsUsedAsSeed * fertilizer * acres; + this.bushelsPerAcre = rand.nextInt(6) + 1; + this.harvest = this.bushelsPerAcre * acres; + this.bushelsOfGrain=this.bushelsOfGrain-bushelsUsedAsSeed+this.harvest; return harvest; - /* - int ran = rand.nextInt(6)+1; - return 1; - */ - } + } //Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. // (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. - int grainEatenByRats(int bushels){ + int grainEatenByRats(int bushels) { boolean ratInfestation = false; int ratEaten = 0; - if(rand.nextFloat() * 100 <= 40){ + if (rand.nextFloat() * 100 <= 40) { ratInfestation = true; } - if(ratInfestation){ - ratEaten = bushels * (rand.nextInt(31 - 10 ) + 10) / 100; + if (ratInfestation) { + ratEaten = bushels * (rand.nextInt(31 - 10) + 10) / 100; } this.ratEaten = ratEaten; return this.ratEaten; @@ -189,12 +240,82 @@ int grainEatenByRats(int bushels){ //There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). - int newCostOfLand(){ + int newCostOfLand() { int min = 17, max = 24; - this.landValue = rand.nextInt(max - min) + min; + this.landValue = rand.nextInt(max - min) + min; return this.landValue; - } + } + + public int getAcres() { + return acres; + } - //The price of land is random, and + public void setAcres(int acres) { + this.acres = acres; + } + + public int getBushelsOfGrain() { + return bushelsOfGrain; + } + + public void setBushelsOfGrain(int bushelsOfGrain) { + this.bushelsOfGrain = bushelsOfGrain; + } + + public int getHarvest() { + return harvest; + } + + public void setHarvest(int harvest) { + this.harvest = harvest; + } + + public int getLandValue() { + return landValue; + } + + public void setLandValue(int landValue) { + this.landValue = landValue; + } + + public int getImmigrants() { + return immigrants; + } + + public void setImmigrants(int immigrants) { + this.immigrants = immigrants; + } + + public int getPeople() { + return people; + } + + public void setPeople(int people) { + this.people = people; + } + + public int getStarving() { + return starving; + } + + public void setStarving(int starving) { + this.starving = starving; + } + + public int getRatEaten() { + return ratEaten; + } + + public void setRatEaten(int ratEaten) { + this.ratEaten = ratEaten; + } + + public int getBushelsPerAcre() { + return bushelsPerAcre; + } + + public void setBushelsPerAcre(int bushelsPerAcre) { + this.bushelsPerAcre = bushelsPerAcre; + } } diff --git a/target/classes/.idea/misc.xml b/target/classes/.idea/misc.xml index bcd41e5..213cea6 100644 --- a/target/classes/.idea/misc.xml +++ b/target/classes/.idea/misc.xml @@ -7,7 +7,7 @@ - + \ No newline at end of file diff --git a/target/classes/target/classes/.gitignore b/target/classes/target/classes/.gitignore new file mode 100644 index 0000000..a1c2a23 --- /dev/null +++ b/target/classes/target/classes/.gitignore @@ -0,0 +1,23 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* diff --git a/target/classes/target/classes/LICENSE b/target/classes/target/classes/LICENSE new file mode 100644 index 0000000..22474e4 --- /dev/null +++ b/target/classes/target/classes/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Zip Code Wilmington Core + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/target/classes/target/classes/README.md b/target/classes/target/classes/README.md new file mode 100644 index 0000000..e4672c9 --- /dev/null +++ b/target/classes/target/classes/README.md @@ -0,0 +1,228 @@ +# hamurabi +an ancient (in more ways than one) computer game (text) + +## General idea of the lab + +*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. + +Here are the standard instructions for the game: + +> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** +> +> * **Each person needs at least 20 bushels of grain per year to survive** +> * **Each person can farm at most 10 acres of land** +> * **It takes 2 bushels of grain to farm an acre of land** +> * **The market price for land fluctuates yearly** +> +> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** + +### Maven + +There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. + +### Details + +Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): + +```java +package hammurabi; // package declaration +import java.util.Random; // imports go here +import java.util.Scanner; + +public class Hammurabi { // must save in a file named Hammurabi.java + Random rand = new Random(); // this is an instance variable + Scanner scanner = new Scanner(System.in); + + public static void main(String\[\] args) { // required in every Java program + new Hammurabi().playGame(); + } + + void playGame() { + // declare local variables here: grain, population, etc. + // statements go after the declations + } + + //other methods go here +} +``` + +### Playing the game + +Here is what you start the game with: + +* 100 people +* 2800 bushels of grain in storage +* 1000 acres of land +* Land value is 19 bushels/acre + + +Each year, print out a summary similar to the following: + + O great Hammurabi! + You are in year 1 of your ten year rule. + In the previous year 0 people starved to death. + In the previous year 5 people entered the kingdom. + The population is now 100. + We harvested 3000 bushels at 3 bushels per acre. + Rats destroyed 200 bushels, leaving 2800 bushels in storage. + The city owns 1000 acres of land. + Land is currently worth 19 bushels per acre. + +The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. + +Here's what your `playGame` method needs to do each year, for up to 10 years: + +> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: +> +> `int askHowManyAcresToBuy(int price, int bushels)` +> +> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. +> +> ` +> int askHowManyAcresToSell(int acresOwned)` +> +> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. +> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. +> +> ` +> int askHowMuchGrainToFeedPeople(int bushels)` +> +> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. +> +> ` +> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` +> +> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. +> +> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) +> +> Then the method needs to determine: +> +> 1. If there is a plague, and how many people die from it. +> 2. How many people starved. +> 3. How many people came to the city. +> 4. How good the harvest is. +> 5. If you have a problem with rats, and how much grain they eat. +> 6. How much land costs (for deciding what to do next). +> +> These can all be local variables of your `playGame` method. +> +> Use the following methods, **in this order,** to make the necessary calculations: +> +> `int plagueDeaths(int population)` +> +> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). +> +> ` +> int starvationDeaths(int population, int bushelsFedToPeople)` +> +> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). +> +> ` +> boolean uprising(int population, int howManyPeopleStarved)` +> +> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) +> +> ` +> int immigrants(int population, int acresOwned, int grainInStorage)` +> +> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. +> +> ` +> int harvest(int acres, int bushelsUsedAsSeed)` +> +> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. +> +> ` +> int grainEatenByRats(int bushels)` +> +> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). +> +> ` +> int newCostOfLand()` +> +> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) + +Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. + +When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. + +When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. + +Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. + +All the required arithmetic in this program should be **integer**. You do not need doubles. + +### Urgent! + +> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. + +### Things you need to know: + +#### Random numbers + +To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: + +> `static Random rand = new Random();` + +To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as + +> `myNewNumber = rand.nextInt(5); +> if (rand.nextInt(100) < 15) { ... }` + +To do something that happens `p` percent of the time, use + +> `if (rand.nextInt(100) < p) { _...do something..._ }` + +#### Getting input + +To get a number from the player, add this method to your program: + +```java + /** + * Prints the given message (which should ask the user for some integral + * quantity), and returns the number entered by the user. If the user's + * response isn't an integer, the question is repeated until the user + * does give a integer response. + * + * @param message The request to present to the user. + * @return The user's numeric response. + */ + int getNumber(String message) { + while (true) { + System.out.print(message); + try { + return scanner.nextInt(); + } + catch (InputMismatchException e) { + System.out.println("\"" + scanner.next() + "\" isn't a number!"); + } + } + } +``` + +Here is an example of how you can use this method: + +> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` + +### Structure of the solution + +* Project name: `Hammurabi` +* Package name: `hammurabi` +* Class names and method signatures: + * `class Hammurabi` + * `public static void main(String[] args)` + * Numerous other methods, as described above. + +The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. + +### Yo! Test it! + +You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! + +But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. + +### Credits + +Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) + diff --git a/target/classes/target/classes/pom.xml b/target/classes/target/classes/pom.xml new file mode 100644 index 0000000..d789654 --- /dev/null +++ b/target/classes/target/classes/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + + io.zipcoder + MicroLabs-Loops + 1.0-SNAPSHOT + + + + + junit + junit + 4.13.2 + + + + + + 1.8 + 1.8 + + \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/.gitignore b/target/classes/target/classes/target/classes/.gitignore new file mode 100644 index 0000000..a1c2a23 --- /dev/null +++ b/target/classes/target/classes/target/classes/.gitignore @@ -0,0 +1,23 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* diff --git a/target/classes/target/classes/target/classes/LICENSE b/target/classes/target/classes/target/classes/LICENSE new file mode 100644 index 0000000..22474e4 --- /dev/null +++ b/target/classes/target/classes/target/classes/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Zip Code Wilmington Core + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/target/classes/target/classes/target/classes/README.md b/target/classes/target/classes/target/classes/README.md new file mode 100644 index 0000000..e4672c9 --- /dev/null +++ b/target/classes/target/classes/target/classes/README.md @@ -0,0 +1,228 @@ +# hamurabi +an ancient (in more ways than one) computer game (text) + +## General idea of the lab + +*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. + +Here are the standard instructions for the game: + +> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** +> +> * **Each person needs at least 20 bushels of grain per year to survive** +> * **Each person can farm at most 10 acres of land** +> * **It takes 2 bushels of grain to farm an acre of land** +> * **The market price for land fluctuates yearly** +> +> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** + +### Maven + +There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. + +### Details + +Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): + +```java +package hammurabi; // package declaration +import java.util.Random; // imports go here +import java.util.Scanner; + +public class Hammurabi { // must save in a file named Hammurabi.java + Random rand = new Random(); // this is an instance variable + Scanner scanner = new Scanner(System.in); + + public static void main(String\[\] args) { // required in every Java program + new Hammurabi().playGame(); + } + + void playGame() { + // declare local variables here: grain, population, etc. + // statements go after the declations + } + + //other methods go here +} +``` + +### Playing the game + +Here is what you start the game with: + +* 100 people +* 2800 bushels of grain in storage +* 1000 acres of land +* Land value is 19 bushels/acre + + +Each year, print out a summary similar to the following: + + O great Hammurabi! + You are in year 1 of your ten year rule. + In the previous year 0 people starved to death. + In the previous year 5 people entered the kingdom. + The population is now 100. + We harvested 3000 bushels at 3 bushels per acre. + Rats destroyed 200 bushels, leaving 2800 bushels in storage. + The city owns 1000 acres of land. + Land is currently worth 19 bushels per acre. + +The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. + +Here's what your `playGame` method needs to do each year, for up to 10 years: + +> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: +> +> `int askHowManyAcresToBuy(int price, int bushels)` +> +> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. +> +> ` +> int askHowManyAcresToSell(int acresOwned)` +> +> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. +> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. +> +> ` +> int askHowMuchGrainToFeedPeople(int bushels)` +> +> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. +> +> ` +> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` +> +> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. +> +> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) +> +> Then the method needs to determine: +> +> 1. If there is a plague, and how many people die from it. +> 2. How many people starved. +> 3. How many people came to the city. +> 4. How good the harvest is. +> 5. If you have a problem with rats, and how much grain they eat. +> 6. How much land costs (for deciding what to do next). +> +> These can all be local variables of your `playGame` method. +> +> Use the following methods, **in this order,** to make the necessary calculations: +> +> `int plagueDeaths(int population)` +> +> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). +> +> ` +> int starvationDeaths(int population, int bushelsFedToPeople)` +> +> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). +> +> ` +> boolean uprising(int population, int howManyPeopleStarved)` +> +> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) +> +> ` +> int immigrants(int population, int acresOwned, int grainInStorage)` +> +> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. +> +> ` +> int harvest(int acres, int bushelsUsedAsSeed)` +> +> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. +> +> ` +> int grainEatenByRats(int bushels)` +> +> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). +> +> ` +> int newCostOfLand()` +> +> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) + +Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. + +When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. + +When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. + +Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. + +All the required arithmetic in this program should be **integer**. You do not need doubles. + +### Urgent! + +> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. + +### Things you need to know: + +#### Random numbers + +To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: + +> `static Random rand = new Random();` + +To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as + +> `myNewNumber = rand.nextInt(5); +> if (rand.nextInt(100) < 15) { ... }` + +To do something that happens `p` percent of the time, use + +> `if (rand.nextInt(100) < p) { _...do something..._ }` + +#### Getting input + +To get a number from the player, add this method to your program: + +```java + /** + * Prints the given message (which should ask the user for some integral + * quantity), and returns the number entered by the user. If the user's + * response isn't an integer, the question is repeated until the user + * does give a integer response. + * + * @param message The request to present to the user. + * @return The user's numeric response. + */ + int getNumber(String message) { + while (true) { + System.out.print(message); + try { + return scanner.nextInt(); + } + catch (InputMismatchException e) { + System.out.println("\"" + scanner.next() + "\" isn't a number!"); + } + } + } +``` + +Here is an example of how you can use this method: + +> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` + +### Structure of the solution + +* Project name: `Hammurabi` +* Package name: `hammurabi` +* Class names and method signatures: + * `class Hammurabi` + * `public static void main(String[] args)` + * Numerous other methods, as described above. + +The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. + +### Yo! Test it! + +You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! + +But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. + +### Credits + +Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) + diff --git a/target/classes/target/classes/target/classes/pom.xml b/target/classes/target/classes/target/classes/pom.xml new file mode 100644 index 0000000..d789654 --- /dev/null +++ b/target/classes/target/classes/target/classes/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + + io.zipcoder + MicroLabs-Loops + 1.0-SNAPSHOT + + + + + junit + junit + 4.13.2 + + + + + + 1.8 + 1.8 + + \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/target/classes/.gitignore b/target/classes/target/classes/target/classes/target/classes/.gitignore new file mode 100644 index 0000000..a1c2a23 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/.gitignore @@ -0,0 +1,23 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* diff --git a/target/classes/target/classes/target/classes/target/classes/LICENSE b/target/classes/target/classes/target/classes/target/classes/LICENSE new file mode 100644 index 0000000..22474e4 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Zip Code Wilmington Core + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/target/classes/target/classes/target/classes/target/classes/README.md b/target/classes/target/classes/target/classes/target/classes/README.md new file mode 100644 index 0000000..e4672c9 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/README.md @@ -0,0 +1,228 @@ +# hamurabi +an ancient (in more ways than one) computer game (text) + +## General idea of the lab + +*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. + +Here are the standard instructions for the game: + +> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** +> +> * **Each person needs at least 20 bushels of grain per year to survive** +> * **Each person can farm at most 10 acres of land** +> * **It takes 2 bushels of grain to farm an acre of land** +> * **The market price for land fluctuates yearly** +> +> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** + +### Maven + +There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. + +### Details + +Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): + +```java +package hammurabi; // package declaration +import java.util.Random; // imports go here +import java.util.Scanner; + +public class Hammurabi { // must save in a file named Hammurabi.java + Random rand = new Random(); // this is an instance variable + Scanner scanner = new Scanner(System.in); + + public static void main(String\[\] args) { // required in every Java program + new Hammurabi().playGame(); + } + + void playGame() { + // declare local variables here: grain, population, etc. + // statements go after the declations + } + + //other methods go here +} +``` + +### Playing the game + +Here is what you start the game with: + +* 100 people +* 2800 bushels of grain in storage +* 1000 acres of land +* Land value is 19 bushels/acre + + +Each year, print out a summary similar to the following: + + O great Hammurabi! + You are in year 1 of your ten year rule. + In the previous year 0 people starved to death. + In the previous year 5 people entered the kingdom. + The population is now 100. + We harvested 3000 bushels at 3 bushels per acre. + Rats destroyed 200 bushels, leaving 2800 bushels in storage. + The city owns 1000 acres of land. + Land is currently worth 19 bushels per acre. + +The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. + +Here's what your `playGame` method needs to do each year, for up to 10 years: + +> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: +> +> `int askHowManyAcresToBuy(int price, int bushels)` +> +> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. +> +> ` +> int askHowManyAcresToSell(int acresOwned)` +> +> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. +> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. +> +> ` +> int askHowMuchGrainToFeedPeople(int bushels)` +> +> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. +> +> ` +> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` +> +> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. +> +> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) +> +> Then the method needs to determine: +> +> 1. If there is a plague, and how many people die from it. +> 2. How many people starved. +> 3. How many people came to the city. +> 4. How good the harvest is. +> 5. If you have a problem with rats, and how much grain they eat. +> 6. How much land costs (for deciding what to do next). +> +> These can all be local variables of your `playGame` method. +> +> Use the following methods, **in this order,** to make the necessary calculations: +> +> `int plagueDeaths(int population)` +> +> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). +> +> ` +> int starvationDeaths(int population, int bushelsFedToPeople)` +> +> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). +> +> ` +> boolean uprising(int population, int howManyPeopleStarved)` +> +> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) +> +> ` +> int immigrants(int population, int acresOwned, int grainInStorage)` +> +> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. +> +> ` +> int harvest(int acres, int bushelsUsedAsSeed)` +> +> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. +> +> ` +> int grainEatenByRats(int bushels)` +> +> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). +> +> ` +> int newCostOfLand()` +> +> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) + +Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. + +When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. + +When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. + +Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. + +All the required arithmetic in this program should be **integer**. You do not need doubles. + +### Urgent! + +> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. + +### Things you need to know: + +#### Random numbers + +To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: + +> `static Random rand = new Random();` + +To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as + +> `myNewNumber = rand.nextInt(5); +> if (rand.nextInt(100) < 15) { ... }` + +To do something that happens `p` percent of the time, use + +> `if (rand.nextInt(100) < p) { _...do something..._ }` + +#### Getting input + +To get a number from the player, add this method to your program: + +```java + /** + * Prints the given message (which should ask the user for some integral + * quantity), and returns the number entered by the user. If the user's + * response isn't an integer, the question is repeated until the user + * does give a integer response. + * + * @param message The request to present to the user. + * @return The user's numeric response. + */ + int getNumber(String message) { + while (true) { + System.out.print(message); + try { + return scanner.nextInt(); + } + catch (InputMismatchException e) { + System.out.println("\"" + scanner.next() + "\" isn't a number!"); + } + } + } +``` + +Here is an example of how you can use this method: + +> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` + +### Structure of the solution + +* Project name: `Hammurabi` +* Package name: `hammurabi` +* Class names and method signatures: + * `class Hammurabi` + * `public static void main(String[] args)` + * Numerous other methods, as described above. + +The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. + +### Yo! Test it! + +You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! + +But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. + +### Credits + +Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) + diff --git a/target/classes/target/classes/target/classes/target/classes/pom.xml b/target/classes/target/classes/target/classes/target/classes/pom.xml new file mode 100644 index 0000000..d789654 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + + io.zipcoder + MicroLabs-Loops + 1.0-SNAPSHOT + + + + + junit + junit + 4.13.2 + + + + + + 1.8 + 1.8 + + \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore b/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore new file mode 100644 index 0000000..a1c2a23 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore @@ -0,0 +1,23 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE b/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE new file mode 100644 index 0000000..22474e4 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Zip Code Wilmington Core + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/README.md b/target/classes/target/classes/target/classes/target/classes/target/classes/README.md new file mode 100644 index 0000000..e4672c9 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/README.md @@ -0,0 +1,228 @@ +# hamurabi +an ancient (in more ways than one) computer game (text) + +## General idea of the lab + +*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. + +Here are the standard instructions for the game: + +> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** +> +> * **Each person needs at least 20 bushels of grain per year to survive** +> * **Each person can farm at most 10 acres of land** +> * **It takes 2 bushels of grain to farm an acre of land** +> * **The market price for land fluctuates yearly** +> +> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** + +### Maven + +There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. + +### Details + +Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): + +```java +package hammurabi; // package declaration +import java.util.Random; // imports go here +import java.util.Scanner; + +public class Hammurabi { // must save in a file named Hammurabi.java + Random rand = new Random(); // this is an instance variable + Scanner scanner = new Scanner(System.in); + + public static void main(String\[\] args) { // required in every Java program + new Hammurabi().playGame(); + } + + void playGame() { + // declare local variables here: grain, population, etc. + // statements go after the declations + } + + //other methods go here +} +``` + +### Playing the game + +Here is what you start the game with: + +* 100 people +* 2800 bushels of grain in storage +* 1000 acres of land +* Land value is 19 bushels/acre + + +Each year, print out a summary similar to the following: + + O great Hammurabi! + You are in year 1 of your ten year rule. + In the previous year 0 people starved to death. + In the previous year 5 people entered the kingdom. + The population is now 100. + We harvested 3000 bushels at 3 bushels per acre. + Rats destroyed 200 bushels, leaving 2800 bushels in storage. + The city owns 1000 acres of land. + Land is currently worth 19 bushels per acre. + +The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. + +Here's what your `playGame` method needs to do each year, for up to 10 years: + +> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: +> +> `int askHowManyAcresToBuy(int price, int bushels)` +> +> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. +> +> ` +> int askHowManyAcresToSell(int acresOwned)` +> +> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. +> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. +> +> ` +> int askHowMuchGrainToFeedPeople(int bushels)` +> +> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. +> +> ` +> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` +> +> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. +> +> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) +> +> Then the method needs to determine: +> +> 1. If there is a plague, and how many people die from it. +> 2. How many people starved. +> 3. How many people came to the city. +> 4. How good the harvest is. +> 5. If you have a problem with rats, and how much grain they eat. +> 6. How much land costs (for deciding what to do next). +> +> These can all be local variables of your `playGame` method. +> +> Use the following methods, **in this order,** to make the necessary calculations: +> +> `int plagueDeaths(int population)` +> +> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). +> +> ` +> int starvationDeaths(int population, int bushelsFedToPeople)` +> +> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). +> +> ` +> boolean uprising(int population, int howManyPeopleStarved)` +> +> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) +> +> ` +> int immigrants(int population, int acresOwned, int grainInStorage)` +> +> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. +> +> ` +> int harvest(int acres, int bushelsUsedAsSeed)` +> +> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. +> +> ` +> int grainEatenByRats(int bushels)` +> +> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). +> +> ` +> int newCostOfLand()` +> +> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) + +Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. + +When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. + +When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. + +Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. + +All the required arithmetic in this program should be **integer**. You do not need doubles. + +### Urgent! + +> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. + +### Things you need to know: + +#### Random numbers + +To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: + +> `static Random rand = new Random();` + +To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as + +> `myNewNumber = rand.nextInt(5); +> if (rand.nextInt(100) < 15) { ... }` + +To do something that happens `p` percent of the time, use + +> `if (rand.nextInt(100) < p) { _...do something..._ }` + +#### Getting input + +To get a number from the player, add this method to your program: + +```java + /** + * Prints the given message (which should ask the user for some integral + * quantity), and returns the number entered by the user. If the user's + * response isn't an integer, the question is repeated until the user + * does give a integer response. + * + * @param message The request to present to the user. + * @return The user's numeric response. + */ + int getNumber(String message) { + while (true) { + System.out.print(message); + try { + return scanner.nextInt(); + } + catch (InputMismatchException e) { + System.out.println("\"" + scanner.next() + "\" isn't a number!"); + } + } + } +``` + +Here is an example of how you can use this method: + +> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` + +### Structure of the solution + +* Project name: `Hammurabi` +* Package name: `hammurabi` +* Class names and method signatures: + * `class Hammurabi` + * `public static void main(String[] args)` + * Numerous other methods, as described above. + +The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. + +### Yo! Test it! + +You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! + +But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. + +### Credits + +Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml b/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml new file mode 100644 index 0000000..d789654 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + + io.zipcoder + MicroLabs-Loops + 1.0-SNAPSHOT + + + + + junit + junit + 4.13.2 + + + + + + 1.8 + 1.8 + + \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore new file mode 100644 index 0000000..a1c2a23 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore @@ -0,0 +1,23 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE new file mode 100644 index 0000000..22474e4 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Zip Code Wilmington Core + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md new file mode 100644 index 0000000..e4672c9 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md @@ -0,0 +1,228 @@ +# hamurabi +an ancient (in more ways than one) computer game (text) + +## General idea of the lab + +*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. + +Here are the standard instructions for the game: + +> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** +> +> * **Each person needs at least 20 bushels of grain per year to survive** +> * **Each person can farm at most 10 acres of land** +> * **It takes 2 bushels of grain to farm an acre of land** +> * **The market price for land fluctuates yearly** +> +> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** + +### Maven + +There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. + +### Details + +Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): + +```java +package hammurabi; // package declaration +import java.util.Random; // imports go here +import java.util.Scanner; + +public class Hammurabi { // must save in a file named Hammurabi.java + Random rand = new Random(); // this is an instance variable + Scanner scanner = new Scanner(System.in); + + public static void main(String\[\] args) { // required in every Java program + new Hammurabi().playGame(); + } + + void playGame() { + // declare local variables here: grain, population, etc. + // statements go after the declations + } + + //other methods go here +} +``` + +### Playing the game + +Here is what you start the game with: + +* 100 people +* 2800 bushels of grain in storage +* 1000 acres of land +* Land value is 19 bushels/acre + + +Each year, print out a summary similar to the following: + + O great Hammurabi! + You are in year 1 of your ten year rule. + In the previous year 0 people starved to death. + In the previous year 5 people entered the kingdom. + The population is now 100. + We harvested 3000 bushels at 3 bushels per acre. + Rats destroyed 200 bushels, leaving 2800 bushels in storage. + The city owns 1000 acres of land. + Land is currently worth 19 bushels per acre. + +The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. + +Here's what your `playGame` method needs to do each year, for up to 10 years: + +> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: +> +> `int askHowManyAcresToBuy(int price, int bushels)` +> +> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. +> +> ` +> int askHowManyAcresToSell(int acresOwned)` +> +> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. +> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. +> +> ` +> int askHowMuchGrainToFeedPeople(int bushels)` +> +> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. +> +> ` +> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` +> +> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. +> +> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) +> +> Then the method needs to determine: +> +> 1. If there is a plague, and how many people die from it. +> 2. How many people starved. +> 3. How many people came to the city. +> 4. How good the harvest is. +> 5. If you have a problem with rats, and how much grain they eat. +> 6. How much land costs (for deciding what to do next). +> +> These can all be local variables of your `playGame` method. +> +> Use the following methods, **in this order,** to make the necessary calculations: +> +> `int plagueDeaths(int population)` +> +> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). +> +> ` +> int starvationDeaths(int population, int bushelsFedToPeople)` +> +> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). +> +> ` +> boolean uprising(int population, int howManyPeopleStarved)` +> +> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) +> +> ` +> int immigrants(int population, int acresOwned, int grainInStorage)` +> +> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. +> +> ` +> int harvest(int acres, int bushelsUsedAsSeed)` +> +> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. +> +> ` +> int grainEatenByRats(int bushels)` +> +> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). +> +> ` +> int newCostOfLand()` +> +> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) + +Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. + +When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. + +When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. + +Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. + +All the required arithmetic in this program should be **integer**. You do not need doubles. + +### Urgent! + +> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. + +### Things you need to know: + +#### Random numbers + +To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: + +> `static Random rand = new Random();` + +To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as + +> `myNewNumber = rand.nextInt(5); +> if (rand.nextInt(100) < 15) { ... }` + +To do something that happens `p` percent of the time, use + +> `if (rand.nextInt(100) < p) { _...do something..._ }` + +#### Getting input + +To get a number from the player, add this method to your program: + +```java + /** + * Prints the given message (which should ask the user for some integral + * quantity), and returns the number entered by the user. If the user's + * response isn't an integer, the question is repeated until the user + * does give a integer response. + * + * @param message The request to present to the user. + * @return The user's numeric response. + */ + int getNumber(String message) { + while (true) { + System.out.print(message); + try { + return scanner.nextInt(); + } + catch (InputMismatchException e) { + System.out.println("\"" + scanner.next() + "\" isn't a number!"); + } + } + } +``` + +Here is an example of how you can use this method: + +> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` + +### Structure of the solution + +* Project name: `Hammurabi` +* Package name: `hammurabi` +* Class names and method signatures: + * `class Hammurabi` + * `public static void main(String[] args)` + * Numerous other methods, as described above. + +The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. + +### Yo! Test it! + +You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! + +But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. + +### Credits + +Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml new file mode 100644 index 0000000..d789654 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + + io.zipcoder + MicroLabs-Loops + 1.0-SNAPSHOT + + + + + junit + junit + 4.13.2 + + + + + + 1.8 + 1.8 + + \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore new file mode 100644 index 0000000..a1c2a23 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore @@ -0,0 +1,23 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE new file mode 100644 index 0000000..22474e4 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Zip Code Wilmington Core + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md new file mode 100644 index 0000000..e4672c9 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md @@ -0,0 +1,228 @@ +# hamurabi +an ancient (in more ways than one) computer game (text) + +## General idea of the lab + +*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. + +Here are the standard instructions for the game: + +> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** +> +> * **Each person needs at least 20 bushels of grain per year to survive** +> * **Each person can farm at most 10 acres of land** +> * **It takes 2 bushels of grain to farm an acre of land** +> * **The market price for land fluctuates yearly** +> +> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** + +### Maven + +There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. + +### Details + +Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): + +```java +package hammurabi; // package declaration +import java.util.Random; // imports go here +import java.util.Scanner; + +public class Hammurabi { // must save in a file named Hammurabi.java + Random rand = new Random(); // this is an instance variable + Scanner scanner = new Scanner(System.in); + + public static void main(String\[\] args) { // required in every Java program + new Hammurabi().playGame(); + } + + void playGame() { + // declare local variables here: grain, population, etc. + // statements go after the declations + } + + //other methods go here +} +``` + +### Playing the game + +Here is what you start the game with: + +* 100 people +* 2800 bushels of grain in storage +* 1000 acres of land +* Land value is 19 bushels/acre + + +Each year, print out a summary similar to the following: + + O great Hammurabi! + You are in year 1 of your ten year rule. + In the previous year 0 people starved to death. + In the previous year 5 people entered the kingdom. + The population is now 100. + We harvested 3000 bushels at 3 bushels per acre. + Rats destroyed 200 bushels, leaving 2800 bushels in storage. + The city owns 1000 acres of land. + Land is currently worth 19 bushels per acre. + +The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. + +Here's what your `playGame` method needs to do each year, for up to 10 years: + +> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: +> +> `int askHowManyAcresToBuy(int price, int bushels)` +> +> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. +> +> ` +> int askHowManyAcresToSell(int acresOwned)` +> +> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. +> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. +> +> ` +> int askHowMuchGrainToFeedPeople(int bushels)` +> +> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. +> +> ` +> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` +> +> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. +> +> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) +> +> Then the method needs to determine: +> +> 1. If there is a plague, and how many people die from it. +> 2. How many people starved. +> 3. How many people came to the city. +> 4. How good the harvest is. +> 5. If you have a problem with rats, and how much grain they eat. +> 6. How much land costs (for deciding what to do next). +> +> These can all be local variables of your `playGame` method. +> +> Use the following methods, **in this order,** to make the necessary calculations: +> +> `int plagueDeaths(int population)` +> +> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). +> +> ` +> int starvationDeaths(int population, int bushelsFedToPeople)` +> +> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). +> +> ` +> boolean uprising(int population, int howManyPeopleStarved)` +> +> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) +> +> ` +> int immigrants(int population, int acresOwned, int grainInStorage)` +> +> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. +> +> ` +> int harvest(int acres, int bushelsUsedAsSeed)` +> +> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. +> +> ` +> int grainEatenByRats(int bushels)` +> +> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). +> +> ` +> int newCostOfLand()` +> +> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) + +Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. + +When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. + +When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. + +Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. + +All the required arithmetic in this program should be **integer**. You do not need doubles. + +### Urgent! + +> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. + +### Things you need to know: + +#### Random numbers + +To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: + +> `static Random rand = new Random();` + +To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as + +> `myNewNumber = rand.nextInt(5); +> if (rand.nextInt(100) < 15) { ... }` + +To do something that happens `p` percent of the time, use + +> `if (rand.nextInt(100) < p) { _...do something..._ }` + +#### Getting input + +To get a number from the player, add this method to your program: + +```java + /** + * Prints the given message (which should ask the user for some integral + * quantity), and returns the number entered by the user. If the user's + * response isn't an integer, the question is repeated until the user + * does give a integer response. + * + * @param message The request to present to the user. + * @return The user's numeric response. + */ + int getNumber(String message) { + while (true) { + System.out.print(message); + try { + return scanner.nextInt(); + } + catch (InputMismatchException e) { + System.out.println("\"" + scanner.next() + "\" isn't a number!"); + } + } + } +``` + +Here is an example of how you can use this method: + +> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` + +### Structure of the solution + +* Project name: `Hammurabi` +* Package name: `hammurabi` +* Class names and method signatures: + * `class Hammurabi` + * `public static void main(String[] args)` + * Numerous other methods, as described above. + +The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. + +### Yo! Test it! + +You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! + +But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. + +### Credits + +Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml new file mode 100644 index 0000000..d789654 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + + io.zipcoder + MicroLabs-Loops + 1.0-SNAPSHOT + + + + + junit + junit + 4.13.2 + + + + + + 1.8 + 1.8 + + \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore new file mode 100644 index 0000000..a1c2a23 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore @@ -0,0 +1,23 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE new file mode 100644 index 0000000..22474e4 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Zip Code Wilmington Core + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md new file mode 100644 index 0000000..e4672c9 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md @@ -0,0 +1,228 @@ +# hamurabi +an ancient (in more ways than one) computer game (text) + +## General idea of the lab + +*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. + +Here are the standard instructions for the game: + +> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** +> +> * **Each person needs at least 20 bushels of grain per year to survive** +> * **Each person can farm at most 10 acres of land** +> * **It takes 2 bushels of grain to farm an acre of land** +> * **The market price for land fluctuates yearly** +> +> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** + +### Maven + +There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. + +### Details + +Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): + +```java +package hammurabi; // package declaration +import java.util.Random; // imports go here +import java.util.Scanner; + +public class Hammurabi { // must save in a file named Hammurabi.java + Random rand = new Random(); // this is an instance variable + Scanner scanner = new Scanner(System.in); + + public static void main(String\[\] args) { // required in every Java program + new Hammurabi().playGame(); + } + + void playGame() { + // declare local variables here: grain, population, etc. + // statements go after the declations + } + + //other methods go here +} +``` + +### Playing the game + +Here is what you start the game with: + +* 100 people +* 2800 bushels of grain in storage +* 1000 acres of land +* Land value is 19 bushels/acre + + +Each year, print out a summary similar to the following: + + O great Hammurabi! + You are in year 1 of your ten year rule. + In the previous year 0 people starved to death. + In the previous year 5 people entered the kingdom. + The population is now 100. + We harvested 3000 bushels at 3 bushels per acre. + Rats destroyed 200 bushels, leaving 2800 bushels in storage. + The city owns 1000 acres of land. + Land is currently worth 19 bushels per acre. + +The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. + +Here's what your `playGame` method needs to do each year, for up to 10 years: + +> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: +> +> `int askHowManyAcresToBuy(int price, int bushels)` +> +> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. +> +> ` +> int askHowManyAcresToSell(int acresOwned)` +> +> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. +> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. +> +> ` +> int askHowMuchGrainToFeedPeople(int bushels)` +> +> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. +> +> ` +> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` +> +> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. +> +> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) +> +> Then the method needs to determine: +> +> 1. If there is a plague, and how many people die from it. +> 2. How many people starved. +> 3. How many people came to the city. +> 4. How good the harvest is. +> 5. If you have a problem with rats, and how much grain they eat. +> 6. How much land costs (for deciding what to do next). +> +> These can all be local variables of your `playGame` method. +> +> Use the following methods, **in this order,** to make the necessary calculations: +> +> `int plagueDeaths(int population)` +> +> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). +> +> ` +> int starvationDeaths(int population, int bushelsFedToPeople)` +> +> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). +> +> ` +> boolean uprising(int population, int howManyPeopleStarved)` +> +> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) +> +> ` +> int immigrants(int population, int acresOwned, int grainInStorage)` +> +> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. +> +> ` +> int harvest(int acres, int bushelsUsedAsSeed)` +> +> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. +> +> ` +> int grainEatenByRats(int bushels)` +> +> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). +> +> ` +> int newCostOfLand()` +> +> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) + +Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. + +When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. + +When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. + +Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. + +All the required arithmetic in this program should be **integer**. You do not need doubles. + +### Urgent! + +> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. + +### Things you need to know: + +#### Random numbers + +To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: + +> `static Random rand = new Random();` + +To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as + +> `myNewNumber = rand.nextInt(5); +> if (rand.nextInt(100) < 15) { ... }` + +To do something that happens `p` percent of the time, use + +> `if (rand.nextInt(100) < p) { _...do something..._ }` + +#### Getting input + +To get a number from the player, add this method to your program: + +```java + /** + * Prints the given message (which should ask the user for some integral + * quantity), and returns the number entered by the user. If the user's + * response isn't an integer, the question is repeated until the user + * does give a integer response. + * + * @param message The request to present to the user. + * @return The user's numeric response. + */ + int getNumber(String message) { + while (true) { + System.out.print(message); + try { + return scanner.nextInt(); + } + catch (InputMismatchException e) { + System.out.println("\"" + scanner.next() + "\" isn't a number!"); + } + } + } +``` + +Here is an example of how you can use this method: + +> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` + +### Structure of the solution + +* Project name: `Hammurabi` +* Package name: `hammurabi` +* Class names and method signatures: + * `class Hammurabi` + * `public static void main(String[] args)` + * Numerous other methods, as described above. + +The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. + +### Yo! Test it! + +You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! + +But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. + +### Credits + +Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml new file mode 100644 index 0000000..d789654 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + + io.zipcoder + MicroLabs-Loops + 1.0-SNAPSHOT + + + + + junit + junit + 4.13.2 + + + + + + 1.8 + 1.8 + + \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore new file mode 100644 index 0000000..a1c2a23 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore @@ -0,0 +1,23 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE new file mode 100644 index 0000000..22474e4 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Zip Code Wilmington Core + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md new file mode 100644 index 0000000..e4672c9 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md @@ -0,0 +1,228 @@ +# hamurabi +an ancient (in more ways than one) computer game (text) + +## General idea of the lab + +*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. + +Here are the standard instructions for the game: + +> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** +> +> * **Each person needs at least 20 bushels of grain per year to survive** +> * **Each person can farm at most 10 acres of land** +> * **It takes 2 bushels of grain to farm an acre of land** +> * **The market price for land fluctuates yearly** +> +> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** + +### Maven + +There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. + +### Details + +Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): + +```java +package hammurabi; // package declaration +import java.util.Random; // imports go here +import java.util.Scanner; + +public class Hammurabi { // must save in a file named Hammurabi.java + Random rand = new Random(); // this is an instance variable + Scanner scanner = new Scanner(System.in); + + public static void main(String\[\] args) { // required in every Java program + new Hammurabi().playGame(); + } + + void playGame() { + // declare local variables here: grain, population, etc. + // statements go after the declations + } + + //other methods go here +} +``` + +### Playing the game + +Here is what you start the game with: + +* 100 people +* 2800 bushels of grain in storage +* 1000 acres of land +* Land value is 19 bushels/acre + + +Each year, print out a summary similar to the following: + + O great Hammurabi! + You are in year 1 of your ten year rule. + In the previous year 0 people starved to death. + In the previous year 5 people entered the kingdom. + The population is now 100. + We harvested 3000 bushels at 3 bushels per acre. + Rats destroyed 200 bushels, leaving 2800 bushels in storage. + The city owns 1000 acres of land. + Land is currently worth 19 bushels per acre. + +The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. + +Here's what your `playGame` method needs to do each year, for up to 10 years: + +> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: +> +> `int askHowManyAcresToBuy(int price, int bushels)` +> +> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. +> +> ` +> int askHowManyAcresToSell(int acresOwned)` +> +> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. +> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. +> +> ` +> int askHowMuchGrainToFeedPeople(int bushels)` +> +> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. +> +> ` +> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` +> +> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. +> +> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) +> +> Then the method needs to determine: +> +> 1. If there is a plague, and how many people die from it. +> 2. How many people starved. +> 3. How many people came to the city. +> 4. How good the harvest is. +> 5. If you have a problem with rats, and how much grain they eat. +> 6. How much land costs (for deciding what to do next). +> +> These can all be local variables of your `playGame` method. +> +> Use the following methods, **in this order,** to make the necessary calculations: +> +> `int plagueDeaths(int population)` +> +> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). +> +> ` +> int starvationDeaths(int population, int bushelsFedToPeople)` +> +> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). +> +> ` +> boolean uprising(int population, int howManyPeopleStarved)` +> +> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) +> +> ` +> int immigrants(int population, int acresOwned, int grainInStorage)` +> +> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. +> +> ` +> int harvest(int acres, int bushelsUsedAsSeed)` +> +> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. +> +> ` +> int grainEatenByRats(int bushels)` +> +> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). +> +> ` +> int newCostOfLand()` +> +> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) + +Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. + +When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. + +When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. + +Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. + +All the required arithmetic in this program should be **integer**. You do not need doubles. + +### Urgent! + +> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. + +### Things you need to know: + +#### Random numbers + +To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: + +> `static Random rand = new Random();` + +To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as + +> `myNewNumber = rand.nextInt(5); +> if (rand.nextInt(100) < 15) { ... }` + +To do something that happens `p` percent of the time, use + +> `if (rand.nextInt(100) < p) { _...do something..._ }` + +#### Getting input + +To get a number from the player, add this method to your program: + +```java + /** + * Prints the given message (which should ask the user for some integral + * quantity), and returns the number entered by the user. If the user's + * response isn't an integer, the question is repeated until the user + * does give a integer response. + * + * @param message The request to present to the user. + * @return The user's numeric response. + */ + int getNumber(String message) { + while (true) { + System.out.print(message); + try { + return scanner.nextInt(); + } + catch (InputMismatchException e) { + System.out.println("\"" + scanner.next() + "\" isn't a number!"); + } + } + } +``` + +Here is an example of how you can use this method: + +> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` + +### Structure of the solution + +* Project name: `Hammurabi` +* Package name: `hammurabi` +* Class names and method signatures: + * `class Hammurabi` + * `public static void main(String[] args)` + * Numerous other methods, as described above. + +The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. + +### Yo! Test it! + +You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! + +But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. + +### Credits + +Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml new file mode 100644 index 0000000..d789654 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + + io.zipcoder + MicroLabs-Loops + 1.0-SNAPSHOT + + + + + junit + junit + 4.13.2 + + + + + + 1.8 + 1.8 + + \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore new file mode 100644 index 0000000..a1c2a23 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore @@ -0,0 +1,23 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE new file mode 100644 index 0000000..22474e4 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Zip Code Wilmington Core + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md new file mode 100644 index 0000000..e4672c9 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md @@ -0,0 +1,228 @@ +# hamurabi +an ancient (in more ways than one) computer game (text) + +## General idea of the lab + +*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. + +Here are the standard instructions for the game: + +> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** +> +> * **Each person needs at least 20 bushels of grain per year to survive** +> * **Each person can farm at most 10 acres of land** +> * **It takes 2 bushels of grain to farm an acre of land** +> * **The market price for land fluctuates yearly** +> +> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** + +### Maven + +There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. + +### Details + +Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): + +```java +package hammurabi; // package declaration +import java.util.Random; // imports go here +import java.util.Scanner; + +public class Hammurabi { // must save in a file named Hammurabi.java + Random rand = new Random(); // this is an instance variable + Scanner scanner = new Scanner(System.in); + + public static void main(String\[\] args) { // required in every Java program + new Hammurabi().playGame(); + } + + void playGame() { + // declare local variables here: grain, population, etc. + // statements go after the declations + } + + //other methods go here +} +``` + +### Playing the game + +Here is what you start the game with: + +* 100 people +* 2800 bushels of grain in storage +* 1000 acres of land +* Land value is 19 bushels/acre + + +Each year, print out a summary similar to the following: + + O great Hammurabi! + You are in year 1 of your ten year rule. + In the previous year 0 people starved to death. + In the previous year 5 people entered the kingdom. + The population is now 100. + We harvested 3000 bushels at 3 bushels per acre. + Rats destroyed 200 bushels, leaving 2800 bushels in storage. + The city owns 1000 acres of land. + Land is currently worth 19 bushels per acre. + +The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. + +Here's what your `playGame` method needs to do each year, for up to 10 years: + +> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: +> +> `int askHowManyAcresToBuy(int price, int bushels)` +> +> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. +> +> ` +> int askHowManyAcresToSell(int acresOwned)` +> +> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. +> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. +> +> ` +> int askHowMuchGrainToFeedPeople(int bushels)` +> +> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. +> +> ` +> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` +> +> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. +> +> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) +> +> Then the method needs to determine: +> +> 1. If there is a plague, and how many people die from it. +> 2. How many people starved. +> 3. How many people came to the city. +> 4. How good the harvest is. +> 5. If you have a problem with rats, and how much grain they eat. +> 6. How much land costs (for deciding what to do next). +> +> These can all be local variables of your `playGame` method. +> +> Use the following methods, **in this order,** to make the necessary calculations: +> +> `int plagueDeaths(int population)` +> +> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). +> +> ` +> int starvationDeaths(int population, int bushelsFedToPeople)` +> +> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). +> +> ` +> boolean uprising(int population, int howManyPeopleStarved)` +> +> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) +> +> ` +> int immigrants(int population, int acresOwned, int grainInStorage)` +> +> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. +> +> ` +> int harvest(int acres, int bushelsUsedAsSeed)` +> +> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. +> +> ` +> int grainEatenByRats(int bushels)` +> +> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). +> +> ` +> int newCostOfLand()` +> +> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) + +Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. + +When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. + +When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. + +Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. + +All the required arithmetic in this program should be **integer**. You do not need doubles. + +### Urgent! + +> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. + +### Things you need to know: + +#### Random numbers + +To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: + +> `static Random rand = new Random();` + +To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as + +> `myNewNumber = rand.nextInt(5); +> if (rand.nextInt(100) < 15) { ... }` + +To do something that happens `p` percent of the time, use + +> `if (rand.nextInt(100) < p) { _...do something..._ }` + +#### Getting input + +To get a number from the player, add this method to your program: + +```java + /** + * Prints the given message (which should ask the user for some integral + * quantity), and returns the number entered by the user. If the user's + * response isn't an integer, the question is repeated until the user + * does give a integer response. + * + * @param message The request to present to the user. + * @return The user's numeric response. + */ + int getNumber(String message) { + while (true) { + System.out.print(message); + try { + return scanner.nextInt(); + } + catch (InputMismatchException e) { + System.out.println("\"" + scanner.next() + "\" isn't a number!"); + } + } + } +``` + +Here is an example of how you can use this method: + +> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` + +### Structure of the solution + +* Project name: `Hammurabi` +* Package name: `hammurabi` +* Class names and method signatures: + * `class Hammurabi` + * `public static void main(String[] args)` + * Numerous other methods, as described above. + +The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. + +### Yo! Test it! + +You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! + +But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. + +### Credits + +Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml new file mode 100644 index 0000000..d789654 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + + io.zipcoder + MicroLabs-Loops + 1.0-SNAPSHOT + + + + + junit + junit + 4.13.2 + + + + + + 1.8 + 1.8 + + \ No newline at end of file From 0b594e7300b12621926fb1d3d089f17dc28424bc Mon Sep 17 00:00:00 2001 From: Hanquan Liu Date: Sun, 13 Nov 2022 07:46:28 -0500 Subject: [PATCH 16/19] seasoning --- docs/matuszek/Hammurabi.java | 29 ++++++++++++------- docs/matuszek/normalEvents.java | 9 ++++++ .../classes/target/classes/.idea/.gitignore | 3 ++ .../classes/target/classes/.idea/compiler.xml | 16 ++++++++++ .../target/classes/.idea/jarRepositories.xml | 20 +++++++++++++ .../libraries/Maven__junit_junit_4_13_2.xml | 13 +++++++++ .../Maven__org_hamcrest_hamcrest_core_1_3.xml | 13 +++++++++ .../classes/target/classes/.idea/modules.xml | 8 +++++ target/classes/target/classes/.idea/vcs.xml | 6 ++++ target/classes/target/classes/Hamurabi.iml | 15 ++++++++++ 10 files changed, 121 insertions(+), 11 deletions(-) create mode 100644 docs/matuszek/normalEvents.java create mode 100644 target/classes/target/classes/.idea/.gitignore create mode 100644 target/classes/target/classes/.idea/compiler.xml create mode 100644 target/classes/target/classes/.idea/jarRepositories.xml create mode 100644 target/classes/target/classes/.idea/libraries/Maven__junit_junit_4_13_2.xml create mode 100644 target/classes/target/classes/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml create mode 100644 target/classes/target/classes/.idea/modules.xml create mode 100644 target/classes/target/classes/.idea/vcs.xml create mode 100644 target/classes/target/classes/Hamurabi.iml diff --git a/docs/matuszek/Hammurabi.java b/docs/matuszek/Hammurabi.java index efde624..ba26a5d 100644 --- a/docs/matuszek/Hammurabi.java +++ b/docs/matuszek/Hammurabi.java @@ -1,21 +1,27 @@ package hammurabi.docs.matuszek;//package Hammurabi; import java.util.Random; // imports go here import java.util.Scanner; +import hammurabi.docs.matuszek.normalEvents.*; public class Hammurabi { // must save in a file named Hammurabi.java Random rand = new Random(); // this is an instance variable Scanner scanner = new Scanner(System.in); - + int year = 0; boolean gameOver = false; int harvest = 0; int ratEaten = 0; int starving = 0; int immigrants = 0; - public int people; - public int bushelsOfGrain; - public int acres; - public int landValue; + public int people = 100; + public int bushelsOfGrain = 2800; + public int acres = 1000; + public int landValue = 25; + + int peopleDeath = 0; + int plagueDeath = 0; + + public Hammurabi(int peo,int bus, int acr, int lan){ @@ -31,15 +37,16 @@ public Hammurabi(int peo,int bus, int acr, int lan){ public static void main(String[] args) { // required in every Java program // - Hammurabi h = new Hammurabi(100,2800,1000,19); + Hammurabi h = new Hammurabi( 100,2800,1000,19); + h.playGame(); } void playGame() { // declare local variables here: grain, population, etc. // statements go after the declations - int people=100; - int bushelsOfGrain =2800; - int acres=1000; - int landValue=19; + while(!gameOver){ + this.year += 1; + normalEvents.printStatus(); + } } //other methods go here int askHowManyAcresToBuy(int price, int bushels){ @@ -103,7 +110,7 @@ int askHowManyAcresToPlant(int acresOwned, int population, int bushels){ int plagueDeaths(int population){ int plaDea = rand.nextInt(100)+1; if(plaDea<=15) { - return population / 2; + return this.peopleDeath = population / 2; }else return 0; } diff --git a/docs/matuszek/normalEvents.java b/docs/matuszek/normalEvents.java new file mode 100644 index 0000000..2424ade --- /dev/null +++ b/docs/matuszek/normalEvents.java @@ -0,0 +1,9 @@ +package hammurabi.docs.matuszek; +import hammurabi.docs.matuszek.Hammurabi; + +public class normalEvents { + + public static void printStatus(){ + System.out.println("Year = " + year); + } +} diff --git a/target/classes/target/classes/.idea/.gitignore b/target/classes/target/classes/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/target/classes/target/classes/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/target/classes/target/classes/.idea/compiler.xml b/target/classes/target/classes/.idea/compiler.xml new file mode 100644 index 0000000..639314b --- /dev/null +++ b/target/classes/target/classes/.idea/compiler.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/target/classes/target/classes/.idea/jarRepositories.xml b/target/classes/target/classes/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/target/classes/target/classes/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/target/classes/target/classes/.idea/libraries/Maven__junit_junit_4_13_2.xml b/target/classes/target/classes/.idea/libraries/Maven__junit_junit_4_13_2.xml new file mode 100644 index 0000000..606c352 --- /dev/null +++ b/target/classes/target/classes/.idea/libraries/Maven__junit_junit_4_13_2.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/target/classes/target/classes/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml b/target/classes/target/classes/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml new file mode 100644 index 0000000..f58bbc1 --- /dev/null +++ b/target/classes/target/classes/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/target/classes/target/classes/.idea/modules.xml b/target/classes/target/classes/.idea/modules.xml new file mode 100644 index 0000000..16ae36c --- /dev/null +++ b/target/classes/target/classes/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/target/classes/target/classes/.idea/vcs.xml b/target/classes/target/classes/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/target/classes/target/classes/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/target/classes/target/classes/Hamurabi.iml b/target/classes/target/classes/Hamurabi.iml new file mode 100644 index 0000000..903044c --- /dev/null +++ b/target/classes/target/classes/Hamurabi.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file From 6a46483c61705ef123099b76077ff1a9edccfd81 Mon Sep 17 00:00:00 2001 From: Hanquan Liu Date: Sun, 13 Nov 2022 10:31:35 -0500 Subject: [PATCH 17/19] chopchop --- .idea/misc.xml | 2 +- target/classes/.idea/misc.xml | 2 +- .../target/classes/target/classes/.gitignore | 23 ++ .../target/classes/target/classes/LICENSE | 21 ++ .../target/classes/target/classes/README.md | 228 ++++++++++++++++++ .../target/classes/target/classes/pom.xml | 25 ++ 6 files changed, 299 insertions(+), 2 deletions(-) create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md create mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml diff --git a/.idea/misc.xml b/.idea/misc.xml index 213cea6..bcd41e5 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -7,7 +7,7 @@ - + \ No newline at end of file diff --git a/target/classes/.idea/misc.xml b/target/classes/.idea/misc.xml index 213cea6..bcd41e5 100644 --- a/target/classes/.idea/misc.xml +++ b/target/classes/.idea/misc.xml @@ -7,7 +7,7 @@ - + \ No newline at end of file diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore new file mode 100644 index 0000000..a1c2a23 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore @@ -0,0 +1,23 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE new file mode 100644 index 0000000..22474e4 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Zip Code Wilmington Core + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md new file mode 100644 index 0000000..e4672c9 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md @@ -0,0 +1,228 @@ +# hamurabi +an ancient (in more ways than one) computer game (text) + +## General idea of the lab + +*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. + +Here are the standard instructions for the game: + +> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** +> +> * **Each person needs at least 20 bushels of grain per year to survive** +> * **Each person can farm at most 10 acres of land** +> * **It takes 2 bushels of grain to farm an acre of land** +> * **The market price for land fluctuates yearly** +> +> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** + +### Maven + +There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. + +### Details + +Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): + +```java +package hammurabi; // package declaration +import java.util.Random; // imports go here +import java.util.Scanner; + +public class Hammurabi { // must save in a file named Hammurabi.java + Random rand = new Random(); // this is an instance variable + Scanner scanner = new Scanner(System.in); + + public static void main(String\[\] args) { // required in every Java program + new Hammurabi().playGame(); + } + + void playGame() { + // declare local variables here: grain, population, etc. + // statements go after the declations + } + + //other methods go here +} +``` + +### Playing the game + +Here is what you start the game with: + +* 100 people +* 2800 bushels of grain in storage +* 1000 acres of land +* Land value is 19 bushels/acre + + +Each year, print out a summary similar to the following: + + O great Hammurabi! + You are in year 1 of your ten year rule. + In the previous year 0 people starved to death. + In the previous year 5 people entered the kingdom. + The population is now 100. + We harvested 3000 bushels at 3 bushels per acre. + Rats destroyed 200 bushels, leaving 2800 bushels in storage. + The city owns 1000 acres of land. + Land is currently worth 19 bushels per acre. + +The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. + +Here's what your `playGame` method needs to do each year, for up to 10 years: + +> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: +> +> `int askHowManyAcresToBuy(int price, int bushels)` +> +> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. +> +> ` +> int askHowManyAcresToSell(int acresOwned)` +> +> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. +> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. +> +> ` +> int askHowMuchGrainToFeedPeople(int bushels)` +> +> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. +> +> ` +> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` +> +> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. +> +> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) +> +> Then the method needs to determine: +> +> 1. If there is a plague, and how many people die from it. +> 2. How many people starved. +> 3. How many people came to the city. +> 4. How good the harvest is. +> 5. If you have a problem with rats, and how much grain they eat. +> 6. How much land costs (for deciding what to do next). +> +> These can all be local variables of your `playGame` method. +> +> Use the following methods, **in this order,** to make the necessary calculations: +> +> `int plagueDeaths(int population)` +> +> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). +> +> ` +> int starvationDeaths(int population, int bushelsFedToPeople)` +> +> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). +> +> ` +> boolean uprising(int population, int howManyPeopleStarved)` +> +> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) +> +> ` +> int immigrants(int population, int acresOwned, int grainInStorage)` +> +> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. +> +> ` +> int harvest(int acres, int bushelsUsedAsSeed)` +> +> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. +> +> ` +> int grainEatenByRats(int bushels)` +> +> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). +> +> ` +> int newCostOfLand()` +> +> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) + +Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. + +When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. + +When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. + +Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. + +All the required arithmetic in this program should be **integer**. You do not need doubles. + +### Urgent! + +> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. + +### Things you need to know: + +#### Random numbers + +To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: + +> `static Random rand = new Random();` + +To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as + +> `myNewNumber = rand.nextInt(5); +> if (rand.nextInt(100) < 15) { ... }` + +To do something that happens `p` percent of the time, use + +> `if (rand.nextInt(100) < p) { _...do something..._ }` + +#### Getting input + +To get a number from the player, add this method to your program: + +```java + /** + * Prints the given message (which should ask the user for some integral + * quantity), and returns the number entered by the user. If the user's + * response isn't an integer, the question is repeated until the user + * does give a integer response. + * + * @param message The request to present to the user. + * @return The user's numeric response. + */ + int getNumber(String message) { + while (true) { + System.out.print(message); + try { + return scanner.nextInt(); + } + catch (InputMismatchException e) { + System.out.println("\"" + scanner.next() + "\" isn't a number!"); + } + } + } +``` + +Here is an example of how you can use this method: + +> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` + +### Structure of the solution + +* Project name: `Hammurabi` +* Package name: `hammurabi` +* Class names and method signatures: + * `class Hammurabi` + * `public static void main(String[] args)` + * Numerous other methods, as described above. + +The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. + +### Yo! Test it! + +You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! + +But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. + +### Credits + +Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) + diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml new file mode 100644 index 0000000..d789654 --- /dev/null +++ b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + + io.zipcoder + MicroLabs-Loops + 1.0-SNAPSHOT + + + + + junit + junit + 4.13.2 + + + + + + 1.8 + 1.8 + + \ No newline at end of file From c4c1a49d7c45a4496541d01e6403716414a1116f Mon Sep 17 00:00:00 2001 From: Hanquan Liu Date: Sun, 13 Nov 2022 10:35:38 -0500 Subject: [PATCH 18/19] cleaning --- docs/matuszek/Hammurabi.java | 2 +- docs/matuszek/disasterEvents.java | 4 ++++ docs/matuszek/normalEvents.java | 4 +--- 3 files changed, 6 insertions(+), 4 deletions(-) create mode 100644 docs/matuszek/disasterEvents.java diff --git a/docs/matuszek/Hammurabi.java b/docs/matuszek/Hammurabi.java index ba26a5d..ccc544b 100644 --- a/docs/matuszek/Hammurabi.java +++ b/docs/matuszek/Hammurabi.java @@ -45,7 +45,7 @@ void playGame() { // statements go after the declations while(!gameOver){ this.year += 1; - normalEvents.printStatus(); + } } //other methods go here diff --git a/docs/matuszek/disasterEvents.java b/docs/matuszek/disasterEvents.java new file mode 100644 index 0000000..150b13f --- /dev/null +++ b/docs/matuszek/disasterEvents.java @@ -0,0 +1,4 @@ +package hammurabi.docs.matuszek; + +public class disasterEvents { +} diff --git a/docs/matuszek/normalEvents.java b/docs/matuszek/normalEvents.java index 2424ade..734e8cb 100644 --- a/docs/matuszek/normalEvents.java +++ b/docs/matuszek/normalEvents.java @@ -3,7 +3,5 @@ public class normalEvents { - public static void printStatus(){ - System.out.println("Year = " + year); - } + } From 654028babd0d86a47e91f6767ee5bf9a87e79311 Mon Sep 17 00:00:00 2001 From: Hanquan Liu Date: Sun, 13 Nov 2022 16:38:03 -0500 Subject: [PATCH 19/19] restrutured, tests pass --- .idea/uiDesigner.xml | 124 ++++++ docs/matuszek/Hammurabi.java | 407 +++++++----------- docs/matuszek/HammurabiTest.java | 27 +- docs/matuszek/disasterEvents.java | 58 +++ docs/matuszek/gameStart.java | 15 + docs/matuszek/normalEvents.java | 152 +++++++ .../target/classes/target/classes/.gitignore | 23 - .../target/classes/target/classes/LICENSE | 21 - .../target/classes/target/classes/README.md | 228 ---------- .../target/classes/target/classes/pom.xml | 25 -- 10 files changed, 520 insertions(+), 560 deletions(-) create mode 100644 .idea/uiDesigner.xml create mode 100644 docs/matuszek/gameStart.java delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md delete mode 100644 target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/docs/matuszek/Hammurabi.java b/docs/matuszek/Hammurabi.java index 666d788..a00e317 100644 --- a/docs/matuszek/Hammurabi.java +++ b/docs/matuszek/Hammurabi.java @@ -2,355 +2,258 @@ import java.util.Random; // imports go here import java.util.Scanner; import hammurabi.docs.matuszek.normalEvents.*; +import hammurabi.docs.matuszek.disasterEvents.*; public class Hammurabi { // must save in a file named Hammurabi.java Random rand = new Random(); // this is an instance variable - Scanner scanner = new Scanner(System.in); + static Scanner scanner = new Scanner(System.in); + + private static int year = 0; + private static boolean gameOver = false; + private static int harvest = 0; + private static int ratEaten = 0; + private static int starving = 0; + private static int immigrants = 0; + private static int people = 100; + private static int bushelsOfGrain = 2800; + private static int acres = 1000; + private static int landValue = 25; + private static int bushelsPerAcre = 0; + private static int peopleDeath = 0; + private static int starvationPeopleDeath = 0; + private static int acresToBuy =0; + private static int acresToSell =0; + private static int grainToFeed =0; + private static int acresToPlant = 0; + private static int plaguePeopleDeath =0; + private static boolean uprisingPeople =false; + private static int immigrantsPeople = 0; + private static int harvestPeople = 0; + private static int grainEatenByRatsPeople =0; + private static int newCostOfLandPeople =0; - int year = 0; - boolean gameOver = false; - int harvest = 0; - int ratEaten = 0; - int starving = 0; - int immigrants = 0; - public int people = 100; - public int bushelsOfGrain = 2800; - public int acres = 1000; - public int landValue = 25; - - int peopleDeath = 0; - int plagueDeath = 0; public Hammurabi(int peo,int bus, int acr, int lan){ - this.people=peo; - this.bushelsOfGrain=bus; - this.acres=acr; - this.landValue=lan; - - /* - int people; - int bushelsOfGrain; - int acres; - int landValue; - int bushelsPerAcre; - - - public Hammurabi(int peo, int bus, int acr, int lan) { - this.people = peo; - this.bushelsOfGrain = bus; - this.acres = acr; - this.landValue = lan; - */ - - } - - - public static void main(String[] args) { // required in every Java program - - - new Hammurabi(100, 2800, 1000, 19).playGame(); + people=peo; + bushelsOfGrain=bus; + acres=acr; + landValue=lan; } - void playGame() { - // declare local variables here: grain, population, etc. - // statements go after the declations - - int people = 100; - int bushelsOfGrain = 2800; - int acres = 1000; - int landValue = 19; - int acresToBuy =0; - int acresToSell =0; - int grainToFeed =0; - int acresToPlant = 0; - int plaguePeopleDeath =0; - int starvationPeopleDeath=0; - boolean uprisingPeople =false; - int immigrantsPeople = 0; - int harvestPeople = 0; - int grainEatenByRatsPeople =0; - int newCostOfLandPeople =0; - for (int i = 1; i < 11; i++) { - System.out.println("O great Hammurabi!"); - System.out.println("You are in year " + i + " of your ten year rule."); - System.out.println("In the previous year " + starvationPeopleDeath + " people starved to death."); - System.out.println("the previous year " + this.getImmigrants() + " people entered the kingdom."); - System.out.println("The population is now "+this.getPeople()+" ."); - System.out.println("We harvested "+this.getHarvest()+ " bushels at "+this.getBushelsPerAcre()+ " bushels per acre."); - System.out.println("Rats destroyed "+ this.getRatEaten()+" bushels, leaving "+this.getBushelsOfGrain()+" bushels in storage."); - System.out.println("The city owns "+this.getAcres()+ " acres of land."); - System.out.println("Land is currently worth "+ this.getLandValue()+" bushels per acre.\n"); - acresToBuy=this.askHowManyAcresToBuy(this.getLandValue(), this.getBushelsOfGrain()); - if(acresToBuy==0){ - acresToSell=this.askHowManyAcresToSell(this.getAcres()); + public void playGame() { - } - grainToFeed=askHowMuchGrainToFeedPeople(this.bushelsOfGrain); - acresToPlant=askHowManyAcresToPlant(this.acres,this.people, this.bushelsOfGrain); - plaguePeopleDeath = plagueDeaths(this.people); - starvationPeopleDeath = starvationDeaths(this.people, grainToFeed); - uprisingPeople = uprising(this.people, starvationPeopleDeath); + while (!gameOver) { + year += 1; + normalEvents.printStatus(); + normalEvents.playerTypeIn(); + disasterEvents.disasterCal(); if (uprisingPeople) { System.out.println("Too many people starved to death. Game Over!"); break; } - if(starvationPeopleDeath>0){ - immigrantsPeople = immigrants(this.people, this.acres, this.bushelsOfGrain); + if(starvationPeopleDeath > 0){ + immigrantsPeople = normalEvents.immigrants(people, acres, bushelsOfGrain); + } + normalEvents.nextCal(); + if(year == 10){ + gameOver = true; } - harvestPeople = harvest(acresToPlant, this.bushelsOfGrain); - grainEatenByRatsPeople =grainEatenByRats(this.bushelsOfGrain); - newCostOfLandPeople =newCostOfLand(); - } - - } //other methods go here - int askHowManyAcresToBuy(int price, int bushels) { - System.out.println("How many acres do you wish to buy?"); - int in = scanner.nextInt(); - while (in * price > bushels) { - System.out.println("Hammurabi: Think again. You have only " + bushels + " of grain. "); - System.out.println("Re-enter the numbers of acres you wish to buy"); - in = scanner.nextInt(); - } - this.bushelsOfGrain-=in*price; - this.acres+=in; - return in; - } - //Asks the player how many acres of land to buy, and returns that number. - // You must have enough grain to pay for your purchase. - int askHowManyAcresToSell(int acresOwned) { - System.out.println("How many acres do you wish to sell?"); - int in = scanner.nextInt(); - while (in > acresOwned) { - System.out.println("Hammurabi: Thank again. You have only " + acresOwned + " of grain. "); - System.out.println("Re-enter the numbers of acres you wish to sell: "); - in = scanner.nextInt(); - } - this.bushelsOfGrain+=in*this.landValue; - this.acres-=in; - return in; - } - //Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. - //Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. - int askHowMuchGrainToFeedPeople(int bushels) { - System.out.println("How many bushels do you wish to feed your people?"); - int in = scanner.nextInt(); - while (in > bushels ) { - System.out.println("Hammurabi: Think again. You have only " + bushelsOfGrain + " of grain."); - System.out.println("Re-enter the numbers of bushels you wish to feed people: "); - in = scanner.nextInt(); - } - this.bushelsOfGrain-=in; - return in; + public static int getYear() { + return year; } - //Ask the player how much grain to feed people, - // and returns that number. You can't feed them more grain than you have. - // You can feed them more than they need to survive. - - int askHowManyAcresToPlant(int acresOwned, int population, int bushels) { - System.out.println("How many acres do you wish to plant with seed?"); - int in = scanner.nextInt(); - while (in > acresOwned || in > bushels || in>population*10) { - System.out.println("Hammurabi: Think again. You have only " + bushelsOfGrain + " of grain. "); - System.out.println("Re-enter the numbers of acres you wish to plant with seed: "); - in = scanner.nextInt(); - } - this.bushelsOfGrain-= in; - return in; + public static void setYear(int year) { + Hammurabi.year = year; } - //Ask the player how many acres to plant with grain, and returns that number. - // You must have enough acres, enough grain, and enough people to do the planting. - // Any grain left over goes into storage for next year. - - int plagueDeaths(int population){ - int plaDea = rand.nextInt(100)+1; - if(plaDea<=15) { - return this.peopleDeath = population / 2; - }else return 0; + public static boolean isGameOver() { + return gameOver; + } - /* - int plagueDeaths(int population) { - int plaDea = rand.nextInt(100) + 1; - if (plaDea <= 15) { - return population / 2; - } else return 0; - */ + public static void setGameOver(boolean gameOver) { + Hammurabi.gameOver = gameOver; + } + public static int getHarvest() { + return harvest; } + public static void setHarvest(int harvest) { + Hammurabi.harvest = harvest; + } - // Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. - // Return the number of plague deaths (possibly zero). - int starvationDeaths(int population, int bushelsFedToPeople) { - int numberOfStar = bushelsFedToPeople / 20 - population; - if (numberOfStar >= 0) { - return 0; - } else { - this.people -= Math.abs(numberOfStar); - return Math.abs(numberOfStar); - } + public static int getRatEaten() { + return ratEaten; } - // Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, - // but the grain is still gone. You don't get any benefit from having happy subjects. - // Return the number of deaths from starvation (possibly zero). - boolean uprising(int population, int howManyPeopleStarved) { + public static void setRatEaten(int ratEaten) { + Hammurabi.ratEaten = ratEaten; + } - double starvingRate = (double) howManyPeopleStarved / population; - if (starvingRate > 0.450) { - this.gameOver = true; - } else if (starvingRate <= 0.450) { - this.gameOver = false; - } + public static int getStarving() { + return starving; + } - return this.gameOver; + public static void setStarving(int starving) { + Hammurabi.starving = starving; + } + public static int getImmigrants() { + return immigrants; + } + public static void setImmigrants(int immigrants) { + Hammurabi.immigrants = immigrants; } - // Return true if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) + public static int getPeople() { + return people; + } - int immigrants(int population, int acresOwned, int grainInStorage) { + public static void setPeople(int people) { + Hammurabi.people = people; + } - if (starving == 0) { - this.immigrants = (20 * acresOwned + grainInStorage) / (100 * population) + 1; - } - this.people +=immigrants; - return immigrants; - /* - if(starvationDeaths(population,grainInStorage)>0){ - return 0; - }else{ - return (20*acresOwned+grainInStorage)/(100*population)+1; - } - */ + public static int getBushelsOfGrain() { + return bushelsOfGrain; + } + public static void setBushelsOfGrain(int bushelsOfGrain) { + Hammurabi.bushelsOfGrain = bushelsOfGrain; } - //Nobody will come to the city if people are starving (so don't call this method). - // If everyone is well fed, compute how many people come to the city as: - // (20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1. + public static int getAcres() { + return acres; + } - int harvest(int acres, int bushelsUsedAsSeed) { + public static void setAcres(int acres) { + Hammurabi.acres = acres; + } - this.bushelsPerAcre = rand.nextInt(6) + 1; - this.harvest = this.bushelsPerAcre * acres; - this.bushelsOfGrain=this.bushelsOfGrain-bushelsUsedAsSeed+this.harvest; - return harvest; + public static int getLandValue() { + return landValue; + } + public static void setLandValue(int landValue) { + Hammurabi.landValue = landValue; } - //Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. - // (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. + public static int getBushelsPerAcre() { + return bushelsPerAcre; + } - int grainEatenByRats(int bushels) { - boolean ratInfestation = false; - int ratEaten = 0; - if (rand.nextFloat() * 100 <= 40) { - ratInfestation = true; - } - if (ratInfestation) { - ratEaten = bushels * (rand.nextInt(31 - 10) + 10) / 100; - } - this.ratEaten = ratEaten; - return this.ratEaten; + public static void setBushelsPerAcre(int bushelsPerAcre) { + Hammurabi.bushelsPerAcre = bushelsPerAcre; } - //There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). + public static int getPeopleDeath() { + return peopleDeath; + } - int newCostOfLand() { - int min = 17, max = 24; - this.landValue = rand.nextInt(max - min) + min; - return this.landValue; + public static void setPeopleDeath(int peopleDeath) { + Hammurabi.peopleDeath = peopleDeath; } - public int getAcres() { - return acres; + public static int getStarvationPeopleDeath() { + return starvationPeopleDeath; } - public void setAcres(int acres) { - this.acres = acres; + public static void setStarvationPeopleDeath(int starvationPeopleDeath) { + Hammurabi.starvationPeopleDeath = starvationPeopleDeath; + } + public static int getAcresToBuy() { + return acresToBuy; } - public int getBushelsOfGrain() { - return bushelsOfGrain; + public static void setAcresToBuy(int acresToBuy) { + Hammurabi.acresToBuy = acresToBuy; } - public void setBushelsOfGrain(int bushelsOfGrain) { - this.bushelsOfGrain = bushelsOfGrain; + public static int getAcresToSell() { + return acresToSell; } - public int getHarvest() { - return harvest; + public static void setAcresToSell(int acresToSell) { + Hammurabi.acresToSell = acresToSell; + } + public static int getGrainToFeed() { + return grainToFeed; } - public void setHarvest(int harvest) { - this.harvest = harvest; + public static void setGrainToFeed(int grainToFeed) { + Hammurabi.grainToFeed = grainToFeed; } - public int getLandValue() { - return landValue; + public static int getAcresToPlant() { + return acresToPlant; } - public void setLandValue(int landValue) { - this.landValue = landValue; + public static void setAcresToPlant(int acresToPlant) { + Hammurabi.acresToPlant = acresToPlant; } - public int getImmigrants() { - return immigrants; + public static int getPlaguePeopleDeath() { + return plaguePeopleDeath; } - public void setImmigrants(int immigrants) { - this.immigrants = immigrants; + public static void setPlaguePeopleDeath(int plaguePeopleDeath) { + Hammurabi.plaguePeopleDeath = plaguePeopleDeath; + } + public static boolean isUprisingPeople() { + return uprisingPeople; } - public int getPeople() { - return people; + public static void setUprisingPeople(boolean uprisingPeople) { + Hammurabi.uprisingPeople = uprisingPeople; + } + public static int getImmigrantsPeople() { + return immigrantsPeople; } - public void setPeople(int people) { - this.people = people; + public static void setImmigrantsPeople(int immigrantsPeople) { + Hammurabi.immigrantsPeople = immigrantsPeople; } - public int getStarving() { - return starving; + public static int getHarvestPeople() { + return harvestPeople; } - public void setStarving(int starving) { - this.starving = starving; + public static void setHarvestPeople(int harvestPeople) { + Hammurabi.harvestPeople = harvestPeople; } - public int getRatEaten() { - return ratEaten; + public static int getGrainEatenByRatsPeople() { + return grainEatenByRatsPeople; } - public void setRatEaten(int ratEaten) { - this.ratEaten = ratEaten; + public static void setGrainEatenByRatsPeople(int grainEatenByRatsPeople) { + Hammurabi.grainEatenByRatsPeople = grainEatenByRatsPeople; } - public int getBushelsPerAcre() { - return bushelsPerAcre; + public static int getNewCostOfLandPeople() { + return newCostOfLandPeople; } - public void setBushelsPerAcre(int bushelsPerAcre) { - this.bushelsPerAcre = bushelsPerAcre; + public static void setNewCostOfLandPeople(int newCostOfLandPeople) { + Hammurabi.newCostOfLandPeople = newCostOfLandPeople; } + + } diff --git a/docs/matuszek/HammurabiTest.java b/docs/matuszek/HammurabiTest.java index 1a41166..1887863 100644 --- a/docs/matuszek/HammurabiTest.java +++ b/docs/matuszek/HammurabiTest.java @@ -1,6 +1,7 @@ package hammurabi.docs.matuszek; import static org.junit.Assert.*; +import hammurabi.docs.matuszek.disasterEvents.*; import org.junit.Before; import org.junit.Test; @@ -8,6 +9,8 @@ public class HammurabiTest { Hammurabi ham; + disasterEvents disa; + normalEvents nor; boolean about(double expected, double actual) { return actual > 0.90 * expected && actual < 1.10 * expected; @@ -16,13 +19,15 @@ boolean about(double expected, double actual) { @Before public void setUp() throws Exception { ham = new Hammurabi(100,2800,1000,19); + disa = new disasterEvents(); + nor = new normalEvents(); } @Test public final void testPlagueDeaths1() { int number_of_plagues = 0; for (int i = 0; i < 10000; i++) { - int deaths = ham.plagueDeaths(100); + int deaths = disa.plagueDeaths(100); if (deaths > 0) { number_of_plagues += 1; } @@ -36,7 +41,7 @@ public final void testPlagueDeaths1() { public final void testPlagueDeaths2() { int deaths = 0; for (int i = 0; i < 10000; i++) { - deaths = ham.plagueDeaths(100); + deaths = disa.plagueDeaths(100); if (deaths > 0) break; } assertEquals("In a plague, " + deaths + "% of your people die, not 50%.", @@ -45,9 +50,9 @@ public final void testPlagueDeaths2() { @Test public final void testStarvationDeaths() { - int deaths = ham.starvationDeaths(100, 1639); + int deaths = disa.starvationDeaths(100, 1639); assertEquals("Wrong number of starvations deaths.", 19, deaths); - deaths = ham.starvationDeaths(100, 2500); + deaths = disa.starvationDeaths(100, 2500); if (deaths < 0) { fail("You starved a negative number of people!"); } @@ -55,13 +60,13 @@ public final void testStarvationDeaths() { @Test public final void testUprising() { - assertTrue("Should have had an uprising!", ham.uprising(1000, 451)); - assertFalse("Should not have had an uprising!", ham.uprising(1000, 449)); + assertTrue("Should have had an uprising!", disa.uprising(1000, 451)); + assertFalse("Should not have had an uprising!", disa.uprising(1000, 449)); } @Test public final void testImmigrants() { - int imm = ham.immigrants(10, 1200, 500); + int imm = nor.immigrants(10, 1200, 500); assertEquals("Wrong number of immigrants.", 25, imm); } @@ -69,7 +74,7 @@ public final void testImmigrants() { public final void testHarvest() { int[] yield = new int[7]; for (int i = 0; i < 1000; i++) { - int harvest = ham.harvest(1,1); + int harvest = nor.harvest(1,1); assertTrue("Illegal harvest per acre: " + harvest, harvest > 0 && harvest <= 6); yield[harvest] += 1; } @@ -82,7 +87,7 @@ public final void testHarvest() { public final void testGrainEatenByRats1() { int infestations = 0; for (int i = 0; i < 1000; i++) { - int eaten = ham.grainEatenByRats(100); + int eaten = nor.grainEatenByRats(100); if (eaten > 0) { infestations += 1; } @@ -97,7 +102,7 @@ public final void testGrainEatenByRats2() { int percent = 0; int[] counts = new int[31]; for (int i = 0; i < 10000; i++) { - percent = ham.grainEatenByRats(100); + percent = nor.grainEatenByRats(100); if (percent == 0) continue; counts[percent] += 1; assertTrue("Rats ate " + percent + "% of your grain, not 10% to 30%.", @@ -112,7 +117,7 @@ public final void testGrainEatenByRats2() { public final void testNewCostOfLand() { int[] cost = new int[24]; for (int i = 0; i < 1000; i++) { - int price = ham.newCostOfLand(); + int price = nor.newCostOfLand(); assertTrue("Illegal cost of land: " + price, price >= 17 && price <= 23); cost[price] += 1; } diff --git a/docs/matuszek/disasterEvents.java b/docs/matuszek/disasterEvents.java index 150b13f..841d563 100644 --- a/docs/matuszek/disasterEvents.java +++ b/docs/matuszek/disasterEvents.java @@ -1,4 +1,62 @@ package hammurabi.docs.matuszek; +import java.util.Random; + public class disasterEvents { + + public disasterEvents(){} + static Random rand = new Random(); // this is an instance variable + public static void disasterCal(){ + Hammurabi.setPlaguePeopleDeath( plagueDeaths(Hammurabi.getPeople())); + Hammurabi.setStarvationPeopleDeath( starvationDeaths(Hammurabi.getPeople(), Hammurabi.getGrainToFeed())); + Hammurabi.setUprisingPeople(uprising(Hammurabi.getPeople(), Hammurabi.getStarvationPeopleDeath())); + } + + static int plagueDeaths(int population){ + int plaDea = rand.nextInt(100)+1; + if(plaDea<=15) { + Hammurabi.setPeopleDeath(Hammurabi.getPeople() / 2); + return Hammurabi.getPeopleDeath(); + }else return 0; + + /* + int plagueDeaths(int population) { + int plaDea = rand.nextInt(100) + 1; + if (plaDea <= 15) { + return population / 2; + } else return 0; + */ + + } + + + // Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. + // Return the number of plague deaths (possibly zero). + static int starvationDeaths(int population, int bushelsFedToPeople) { + int numberOfStar = bushelsFedToPeople / 20 - population; + if (numberOfStar >= 0) { + return 0; + } else { + + Hammurabi.setPeople(Hammurabi.getPeople() - Math.abs(numberOfStar)); + return Math.abs(numberOfStar); + } + } + // Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, + // but the grain is still gone. You don't get any benefit from having happy subjects. + // Return the number of deaths from starvation (possibly zero). + + static boolean uprising(int population, int howManyPeopleStarved) { + + double starvingRate = (double) howManyPeopleStarved / population; + if (starvingRate > 0.450) { + Hammurabi.setGameOver(true); + } else if (starvingRate <= 0.450) { + Hammurabi.setGameOver(false); + } + + return Hammurabi.isGameOver(); + + + } } diff --git a/docs/matuszek/gameStart.java b/docs/matuszek/gameStart.java new file mode 100644 index 0000000..1a57d7e --- /dev/null +++ b/docs/matuszek/gameStart.java @@ -0,0 +1,15 @@ +package hammurabi.docs.matuszek;//package Hammurabi; +import java.util.Random; // imports go here +import java.util.Scanner; + +import hammurabi.docs.matuszek.Hammurabi; +import hammurabi.docs.matuszek.normalEvents.*; +import hammurabi.docs.matuszek.disasterEvents.*;; + +public class gameStart { + public static void main(String[] args) { // required in every Java program + + new Hammurabi(100, 2800, 1000, 19).playGame(); + + } +} diff --git a/docs/matuszek/normalEvents.java b/docs/matuszek/normalEvents.java index 734e8cb..3e2657c 100644 --- a/docs/matuszek/normalEvents.java +++ b/docs/matuszek/normalEvents.java @@ -1,7 +1,159 @@ package hammurabi.docs.matuszek; import hammurabi.docs.matuszek.Hammurabi; +import static hammurabi.docs.matuszek.Hammurabi.*; +import static hammurabi.docs.matuszek.disasterEvents.rand; + public class normalEvents { + public normalEvents(){}; + public static void printStatus() { + System.out.println("O great Hammurabi!"); + System.out.println("You are in year " + Hammurabi.getYear() + " of your ten year rule."); + System.out.println("In the previous year " + Hammurabi.getStarvationPeopleDeath() + " people starved to death."); + System.out.println("the previous year " + Hammurabi.getImmigrants() + " people entered the kingdom."); + System.out.println("The population is now " + Hammurabi.getPeople() + " ."); + System.out.println("We harvested " + Hammurabi.getHarvest() + " bushels at " + Hammurabi.getBushelsPerAcre() + " bushels per acre."); + System.out.println("Rats destroyed " + Hammurabi.getRatEaten() + " bushels, leaving " + Hammurabi.getBushelsOfGrain() + " bushels in storage."); + System.out.println("The city owns " + Hammurabi.getAcres() + " acres of land."); + System.out.println("Land is currently worth " + Hammurabi.getLandValue() + " bushels per acre.\n"); + } + + public static void playerTypeIn() { + int acresToBuy = askHowManyAcresToBuy(Hammurabi.getLandValue(), Hammurabi.getBushelsOfGrain()); + Hammurabi.setAcresToBuy(acresToBuy); + if (Hammurabi.getAcresToBuy() == 0) { + int acresToSell = askHowManyAcresToSell(Hammurabi.getAcres()); + Hammurabi.setAcresToSell(acresToSell); + + } + int grainToFeed = askHowMuchGrainToFeedPeople(Hammurabi.getBushelsOfGrain()); + Hammurabi.setGrainToFeed(grainToFeed); + + int acresToPlant = askHowManyAcresToPlant(Hammurabi.getAcres(), Hammurabi.getPeople(), Hammurabi.getBushelsOfGrain()); + Hammurabi.setAcresToPlant(acresToPlant); + } + public static void nextCal(){ + Hammurabi.setHarvestPeople(harvest(Hammurabi.getAcresToPlant(), Hammurabi.getBushelsOfGrain())); + Hammurabi.setGrainEatenByRatsPeople(grainEatenByRats(Hammurabi.getBushelsOfGrain())); + Hammurabi.setNewCostOfLandPeople(newCostOfLand()); + } + static int askHowManyAcresToBuy(int price, int bushels) { + System.out.println("How many acres do you wish to buy?"); + int in = scanner.nextInt(); + while (in * price > bushels) { + System.out.println("Hammurabi: Think again. You have only " + bushels + " of grain. "); + System.out.println("Re-enter the numbers of acres you wish to buy"); + in = scanner.nextInt(); + } + Hammurabi.setBushelsOfGrain(Hammurabi.getBushelsOfGrain() - in * price); + Hammurabi.setAcres(Hammurabi.getAcres() + in); + return in; + } + //Asks the player how many acres of land to buy, and returns that number. + // You must have enough grain to pay for your purchase. + + static int askHowManyAcresToSell(int acresOwned) { + + System.out.println("How many acres do you wish to sell?"); + int in = scanner.nextInt(); + while (in > acresOwned) { + System.out.println("Hammurabi: Thank again. You have only " + acresOwned + " of grain. "); + System.out.println("Re-enter the numbers of acres you wish to sell: "); + in = scanner.nextInt(); + } + Hammurabi.setBushelsOfGrain(Hammurabi.getBushelsOfGrain() + in * Hammurabi.getLandValue()); + Hammurabi.setAcres(Hammurabi.getAcres() - in); + return in; + } + //Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. + //Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. + + static int askHowMuchGrainToFeedPeople(int bushels) { + + System.out.println("How many bushels do you wish to feed your people?"); + int in = scanner.nextInt(); + while (in > bushels ) { + System.out.println("Hammurabi: Think again. You have only " + Hammurabi.getBushelsOfGrain() + " of grain."); + System.out.println("Re-enter the numbers of bushels you wish to feed people: "); + in = scanner.nextInt(); + } + + Hammurabi.setBushelsOfGrain(Hammurabi.getBushelsOfGrain() - in); + return in; + } + + //Ask the player how much grain to feed people, + // and returns that number. You can't feed them more grain than you have. + // You can feed them more than they need to survive. + + static int askHowManyAcresToPlant(int acresOwned, int population, int bushels) { + System.out.println("How many acres do you wish to plant with seed?"); + int in = scanner.nextInt(); + while (in > acresOwned || in > bushels || in>population*10) { + System.out.println("Hammurabi: Think again. You have only " + Hammurabi.getBushelsOfGrain() + " of grain. "); + System.out.println("Re-enter the numbers of acres you wish to plant with seed: "); + in = scanner.nextInt(); + } + + Hammurabi.setBushelsOfGrain(Hammurabi.getBushelsOfGrain() - in); + return in; + } + // Return true if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) + + static int immigrants(int population, int acresOwned, int grainInStorage) { + + if (Hammurabi.getStarving() == 0) { + Hammurabi.setImmigrants((20 * acresOwned + grainInStorage) / (100 * population) + 1); + } + Hammurabi.setPeople(Hammurabi.getPeople() + Hammurabi.getImmigrants()); + return Hammurabi.getImmigrants(); + /* + if(starvationDeaths(population,grainInStorage)>0){ + return 0; + }else{ + return (20*acresOwned+grainInStorage)/(100*population)+1; + } + */ + + } + + //Nobody will come to the city if people are starving (so don't call this method). + // If everyone is well fed, compute how many people come to the city as: + // (20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1. + + static int harvest(int acres, int bushelsUsedAsSeed) { + + Hammurabi.setBushelsPerAcre(rand.nextInt(6) + 1); + Hammurabi.setHarvest(Hammurabi.getBushelsPerAcre() * acres); + Hammurabi.setBushelsOfGrain(Hammurabi.getBushelsOfGrain() - bushelsUsedAsSeed + Hammurabi.getHarvest()); + return Hammurabi.getHarvest(); + + } + + //Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. + // (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. + + static int grainEatenByRats(int bushels) { + boolean ratInfestation = false; + int ratEaten = 0; + if (rand.nextFloat() * 100 <= 40) { + ratInfestation = true; + } + if (ratInfestation) { + ratEaten = bushels * (rand.nextInt(31 - 10) + 10) / 100; + } + + Hammurabi.setRatEaten(ratEaten); + return Hammurabi.getRatEaten(); + } + + //There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). + + static int newCostOfLand() { + int min = 17, max = 24; + Hammurabi.setLandValue(rand.nextInt(max - min) + min); + return Hammurabi.getLandValue(); + } } diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore deleted file mode 100644 index a1c2a23..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/.gitignore +++ /dev/null @@ -1,23 +0,0 @@ -# Compiled class file -*.class - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE deleted file mode 100644 index 22474e4..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2022 Zip Code Wilmington Core - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md deleted file mode 100644 index e4672c9..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/README.md +++ /dev/null @@ -1,228 +0,0 @@ -# hamurabi -an ancient (in more ways than one) computer game (text) - -## General idea of the lab - -*Hammurabi* is a very old computer game (like about as old as Kris). Your job is to bring it into the 21st century by writing it in Java. - -Here are the standard instructions for the game: - -> **Congratulations, you are the newest ruler of ancient Sumer, elected for a ten year term of office. Your duties are to dispense food, direct farming, and buy and sell land as needed to support your people. Watch out for rat infestiations and the plague! Grain is the general currency, measured in bushels. The following will help you in your decisions:** -> -> * **Each person needs at least 20 bushels of grain per year to survive** -> * **Each person can farm at most 10 acres of land** -> * **It takes 2 bushels of grain to farm an acre of land** -> * **The market price for land fluctuates yearly** -> -> **Rule wisely and you will be showered with appreciation at the end of your term. Rule poorly and you will be kicked out of office!** - -### Maven - -There is NO `pom.xml` file in this repo. You need to add that. Use `vscode` or `IntelliJ` to make sure your project is a Maven project with a POM file. - -### Details - -Define a single class named `Hammurabi`. Use the following skeleton (but leave out the `//` comments): - -```java -package hammurabi; // package declaration -import java.util.Random; // imports go here -import java.util.Scanner; - -public class Hammurabi { // must save in a file named Hammurabi.java - Random rand = new Random(); // this is an instance variable - Scanner scanner = new Scanner(System.in); - - public static void main(String\[\] args) { // required in every Java program - new Hammurabi().playGame(); - } - - void playGame() { - // declare local variables here: grain, population, etc. - // statements go after the declations - } - - //other methods go here -} -``` - -### Playing the game - -Here is what you start the game with: - -* 100 people -* 2800 bushels of grain in storage -* 1000 acres of land -* Land value is 19 bushels/acre - - -Each year, print out a summary similar to the following: - - O great Hammurabi! - You are in year 1 of your ten year rule. - In the previous year 0 people starved to death. - In the previous year 5 people entered the kingdom. - The population is now 100. - We harvested 3000 bushels at 3 bushels per acre. - Rats destroyed 200 bushels, leaving 2800 bushels in storage. - The city owns 1000 acres of land. - Land is currently worth 19 bushels per acre. - -The above summary represents the initial state, at the _beginning_ of the first year--that is, when you first take office, and before you do any of the computations below). So, for example, the previous year (under a different ruler) must have started with 95 people; none starved, and 5 entered the kingdom, so as you enter office you rule 100 people. - -Here's what your `playGame` method needs to do each year, for up to 10 years: - -> Ask the player the following questions. These questions should be asked **in this order.** Do **not** give the player a chance to "back up" and change a previous answer. Each question should be asked in a separate method, and the answer returned as the value of the method, as specified below: -> -> `int askHowManyAcresToBuy(int price, int bushels)` -> -> Asks the player how many acres of land to buy, and returns that number. You must have enough grain to pay for your purchase. -> -> ` -> int askHowManyAcresToSell(int acresOwned)` -> -> Asks the player how many acres of land to sell, and returns that number. You can't sell more than you have. -> Do not ask this question if the player is buying land; it doesn't make sense to do both in one turn. -> -> ` -> int askHowMuchGrainToFeedPeople(int bushels)` -> -> Ask the player how much grain to feed people, and returns that number. You can't feed them more grain than you have. You **can** feed them more than they need to survive. -> -> ` -> int askHowManyAcresToPlant(int acresOwned, int population, int bushels)` -> -> Ask the player how many acres to plant with grain, and returns that number. You must have enough acres, enough grain, and enough people to do the planting. Any grain left over goes into storage for next year. -> -> For each question, do "sanity checking"; that is, test whether the answer is possible (you have enough grain, you have enough people to do the planting etc.), and keep asking until you get a possible value. (For example, `O Great Hammurabi, surely you jest! We have only 3415 bushels left!`) -> -> Then the method needs to determine: -> -> 1. If there is a plague, and how many people die from it. -> 2. How many people starved. -> 3. How many people came to the city. -> 4. How good the harvest is. -> 5. If you have a problem with rats, and how much grain they eat. -> 6. How much land costs (for deciding what to do next). -> -> These can all be local variables of your `playGame` method. -> -> Use the following methods, **in this order,** to make the necessary calculations: -> -> `int plagueDeaths(int population)` -> -> Each year, there is a 15% chance of a horrible plague. When this happens, half your people die. Return the number of plague deaths (possibly zero). -> -> ` -> int starvationDeaths(int population, int bushelsFedToPeople)` -> -> Each person needs 20 bushels of grain to survive. If you feed them more than this, they are happy, but the grain is still gone. You don't get any benefit from having happy subjects. Return the number of deaths from starvation (possibly zero). -> -> ` -> boolean uprising(int population, int howManyPeopleStarved)` -> -> Return `true` if more than 45% of the people starve. (This will cause you to be immediately thrown out of office, ending the game.) -> -> ` -> int immigrants(int population, int acresOwned, int grainInStorage)` -> -> Nobody will come to the city if people are starving (so don't call this method). If everyone is well fed, compute how many people come to the city as: `(20 * _number of acres you have_ + _amount of grain you have in storage_) / (100 * _population_) + 1`. -> -> ` -> int harvest(int acres, int bushelsUsedAsSeed)` -> -> Choose a random integer between 1 and 6, inclusive. Each acre that was planted with seed will yield this many bushels of grain. (Example: if you planted 50 acres, and your number is 3, you harvest 150 bushels of grain). Return the number of bushels harvested. -> -> ` -> int grainEatenByRats(int bushels)` -> -> There is a 40% chance that you will have a rat infestation. When this happens, rats will eat somewhere between 10% and 30% of your grain. Return the amount of grain eaten by rats (possibly zero). -> -> ` -> int newCostOfLand()` -> -> The price of land is random, and ranges from 17 to 23 bushels per acre. Return the new price for the next set of decisions the player has to make. (The player will need this information in order to buy or sell land.) - -Do these computations, _in this order,_ for each of ten years. Each computation should be done in a separate method, and none of these methods should read anything or print anything. Since most methods change the amount of grain available, you will need to keep this information in a variable so it is available to the next method that needs it. - -When the computations are finished, call a method `printSummary` to print the summary for the year. This method will take several parameters. - -When the game ends, use a method `finalSummary` to print out a final summary, and to tell the player how good a job he/she did. I'll leave the details up to you, but the usual evaluation is based on how many people starved, and how many acres per person you end up with. - -Your `playGame` method will be quite long, but very straightforward; it does very little but call other methods. - -All the required arithmetic in this program should be **integer**. You do not need doubles. - -### Urgent! - -> It is **strongly** suggest that you first get the *simplest possible version of the program running* and tested out (that is, leave out things like rats, plagues, and immigration), then add these things one at a time to a _working_ program, **testing as you go**. - -### Things you need to know: - -#### Random numbers - -To get a random number generator, you first need to import `java.util.Random` (or `java.util.*`). Then, you can create a random number generator with a statement such as: - -> `static Random rand = new Random();` - -To get a new random number in the range `0..n-1`, where `n` is an `int`, call `rand.nextInt(n)`. To get a new random number in the range `min..max`, use the expression `rand.nextInt(max - min + 1) + min`. You can use the `rand` method in statements such as - -> `myNewNumber = rand.nextInt(5); -> if (rand.nextInt(100) < 15) { ... }` - -To do something that happens `p` percent of the time, use - -> `if (rand.nextInt(100) < p) { _...do something..._ }` - -#### Getting input - -To get a number from the player, add this method to your program: - -```java - /** - * Prints the given message (which should ask the user for some integral - * quantity), and returns the number entered by the user. If the user's - * response isn't an integer, the question is repeated until the user - * does give a integer response. - * - * @param message The request to present to the user. - * @return The user's numeric response. - */ - int getNumber(String message) { - while (true) { - System.out.print(message); - try { - return scanner.nextInt(); - } - catch (InputMismatchException e) { - System.out.println("\"" + scanner.next() + "\" isn't a number!"); - } - } - } -``` - -Here is an example of how you can use this method: - -> `sell = getNumber("O great Hammurabi, how many acres shall you sell?");` - -### Structure of the solution - -* Project name: `Hammurabi` -* Package name: `hammurabi` -* Class names and method signatures: - * `class Hammurabi` - * `public static void main(String[] args)` - * Numerous other methods, as described above. - -The above are requirements. **The methods that do calculations**, not input/output, **will be tested by the test methods in the test class**, so be sure to get the spelling, capitalization, and number and types of arguments correct (argument _names_ are irrelevant). You may have additional methods if you wish. - -### Yo! Test it! - -You'll see there is a Test File (HammurabiTest.java) you need to be able to run against your code to prove your solution works. Use It!! - -But realize that you'll have to structure your solution so that app classes are in one source direstory and your test files is in another. Study your other labs to figure out what to do. - -### Credits - -Adapted from: CIT 591 Assignment 3: Hammurabi, Fall 2010, David Matuszek (this guy is a Rock Star) - diff --git a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml b/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml deleted file mode 100644 index d789654..0000000 --- a/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/target/classes/pom.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - 4.0.0 - - io.zipcoder - MicroLabs-Loops - 1.0-SNAPSHOT - - - - - junit - junit - 4.13.2 - - - - - - 1.8 - 1.8 - - \ No newline at end of file