CIS 3120
Design and Implementation of Software Applications I
Lab 2

What to Do

  1. Start with the Coin class example :
  2. public class Coin {
       public static final int HEADS = 0 ; 
       public static final int TAILS = 1 ; 
       private int face ;     
       private int value ;   
        
       public Coin(int value) {
          this.value = value ; 
          flip(); 
       } 
    
       public void flip() {
          face = (int) (Math.random() * 2); 
       }
        
       public int getFace() { return face; }
    
       public int getValue() { return value; }
    
       public String toString() {
          String facename; 
          if( face == HEADS ) {
             facename = "heads"; 
          }
          else {
             facename = "tails";
          }
          return ( Integer.toString(value) + " cent coin, face: " + facename ); 
       }
    }
    			
  3. Save this class in a separate file, Coin.java
  4. Perform a unit test for Coin class (don't do it the same way we did in class)
  5. Write a new class called CoinFlip. It will contain a main method which will perform the following:
  6. Make sure that when you run Coin, the unit test gets executed and when you run CoinFlip the above program gets executed.
  7. Add a printUsage method to the CoinFlip class which will print a few sentences about how the game should be played.
    Modify the main method to call this function whenever the user provides an invalid input.

Additional info: Reading user input using Scanner

What to Submit

You should complete lab by the indicated due date. Please read this carefully:

Results of the labs and assignments that do not involve usage of web server should be submitted as follows: