This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

HAMURABI.java

By: a guest on Jul 27th, 2010  |  syntax: Java  |  size: 5.54 KB  |  views: 172  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import java.io.IOException;
  2. import java.util.Scanner;
  3.  
  4. public class HAMURABI {
  5.         static int totalDeaths = 0, percentDied = 0, year = 0, population = 95, stores = 2800, immigrants = 5, deaths,
  6.                 harvest = 3000, yeild = 3, acres = harvest / yeild, eaten = harvest - stores, landPrice, fullPeople, temp;
  7.         static boolean plague = false;
  8.         final static String FINK = "DUE TO THIS EXTREME MISMANAGEMENT YOU HAVE NOT ONLY\n" +
  9.                 "BEEN IMPEACHED AND THROWN OUT OF OFFICE BUT YOU HAVE\n" +
  10.                 "ALSO BEEN DECLARED 'NATIONAL FINK' !!\n";
  11.         Scanner input = new Scanner(System.in);
  12.  
  13.         private void newYear() {
  14.                 year += 1;
  15.                 population += immigrants;
  16.                 landPrice = (int) (10 * Math.random() + 17);
  17.                 System.out.println(report());
  18.                 do {
  19.                         System.out.print("HOW MANY ACRES DO YOU WISH TO BUY?  ");
  20.                         temp = input.nextInt();
  21.                         if (temp < 0)
  22.                                 epicFail(0);
  23.                         if (temp * landPrice > stores)
  24.                                 System.out.println("HAMURABI:  THINK AGAIN. YOU HAVE ONLY\n" +
  25.                                                 stores + " BUSHELS OF GRAIN. NOW THEN,");
  26.                 } while (temp * landPrice > stores);
  27.                 acres += temp;
  28.                 stores -= temp * landPrice;
  29.                 do {
  30.                         System.out.print("HOW MANY ACRES DO YOU WISH TO SELL?  ");
  31.                         temp = input.nextInt();
  32.                         if (temp < 0)
  33.                                 epicFail(0);
  34.                         if (temp > acres)
  35.                                 System.out.println("HAMURABI:  THINK AGAIN. YOU OWN ONLY " + acres + " ACRES. NOW THEN,");
  36.                 } while (temp > acres);
  37.                 stores += temp * landPrice;
  38.                 acres -= temp;
  39.                 do {
  40.                         System.out.print("\nHOW MANY BUSHELS DO YOU WISH TO FEED YOUR PEOPLE?  ");
  41.                         temp = input.nextInt();
  42.                         if (temp < 0)
  43.                                 epicFail(0);
  44.                         if (temp > stores)
  45.                                 System.out.println("HAMURABI:  THINK AGAIN. YOU HAVE ONLY\n" +
  46.                                                 stores + " BUSHELS OF GRAIN. NOW THEN,");
  47.                 } while (temp > stores);
  48.                 fullPeople = temp / 20;
  49.                 stores -= temp;
  50.                 do {
  51.                         System.out.print("\nHOW MANY ACRES DO YOU WISH TO PLANT WITH SEED?  ");
  52.                         temp = input.nextInt();
  53.                         if (temp < 0)
  54.                                 epicFail(0);
  55.                         if (temp > acres)
  56.                                 System.out.println("HAMURABI:  THINK AGAIN. YOU OWN ONLY " + acres + " ACRES. NOW THEN,");
  57.                         if (temp / 2 > stores)
  58.                                 System.out.println("HAMURABI:  THINK AGAIN. YOU HAVE ONLY\n" +
  59.                                                 stores + " BUSHELS OF GRAIN. NOW THEN,");
  60.                         if (temp > population * 10)
  61.                                 System.out.println("BUT YOU HAVE ONLY" + population + "PEOPLE TO TEND THE FIELDS. NOW THEN,");
  62.                 } while (temp > acres || temp / 2 > stores || temp > population * 10);
  63.                 stores -= temp / 2;
  64.                 yeild = (int) (Math.random() * 5 + 1);
  65.                 harvest = temp * yeild;
  66.                 temp = (int) (Math.random() * 5 + 1);
  67.                 if (temp % 2 != 1)
  68.                         eaten = (stores / temp);
  69.                 else
  70.                         eaten = 0;
  71.                 stores += (harvest - eaten);
  72.                 immigrants = (int) (Math.random() * 5 + 1) *
  73.                                         (20 * acres + stores) / population / 100 + 1;
  74.                 if (population > fullPeople) {
  75.                         deaths = population - fullPeople;
  76.                         if (deaths > .45 * population)
  77.                                 epicFail(1);
  78.                         percentDied = ((year - 1) * percentDied + deaths * 100 / population) / year;
  79.                         population = fullPeople;
  80.                         totalDeaths += deaths;
  81.                 }
  82.                 if (20 * Math.random() >= 17)
  83.                         plague = true;
  84.                 plague = false;
  85.         }
  86.        
  87.         private static String report() {
  88.                 String answer = "\nHAMURABI:  I BEG TO REPORT TO YOU,\n" +
  89.                                 "IN YEAR " + year + ", " + deaths + " PEOPLE STARVED, " + immigrants + " CAME TO THE CITY.\n";
  90.                 if (plague) {
  91.                         population = population / 2;
  92.                         answer += "A HORRIBLE PLAGUE STRUCK!  HALF THE PEOPLE DIED.\n";
  93.                 }
  94.                 answer += "POPULATION IS NOW " + population + ".\n" +
  95.                                 "THE CITY NOW OWNS " + acres + " ACRES.\n" +
  96.                                 "YOU HARVESTED " + yeild + " BUSHELS PER ACRE.\n" +
  97.                                 "RATS ATE " + eaten + " BUSHELS.\n" +
  98.                                 "YOU NOW HAVE " + stores + " BUSHELS IN STORE\n\n" +
  99.                                 "LAND IS TRADING AT " + landPrice + " BUSHELS PER ACRE.";
  100.                 return answer;
  101.         }
  102.  
  103.        
  104.         private static void epicFail(int x) {
  105.                 String reason = "";
  106.                 switch (x) {
  107.                 case 0: reason = "HAMURABI:  I CANNOT DO WHAT YOU WISH.\n" +
  108.                         "GET YOURSELF ANOTHER STEWARD!!!!!"; break;
  109.                 case 1: reason = "YOU STARVED " + deaths + " PEOPLE IN ONE YEAR!!!\n" +
  110.                         FINK; break;
  111.                 }
  112.                 System.out.println(reason);
  113.                 System.exit(0);
  114.         }
  115.        
  116.         private void finished() {
  117.                 String answer = "IN YOUR 10-YEAR TERM OF OFFICE, " + percentDied + " PERCENT OF THE\n" +
  118.                         "POPULATION STARVED PER YEAR ON AVERAGE, I.E., A TOTAL OF\n" +
  119.                         totalDeaths + " PEOPLE DIED!!\n" +
  120.                         "YOU STARTED WITH 10 ACRES PER PERSON AND ENDED WITH\n" +
  121.                         acres / population + " ACRES PER PERSON\n\n";
  122.                 if (percentDied > 33 || acres / population < 7)
  123.                         answer += FINK;
  124.                 else if (percentDied > 10 || acres / population < 9)
  125.                         answer += "YOUR HEAVY-HANDED PERFORMANCE SMACKS OF NERO AND IVAN IV.\n" +
  126.                                         "THE PEOPLE (REMAINING) FIND YOU AN UNPLEASANT RULER, AND,\n" +
  127.                                         "FRANKLY, HATE YOUR GUTS!";
  128.                 else if (percentDied > 3 || acres / population < 10)
  129.                         answer += "YOUR PERFORMANCE COULD HAVE BEEN SOMEWHAT BETTER, BUT\n" +
  130.                                         "REALLY WASN'T TOO BAD AT ALL.\n" +
  131.                                         Math.random() * population * .8 + " PEOPLE WOULD" +
  132.                                         "DEARLY LIKE TO SEE YOU ASSASSINATED BUT WE ALL HAVE OUR" +
  133.                                         "TRIVIAL PROBLEMS";
  134.                 else
  135.                         answer += "A FANTASTIC PERFORMANCE!!!  CHARLEMANGE, DISRAELI, AND\n" +
  136.                                         "JEFFERSON COMBINED COULD NOT HAVE DONE BETTER!";
  137.                 answer += "\n\n\n\n\n\n\n\n\n\nSo long for now.";
  138.                 System.out.println(answer);
  139.         }
  140.        
  141.         public static void main(String[] args) throws IOException {
  142.                 HAMURABI a = new HAMURABI();
  143.                 System.out.println("\t\t\t\tHAMURABI\n\t       CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n\n" +
  144.                                 "TRY YOUR HAND AT GOVERNING ANCIENT SUMERIA\nSUCCESSFULLY FOR A TEN-YEAR TERM OF OFFICE.");
  145.                 while (year < 10)
  146.                         a.newYear();
  147.                 a.finished();
  148.         }
  149. }
clone this paste RAW Paste Data