Question

Need help with a number guessing game in java 1) You should store prior guessses in...

Need help with a number guessing game in java

1) You should store prior guessses in a linked list, and the nodes in the list must follow the order of prior guesses. For example, if the prior guesses are 1000, 2111, 3222 in that order, the nodes must follow the same order

2) You should store the candidate numbers also in a linked list, and the nodes must follow the order of numbers (i.e. from the smallest to the largest).

3) do NOT create any new file – any new file you create will be ignored by the autograder package guessme;

LinkedListGamePublicTest.java
package guessme;
 
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
 
import org.junit.Before;
import org.junit.Test;
 
public class LinkedListGamePublicTest {
 
  private LinkedListGame gamerA; 
  private LinkedListGame gamerB;
 
  @Before
  public void before() {
    gamerA = new LinkedListGame();
    gamerB = new LinkedListGame();
  }
 
  @Test(timeout = 1000)
  public void testReset() {
    gamerA.getGuess();
    gamerA.updateGuess(0);
    gamerA.reset();
    assertEquals("numGuesses after reset", 0, gamerA.numGuesses());
    assertFalse("isOver after reset", gamerA.isOver());
    assertEquals("priorGuesses after reset", null, gamerA.priorGuesses());
    assertEquals("priorGuessesString after reset", "", gamerA.priorGuessesString());
  }
 
  @Test(timeout = 1000)
  public void testFirstGuessAndUpdate() {
    gamerA.reset();
    assertEquals("test first guess", 1000, gamerA.getGuess());
    assertEquals("test first guess", 1, gamerA.numGuesses());
    assertEquals("test first guess", 1000, gamerA.priorGuesses().getInfo());
    assertEquals("test first guess", null, gamerA.priorGuesses().getLink());
    assertEquals("test first guess", "1000", gamerA.priorGuessesString());
    gamerA.updateGuess(0);
    assertFalse("isOver after first update", gamerA.isOver());
  }
 
  @Test(timeout = 1000)
  public void testIsOver() {
    gamerA.reset();
    gamerB.reset();
    assertFalse("gameB not over yet", gamerB.isOver());
    assertEquals("gameB 1st guess", 1000, gamerB.getGuess());
    gamerB.updateGuess(4);
    assertTrue("gameB is over", gamerB.isOver());
    assertFalse("gameA not over yet", gamerA.isOver());
  }
 
  @Test(timeout = 1000)
  public void testIsPriorGuess() {
    gamerA.reset();
    int g1 = gamerA.getGuess();
    assertTrue("is prior guess", gamerA.isPriorGuess(g1));
    assertFalse("not prior guess", gamerA.isPriorGuess(9999));
    gamerA.updateGuess(0);
    int g2 = gamerA.getGuess();
    assertTrue("is prior guess", gamerA.isPriorGuess(g2));
    assertFalse("not prior guess", gamerA.isPriorGuess(9999));
  }
 
  @Test(timeout = 1000)
  public void testNumGuesses() {
    gamerB.reset();
    assertEquals("number of guesses shold be 0", 0, gamerB.numGuesses());
    assertEquals("number of guesses shold be 0", 0, gamerB.numGuesses());
    gamerB.getGuess();
    assertEquals("number of guesses shold be 1", 1, gamerB.numGuesses());
    assertEquals("number of guesses shold be 1", 1, gamerB.numGuesses());
    gamerB.updateGuess(0);
    gamerB.getGuess();
    assertEquals("number of guesses shold be 2", 2, gamerB.numGuesses());
    assertEquals("number of guesses shold be 2", 2, gamerB.numGuesses());
    gamerB.updateGuess(4);
    gamerB.getGuess();
    assertEquals("number of guesses shold be 3", 3, gamerB.numGuesses());
    assertEquals("number of guesses shold be 3", 3, gamerB.numGuesses());
  }
 
  @Test(timeout = 1000) 
  public void testUpdateGuessTrivial() {
    gamerB.reset();
    // ground truth number is 1000
    assertEquals("gamerB first guess", 1000, gamerB.getGuess());
    assertTrue("gamerB first update", gamerB.updateGuess(4));
    assertTrue("gamerB game over", gamerB.isOver());
  }
 
  @Test(timeout = 1000)
  public void testUpdateGuess() {
    gamerA.reset();
    // ground truth number is 3242
    assertEquals("gamerA first guess", 1000, gamerA.getGuess());
    assertTrue("gamerA first update", gamerA.updateGuess(0));
 
    assertEquals("gamerA second guess", 2111, gamerA.getGuess());
    assertTrue("gamerA second update", gamerA.updateGuess(0));
 
    assertEquals("gamerA third guess", 3222, gamerA.getGuess());
    assertTrue("gamerA third update", gamerA.updateGuess(3));
 
    assertEquals("gamerA fourth guess", 3223, gamerA.getGuess());
    assertTrue("gamerA fourth update", gamerA.updateGuess(2));
 
    assertEquals("gamerA fifth guess", 3232, gamerA.getGuess());
    assertTrue("gamerA fifth update", gamerA.updateGuess(3));
 
    assertEquals("gamerA sixth guess", 3242, gamerA.getGuess());
    assertTrue("gamerA sixth update", gamerA.updateGuess(4));
    assertTrue("gamerA game over", gamerA.isOver());
 
  }
 
  @Test(timeout = 1000)
  public void testUpdateGuessError() {
    gamerA.reset();
    gamerA.getGuess();  // should be 1000
    gamerA.updateGuess(3);
    gamerA.getGuess();  // should be 1001
    assertFalse("state of error", gamerA.updateGuess(1)); // this number does not exist
    // updateGuess should return false
 
    gamerA.reset();
    gamerA.getGuess();  // should be 1000
    gamerA.updateGuess(3);
    gamerA.getGuess();  // should be 1001
    gamerA.updateGuess(2);
    gamerA.getGuess();  // should be 1010
    assertFalse("state of error", gamerA.updateGuess(1)); // this number does not exist
    // updateGuess should return false
  }
 
  @Test(timeout = 1000)
  public void testPriorGuesses() {
    gamerB.reset();
    assertEquals("test prior guesses", null, gamerB.priorGuesses());
 
    int g1 = gamerB.getGuess();
    LLIntegerNode pl = gamerB.priorGuesses();
    assertEquals("test prior guesses", g1, pl.getInfo());
    assertEquals("test prior guesses", null, pl.getLink());
 
    gamerB.updateGuess(1);
    int g2 = gamerB.getGuess();
    pl = gamerB.priorGuesses();
    assertEquals("test prior guesses", g1, pl.getInfo());
    assertEquals("test prior guesses", g2, pl.getLink().getInfo());
 
    gamerB.updateGuess(2);
    pl = gamerB.priorGuesses();
    assertEquals("test prior guesses", g1, pl.getInfo());
    assertEquals("test prior guesses", g2, pl.getLink().getInfo());
    int g3 = gamerB.getGuess();
    assertEquals("test prior guesses", g3, pl.getLink().getLink().getInfo());
 
    gamerB.updateGuess(3);
    pl = gamerB.priorGuesses();
    assertEquals("test prior guesses", g1, pl.getInfo());
    assertEquals("test prior guesses", g2, pl.getLink().getInfo());
    assertEquals("test prior guesses", g3, pl.getLink().getLink().getInfo());
    int g4 = gamerB.getGuess();
    assertEquals("test prior guesses", g4, pl.getLink().getLink().getLink().getInfo());
 
    gamerB.updateGuess(3);
    pl = gamerB.priorGuesses();
    assertEquals("test prior guesses", g1, pl.getInfo());
    assertEquals("test prior guesses", g2, pl.getLink().getInfo());
    assertEquals("test prior guesses", g3, pl.getLink().getLink().getInfo());
    assertEquals("test prior guesses", g4, pl.getLink().getLink().getLink().getInfo());
  }
 
  @Test(timeout = 1000)
  public void testPriorGuessesString() {
    gamerB.reset();
    assertEquals("test prior guesses string", "", gamerB.priorGuessesString());
 
    int g1 = gamerB.getGuess();
    String g = new String();
    g = g + g1;
    assertEquals("test prior guesses string", g, gamerB.priorGuessesString());
    gamerB.updateGuess(1);
 
    int g2 = gamerB.getGuess();
    g = g + ", " + g2;
    gamerB.updateGuess(2);
 
    int g3 = gamerB.getGuess();
    g = g + ", " + g3;
    gamerB.updateGuess(3);
 
    int g4 = gamerB.getGuess();
    g = g + ", " + g4;
    assertEquals("test prior guesses string", g, gamerB.priorGuessesString());
    gamerB.updateGuess(4);
    assertEquals("test prior guesses string", g, gamerB.priorGuessesString());
  }
 
}

LinkedListGame.java

package guessme;
 
/**
 * A LinkedList-based implementation of the Guess-A-Number game.
 */
public class LinkedListGame {
 
private boolean gameOver;
 
 
  /********************************************************
   * NOTE: for this project you must use linked lists
   * implemented by yourself. You are NOT ALLOWED to use
   * Java arrays of any type, or any class in the java.util
   * package (such as ArrayList).
   *******************************************************/
 
  /********************************************************
   * NOTE: you are allowed to add new methods if necessary,
   * but DO NOT remove any provided method, and do NOT add
   * new files (as they will be ignored by the autograder).
   *******************************************************/
 
  // LinkedListGame constructor method
  public LinkedListGame() {
    reset();
  }
 
  /** Resets data members and game state so we can play again.
   * 
   */
  public void reset() {
    gameOver = false;
  }
 
  /** Returns true if n is a prior guess; false otherwise.
   * 
   */
  public boolean isPriorGuess(int n) {
    // TODO
    return false;
  }
 
  /** Returns the number of guesses so far.
   * 
   */
  public int numGuesses() {
    // TODO
    return 0;
  }
 
  /**
   * Returns the number of matches between integers a and b.
   * You can assume that both are 4-digits long (i.e. between 1000 and 9999).
   * The return value must be between 0 and 4.
   * 
   * <p>A match is the same digit at the same location. For example:
   *   1234 and 4321 have 0 match;
   *   1234 and 1114 have 2 matches (1 and 4);
   *   1000 and 9000 have 3 matches (three 0's).
   */
  public static int numMatches(int a, int b) {
    // TODO
    return 0;
  }
 
  /**
   * Returns true if the game is over; false otherwise.
   * The game is over if the number has been correctly guessed
   * or if no candidate is left.
   */
  public boolean isOver() {
    return gameOver;
  }
 
  /**
   * Returns the guess number and adds it to the list of prior guesses.
   * The insertion should occur at the end of the prior guesses list,
   * so that the order of the nodes follow the order of prior guesses.
   */
  public int getGuess() {
    // TODO: add guess to the list of prior guesses.
    return 0;
  }
 
  /**
   * Updates guess based on the number of matches of the previous guess.
   * If nmatches is 4, the previous guess is correct and the game is over.
   * Check project description for implementation details.
   * 
   * <p>Returns true if the update has no error; false if no candidate 
   * is left (indicating a state of error);
   */
  public boolean updateGuess(int nmatches) {
    // TODO
    return true;
  }
 
  /**
   *  Returns the head of the prior guesses list.
   *  Returns null if there hasn't been any prior guess
   */
  public LLIntegerNode priorGuesses() {
    // TODO
    return null;
  }
 
  /**
   * Returns the list of prior guesses as a String. For example,
   * if the prior guesses are 1000, 2111, 3222, in that order,
   * the returned string should be "1000, 2111, 3222", in the same order,
   * with every two numbers separated by a comma and space, except the
   * last number (which should not be followed by either comma or space).
   *
   * <p>Returns an empty string if here hasn't been any prior guess
   */
  public String priorGuessesString() {
    // TODO
    return "";
  }
 
}

LLIntegerNode.java

package guessme;
 
/**
 * This class defines a linked list node storing an integer.
 * Use primitive type int (do not use wrapper class Integer)
 * You must provide the following methods:
 * - a constructor
 * - a setInfo method and a getInfo method
 * - a setLink method and a getLink method
 */
public class LLIntegerNode {
  // TODO
}
0 0
Add a comment Improve this question Transcribed image text
Answer #1

I have Edited the part that I could understand, if some help me in understanding this question more clearly then I could also contribute more.

LinkedListGamePublicTest.java
package guessme;


import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;


import org.junit.Before;
import org.junit.Test;


public class LinkedListGamePublicTest {


private LinkedListGame gamerA;
private LinkedListGame gamerB;


@Before
public void before() {
gamerA = new LinkedListGame();
gamerB = new LinkedListGame();
}


@Test(timeout = 1000)
public void testReset() {
gamerA.getGuess();
gamerA.updateGuess(0);
gamerA.reset();
assertEquals("numGuesses after reset", 0, gamerA.numGuesses());
assertFalse("isOver after reset", gamerA.isOver());
assertEquals("priorGuesses after reset", null, gamerA.priorGuesses());
assertEquals("priorGuessesString after reset", "", gamerA.priorGuessesString());
}


@Test(timeout = 1000)
public void testFirstGuessAndUpdate() {
gamerA.reset();
assertEquals("test first guess", 1000, gamerA.getGuess());
assertEquals("test first guess", 1, gamerA.numGuesses());
assertEquals("test first guess", 1000, gamerA.priorGuesses().getInfo());
assertEquals("test first guess", null, gamerA.priorGuesses().getLink());
assertEquals("test first guess", "1000", gamerA.priorGuessesString());
gamerA.updateGuess(0);
assertFalse("isOver after first update", gamerA.isOver());
}


@Test(timeout = 1000)
public void testIsOver() {
gamerA.reset();
gamerB.reset();
assertFalse("gameB not over yet", gamerB.isOver());
assertEquals("gameB 1st guess", 1000, gamerB.getGuess());
gamerB.updateGuess(4);
assertTrue("gameB is over", gamerB.isOver());
assertFalse("gameA not over yet", gamerA.isOver());
}


@Test(timeout = 1000)
public void testIsPriorGuess() {
gamerA.reset();
int g1 = gamerA.getGuess();
assertTrue("is prior guess", gamerA.isPriorGuess(g1));
assertFalse("not prior guess", gamerA.isPriorGuess(9999));
gamerA.updateGuess(0);
int g2 = gamerA.getGuess();
assertTrue("is prior guess", gamerA.isPriorGuess(g2));
assertFalse("not prior guess", gamerA.isPriorGuess(9999));
}


@Test(timeout = 1000)
public void testNumGuesses() {
gamerB.reset();
assertEquals("number of guesses shold be 0", 0, gamerB.numGuesses());
assertEquals("number of guesses shold be 0", 0, gamerB.numGuesses());
gamerB.getGuess();
assertEquals("number of guesses shold be 1", 1, gamerB.numGuesses());
assertEquals("number of guesses shold be 1", 1, gamerB.numGuesses());
gamerB.updateGuess(0);
gamerB.getGuess();
assertEquals("number of guesses shold be 2", 2, gamerB.numGuesses());
assertEquals("number of guesses shold be 2", 2, gamerB.numGuesses());
gamerB.updateGuess(4);
gamerB.getGuess();
assertEquals("number of guesses shold be 3", 3, gamerB.numGuesses());
assertEquals("number of guesses shold be 3", 3, gamerB.numGuesses());
}


@Test(timeout = 1000)
public void testUpdateGuessTrivial() {
gamerB.reset();
// ground truth number is 1000
assertEquals("gamerB first guess", 1000, gamerB.getGuess());
assertTrue("gamerB first update", gamerB.updateGuess(4));
assertTrue("gamerB game over", gamerB.isOver());
}


@Test(timeout = 1000)
public void testUpdateGuess() {
gamerA.reset();
// ground truth number is 3242
assertEquals("gamerA first guess", 1000, gamerA.getGuess());
assertTrue("gamerA first update", gamerA.updateGuess(0));


assertEquals("gamerA second guess", 2111, gamerA.getGuess());
assertTrue("gamerA second update", gamerA.updateGuess(0));


assertEquals("gamerA third guess", 3222, gamerA.getGuess());
assertTrue("gamerA third update", gamerA.updateGuess(3));


assertEquals("gamerA fourth guess", 3223, gamerA.getGuess());
assertTrue("gamerA fourth update", gamerA.updateGuess(2));


assertEquals("gamerA fifth guess", 3232, gamerA.getGuess());
assertTrue("gamerA fifth update", gamerA.updateGuess(3));


assertEquals("gamerA sixth guess", 3242, gamerA.getGuess());
assertTrue("gamerA sixth update", gamerA.updateGuess(4));
assertTrue("gamerA game over", gamerA.isOver());


}


@Test(timeout = 1000)
public void testUpdateGuessError() {
gamerA.reset();
gamerA.getGuess(); // should be 1000
gamerA.updateGuess(3);
gamerA.getGuess(); // should be 1001
assertFalse("state of error", gamerA.updateGuess(1)); // this number does not exist
// updateGuess should return false


gamerA.reset();
gamerA.getGuess(); // should be 1000
gamerA.updateGuess(3);
gamerA.getGuess(); // should be 1001
gamerA.updateGuess(2);
gamerA.getGuess(); // should be 1010
assertFalse("state of error", gamerA.updateGuess(1)); // this number does not exist
// updateGuess should return false
}


@Test(timeout = 1000)
public void testPriorGuesses() {
gamerB.reset();
assertEquals("test prior guesses", null, gamerB.priorGuesses());


int g1 = gamerB.getGuess();
LLIntegerNode pl = gamerB.priorGuesses();
assertEquals("test prior guesses", g1, pl.getInfo());
assertEquals("test prior guesses", null, pl.getLink());


gamerB.updateGuess(1);
int g2 = gamerB.getGuess();
pl = gamerB.priorGuesses();
assertEquals("test prior guesses", g1, pl.getInfo());
assertEquals("test prior guesses", g2, pl.getLink().getInfo());


gamerB.updateGuess(2);
pl = gamerB.priorGuesses();
assertEquals("test prior guesses", g1, pl.getInfo());
assertEquals("test prior guesses", g2, pl.getLink().getInfo());
int g3 = gamerB.getGuess();
assertEquals("test prior guesses", g3, pl.getLink().getLink().getInfo());


gamerB.updateGuess(3);
pl = gamerB.priorGuesses();
assertEquals("test prior guesses", g1, pl.getInfo());
assertEquals("test prior guesses", g2, pl.getLink().getInfo());
assertEquals("test prior guesses", g3, pl.getLink().getLink().getInfo());
int g4 = gamerB.getGuess();
assertEquals("test prior guesses", g4, pl.getLink().getLink().getLink().getInfo());


gamerB.updateGuess(3);
pl = gamerB.priorGuesses();
assertEquals("test prior guesses", g1, pl.getInfo());
assertEquals("test prior guesses", g2, pl.getLink().getInfo());
assertEquals("test prior guesses", g3, pl.getLink().getLink().getInfo());
assertEquals("test prior guesses", g4, pl.getLink().getLink().getLink().getInfo());
}


@Test(timeout = 1000)
public void testPriorGuessesString() {
gamerB.reset();
assertEquals("test prior guesses string", "", gamerB.priorGuessesString());


int g1 = gamerB.getGuess();
String g = new String();
g = g + g1;
assertEquals("test prior guesses string", g, gamerB.priorGuessesString());
gamerB.updateGuess(1);


int g2 = gamerB.getGuess();
g = g + ", " + g2;
gamerB.updateGuess(2);


int g3 = gamerB.getGuess();
g = g + ", " + g3;
gamerB.updateGuess(3);


int g4 = gamerB.getGuess();
g = g + ", " + g4;
assertEquals("test prior guesses string", g, gamerB.priorGuessesString());
gamerB.updateGuess(4);
assertEquals("test prior guesses string", g, gamerB.priorGuessesString());
}


}
LinkedListGame.java

