CS1150 (Spring 2013): Programming Assignment 2



  1. Start with the following code:
    /* HigherOrLower.java
     * Your name
     * CS1150.1301, Programming Assignment #2
     * In your own words, describe the program
    import java.util.Scanner;
    public class HigherOrLower {
      public static void main(String[] args) {
        Scanner keyboard = new Scanner(System.in);
        // Your code will go here
  2. Save the file as HigherOrLower.java.
  3. Add code to create a "higher or lower" game, as follows:
    1. Use Math.random() to generate an integer from 1 to 10 (inclusive). Keep in mind that Math.random() gives back a double between 0 and 1, so it needs to be scaled (multiplied), rounded up (Math.ceil()), and casted to an int.
    2. Ask the user for an integer (their guess). There are three possibilities:
    3. Ask the user for a second guess. Options are the same as for the first guess
    4. Ask the user for a third guess. This time, the user either guessed it or they didn't. Print an appropriate message. In either case, this should be the end of the program<./li>
  4. Play the game a couple times (more than once) and save the output of each.


Submit the source code file (HigherOrLower.java) and the output of your testing.

NOTE: It is OK, in order to print the output, to replace "System.exit(0);" with "return;". Don't worry about what return does and why it works, just use it verbatim and trust that it does, in fact, have the desired result. We will talk about "return" when we talk about methods.