Advertisement
Guest User

Untitled

a guest
Feb 5th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.92 KB | None | 0 0
  1. /**
  2.  * The class <b>Door</b> stores the information about one of the door:
  3.  * does it have the prize behind it? Is it open or closed? Was it
  4.  * selected by the player?
  5.  *
  6.  * It provides other objects access to these information through some
  7.  * <b>setters</b> and <b>getters</b>.
  8.  *
  9.  * @author gvj (gvj@eecs.uottawa.ca)
  10.  *
  11.  */
  12. public class Door {
  13.    
  14.     // ADD YOUR INSTANCE VARIABLES HERE
  15.    
  16.     private boolean isOpen = false;
  17.     private boolean hasPrize = false;
  18.     private String name = "";
  19.     private boolean isChosen = false;
  20.     /**
  21.      * Creates an instance of the Door object.
  22.      * Initially, the door is closed, doesn't have a prize behind it
  23.      * and has not been chosen by the player.
  24.      *
  25.      * @param name identifier for that door
  26.      */
  27.     public Door(String name){
  28.         this.name = name;
  29.     }
  30.  
  31.     /**
  32.      * Resets the door to its initial state: closed, without a prize behind it
  33.      * and not chosen by the player.
  34.      */
  35.     public void reset(){
  36.         isOpen = false;
  37.         hasPrize = false;
  38.         isChosen = false;
  39.     }
  40.    
  41.     /**
  42.      * Sets this door open.
  43.      */
  44.     public void open(){
  45.         isOpen = true;
  46.     }
  47.    
  48.     /**
  49.      * Checks if the door is open.
  50.      * @return true if the door is open
  51.      */
  52.     public boolean isOpen(){
  53.         return isOpen;
  54.     }
  55.    
  56.     /**
  57.      * Puts the prize behind this door.
  58.      */
  59.     public void setPrize(){
  60.         hasPrize = true;
  61.     }
  62.    
  63.     /**
  64.      * Checks if the door has the prize.
  65.      * @return true if the door has the prize
  66.      */
  67.     public boolean hasPrize(){
  68.         return hasPrize;
  69.     }
  70.    
  71.     /**
  72.      * Sets this door as selected by the player.
  73.      */
  74.     public void choose(){
  75.         isChosen = true;
  76.     }
  77.  
  78.     /**
  79.      * Checks if the door is selected by the player.
  80.      * @return true if the door is selected by the player
  81.      */
  82.     public boolean isChosen(){
  83.         return isChosen;
  84.     }
  85.    
  86.    
  87.     /**
  88.      * @return the door's identifier
  89.      */
  90.     public String getName(){
  91.         return name;
  92.     }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement