Commit fbd9bce9 authored by Trisha Gee's avatar Trisha Gee
Browse files

[Ch6] Adding Sharpen Your Pencil, and updating StartupBust according to what's...

[Ch6] Adding Sharpen Your Pencil, and updating StartupBust according to what's in the book. Which is a bit mysterious, because I thought it already was..
parent 29f3d3ca
Loading
Loading
Loading
Loading
+47 −0
Changes for src/main/java/ch6/SharpenYourPencil.java: 47 added lines, 0 removed lines.
Original line number Diff line number Diff line
package ch6;

import java.util.ArrayList;

public class SharpenYourPencil {
  void arrayListCode() {
    ArrayList<String> myList = new ArrayList<String>();

    String a = "whoohoo";
    myList.add(a);

    String b = "Frog";
    myList.add(b);

    int theSize = myList.size();

    String str = myList.get(1);

    myList.remove(1);

    boolean isIn = myList.contains(b);
  }

  void arrayCode() {
    String [] myList = new String[2];

    String a = "whoohoo";
    myList[0] = a;

    String b = "Frog";
    myList[1] = b;

    int theSize = myList.length;

    String str = myList[1];

    myList[1] = null;

    boolean isIn = false;
    for (String item : myList) {
      if (b.equals(item)) {
        isIn = true;
        break;
      }
    }
  }
}
+9 −8
Changes for src/main/java/ch6/StartupBust.java: 9 added lines, 8 removed lines.
Original line number Diff line number Diff line
@@ -4,8 +4,8 @@ import java.util.ArrayList;

public class StartupBust {

  private final GameHelper helper = new GameHelper();
  private final ArrayList<Startup> startups = new ArrayList<Startup>();
  private GameHelper helper = new GameHelper();
  private ArrayList<Startup> startups = new ArrayList<Startup>();
  private int numOfGuesses = 0;

  private void setUpGame() {
@@ -55,22 +55,23 @@ public class StartupBust {
    } // close for

    System.out.println(result);
  }
  } // close method


  private void finishGame() {
    System.out.println("All Startups are dead! Your stock is now worthless");
    if (numOfGuesses <= 9) {
      System.out.println("It only took you " + numOfGuesses + " guesses.  You get the Enron award!");
    if (numOfGuesses <= 18) {
      System.out.println("It only took you " + numOfGuesses + " guesses.");
      System.out.println("You got out before your options sank.");
    } else {
      System.out.println("Took you long enough. " + numOfGuesses + " guesses.");
      System.out.println("Too bad you didn't get out before your options sank.");
    }
      System.out.println("Fish are dancing with your options");
    }
  } // close method

  public static void main(String[] args) {
    StartupBust game = new StartupBust();
    game.setUpGame();
    game.startPlaying();
  }
  } // close method
}
 No newline at end of file