package guessme;


/**
* A LinkedList-based implementation of the Guess-A-Number game.
*/
public class LinkedListGame {


private boolean gameOver;


/********************************************************
* NOTE: for this project you must use linked lists
* implemented by yourself. You are NOT ALLOWED to use
* Java arrays of any type, or any class in the java.util
* package (such as ArrayList).
*******************************************************/


/********************************************************
* NOTE: you are allowed to add new methods if necessary,
* but DO NOT remove any provided method, and do NOT add
* new files (as they will be ignored by the autograder).
*******************************************************/


// LinkedListGame constructor method
public LinkedListGame() {
reset();
}


/** Resets data members and game state so we can play again.
*
*/
public void reset() {
gameOver = false;
}


/** Returns true if n is a prior guess; false otherwise.
*
*/
public boolean isPriorGuess(int n) {
// TODO
return false;
}


/** Returns the number of guesses so far.
*
*/
public int numGuesses() {
// TODO
return 0;
}


/**
* Returns the number of matches between integers a and b.
* You can assume that both are 4-digits long (i.e. between 1000 and 9999).
* The return value must be between 0 and 4.
*
* <p>A match is the same digit at the same location. For example:
* 1234 and 4321 have 0 match;
* 1234 and 1114 have 2 matches (1 and 4);
* 1000 and 9000 have 3 matches (three 0's).
*/


public static int numMatches(int a, int b)
{
String s1 = Integer.toString(a);
String s2 = Integer.toString(b);

   int l1=s1.length();
   int l2=s2.length();
  
   int i=0,j=0;
   int count=0;
while(i<l1 && j<l2)
{
   if(s1.charAt(i)==s2.charAt(j))
       {
       count++;
       }
   }      
return count;
}


/**
* Returns true if the game is over; false otherwise.
* The game is over if the number has been correctly guessed
* or if no candidate is left.
*/
public boolean isOver() {
return gameOver;
}


/**
* Returns the guess number and adds it to the list of prior guesses.
* The insertion should occur at the end of the prior guesses list,
* so that the order of the nodes follow the order of prior guesses.
*/
public int getGuess() {
// TODO: add guess to the list of prior guesses.
return 0;
}


/**
* Updates guess based on the number of matches of the previous guess.
* If nmatches is 4, the previous guess is correct and the game is over.
* Check project description for implementation details.
*
* <p>Returns true if the update has no error; false if no candidate
* is left (indicating a state of error);
*/
public boolean updateGuess(int nmatches) {
// TODO
return true;
}


/**
* Returns the head of the prior guesses list.
* Returns null if there hasn't been any prior guess
*/
public LLIntegerNode priorGuesses() {
// TODO
return null;
}


/**
* Returns the list of prior guesses as a String. For example,
* if the prior guesses are 1000, 2111, 3222, in that order,
* the returned string should be "1000, 2111, 3222", in the same order,
* with every two numbers separated by a comma and space, except the
* last number (which should not be followed by either comma or space).
*
* <p>Returns an empty string if here hasn't been any prior guess
*/
public String priorGuessesString() {
// TODO
return "";
}


}
LLIntegerNode.java

package guessme;


/**
* This class defines a linked list node storing an integer.
* Use primitive type int (do not use wrapper class Integer)
* You must provide the following methods:
* - a constructor
* - a setInfo method and a getInfo method
* - a setLink method and a getLink method
*/
public class LLIntegerNode
{
int info; //data
   LLIntegerNode link=NULL; //link for next node.
  
LLIntegerNode() //default constructor
   {

}
  
   LLIntegerNode(int info) //parameterize constructor
   {
this.info=info;
}
     
   //setter & getter for Info...
   public void setInfo(int info)
{
   this.info=info;
   }  
  
   public int getInfo()
   {
   return info;
   }
  
  
   //setter & getter for Link...
   public void setLink(LLIntegerNode link)
   {
   this.link=link;
   }
  
   public LLIntegerNode getLink()
   {
   return link;
   }

}

Add a comment
Know the answer?
Add Answer to:
Need help with a number guessing game in java 1) You should store prior guessses in...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In Java, you'll find that it contains several methods that have not yet been finished. For now, the methods contain...

    In Java, you'll find that it contains several methods that have not yet been finished. For now, the methods contain only a placeholder return value so that the code will compile. Fill in your own implementation. public class SomePracticeStringMethods { /* * returns true if c is a letter in the word "temple" or false otherwise */ public static boolean inTU(char c) { /* placeholder just so that the function * compiles. fill in your implementation here. * * there...

  • Java code tasks: Please help with a single class (class Coord) in this program. This project...

    Java code tasks: Please help with a single class (class Coord) in this program. This project is called Panic! We will describe a single-level floorplan of a building, filled with different kinds of people and different kinds of threats. We will simulate how the people seek to evacuate the building to safety, and how the threats spread throughout the building. Various events will be announced, such as person movements, threats spawning, and people reaching safety or succumbing to the threats....

  • Please help complete the items marked TODO in the code and get the tests to pass:...

    Please help complete the items marked TODO in the code and get the tests to pass: import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.junit.After; import org.junit.Before; import org.junit.Test; public class TestIterator { private List<Integer> list; // See the Java List Interface documentation to understand what all the List methods do ... @Before public void setUp() throws Exception { list = new ArrayList<Integer>(); // TODO also try with a...

  • I need help with todo line please public class LinkedList { private Node head; public LinkedList()...

    I need help with todo line please public class LinkedList { private Node head; public LinkedList() { head = null; } public boolean isEmpty() { return head == null; } public int size() { int count = 0; Node current = head; while (current != null) { count++; current = current.getNext(); } return count; } public void add(int data) { Node newNode = new Node(data); newNode.setNext(head); head = newNode; } public void append(int data) { Node newNode = new Node(data);...

  • Need some assistance coding this assembler exercise. I have included the test file. Thank you very...

    Need some assistance coding this assembler exercise. I have included the test file. Thank you very much. package sequencer; import java.util.List; public class Assembler {    /**    * Creates a new Assembler containing a list of fragments.    *    * The list is copied into this assembler so that the original list will not    * be modified by the actions of this assembler.    *    * @param fragments    */    public Assembler(List<Fragment> fragments) {   ...

  • Hi, for my Java class I have built a number guessing game. I need to separate...

    Hi, for my Java class I have built a number guessing game. I need to separate my code into two classes and incorporate a try-catch statement. Any help would be appreciated! Here is my code. import javax.swing.JOptionPane; import javax.swing.UIManager; import java.awt.Color; import java.awt.color.*; import java.util.Random; public class game { public static void main (String [] args) { UIManager.put("OptionPane.backround", Color.white); UIManager.put("Pandelbackround", Color.white); UIManager.put("Button.background", Color.white); Random nextRandom = new Random(); int randomNum = nextRandom.nextInt(1000); boolean playerCorrect = false; String keyboardInput; int playerGuess...

  • JAVA Hangman Your game should have a list of at least ten phrases of your choosing.The...

    JAVA Hangman Your game should have a list of at least ten phrases of your choosing.The game chooses a random phrase from the list. This is the phrase the player tries to guess. The phrase is hidden-- all letters are replaced with asterisks. Spaces and punctuation are left unhidden. So if the phrase is "Joe Programmer", the initial partially hidden phrase is: *** ********** The user guesses a letter. All occurrences of the letter in the phrase are replaced in...

  • Project 7-3 Guessing Game import java.util.Scanner; public class GuessNumberApp {    public static void main(String[] args)...

    Project 7-3 Guessing Game import java.util.Scanner; public class GuessNumberApp {    public static void main(String[] args) { displayWelcomeMessage(); // create the Scanner object Scanner sc = new Scanner(System.in); String choice = "y"; while (choice.equalsIgnoreCase("y")) { // generate the random number and invite user to guess it int number = getRandomNumber(); displayPleaseGuessMessage(); // continue until the user guesses the number int guessNumber = 0; int counter = 1; while (guessNumber != number) { // get a valid int from user guessNumber...

  • I need help with this. I need to create the hangman game using char arrays. I've...

    I need help with this. I need to create the hangman game using char arrays. I've been provided with the three following classes to complete it. I have no idea where to start. HELP!! 1. /** * This class contains all of the logic of the hangman game. * Carefully review the comments to see where you must insert * code. * */ public class HangmanGame { private final Integer MAX_GUESSES = 8; private static HangmanLexicon lexicon = new HangmanLexicon();...

  • Write a Java application program that plays a number guessing game with the user. In the...

    Write a Java application program that plays a number guessing game with the user. In the starter code that you are given to help you begin the project, you will find the following lines of code: Random generator = args.length == 0 ? new Random() :                    new Random(Integer.parseInt(args[0])); int secret = generator.nextInt(100); You must keep these lines of code in your program. If you delete these lines, or if you change thse lines in any way, then your program...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT