Advertisement
Guest User

I would like to die

a guest
Dec 5th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.50 KB | None | 0 0
  1.  
  2.  
  3. import java.util.Map;
  4. import java.util.HashMap;
  5. //import java.util.List;
  6. //import java.util.ArrayList;
  7.  
  8.  
  9. public class Hotel {
  10. //this should not interact with room.
  11. private String name;
  12. private int singleBeds;
  13. private int doubleBeds;
  14. //private List<Room> l = new ArrayList<Room>;
  15. private Map<Integer,Room> rooms = new HashMap<Integer,Room>();
  16.  
  17.  
  18. // use math.abs() for any integers
  19. //method to add beds to map, with bed number
  20.  
  21. //adds a room with a unique number key to map.
  22.  
  23.  
  24. //method to add single beds.
  25.  
  26.  
  27. public void addRoom(int numberOfRooms){
  28. for(int j = 0 /*should this be 1?*/; j<numberOfRooms; j++){
  29. rooms.put(j, new Room());
  30.  
  31. //j is the key, e.g. number of rooms = 4, 4 rooms added, indexed 0-3
  32. }
  33.  
  34. }
  35.  
  36. public int roomList(){
  37. return rooms.size();
  38. }
  39.  
  40. //method in room to add number of rooms with certain
  41. //number of singles, and doubles
  42. //move this method into rooms
  43. //careful with roomNumber. it will be -1.
  44. public void numOfBeds(int roomNumber, int singles, int doubles){
  45. singleBeds = Math.abs(singles);
  46. doubleBeds = Math.abs(doubles);
  47.  
  48. //put this into room, maybe?
  49. //will have to iterate through rooms?
  50. for(int i = 0; i < singleBeds; i++){
  51. rooms.get(roomNumber).setBed("single");
  52. }
  53. for(int i = 0; i < doubleBeds; i++){
  54. rooms.get(roomNumber).setBed("double");
  55. }
  56. }
  57.  
  58. // setting hotel name
  59. public void setName(String s) {
  60. name = s;
  61. }
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. // getting hotel name
  71. public String getName() {
  72. return name;
  73. }
  74.  
  75.  
  76.  
  77. //constructor
  78. //this is the correct constructor
  79. public Hotel(String name, int numberOfRooms){
  80. setName(name);
  81. addRoom(numberOfRooms);
  82. }
  83.  
  84.  
  85.  
  86. //bad constuctor
  87. public Hotel(String name, int numberOfRooms, int roomNumber, int singles, int doubles){
  88. setName(name);
  89. addRoom(numberOfRooms);
  90. numOfBeds(roomNumber, singles, doubles);
  91. }
  92.  
  93.  
  94.  
  95. import java.util.ArrayList;
  96. import java.util.List;
  97.  
  98.  
  99.  
  100.  
  101. public class Room {
  102.  
  103.  
  104.  
  105.  
  106. private List<Bed> beds;/* = new ArrayList<Bed>();*/
  107.  
  108.  
  109.  
  110. private String size;
  111. //private int singleBeds;
  112. //private int doubleBeds;
  113. // need to make a list inside of room list for each room
  114.  
  115.  
  116. public Room() {
  117. //demonstrator said to do this, for memory reasons or something, dont get why.
  118. this.beds = new ArrayList<Bed>();
  119. }
  120.  
  121. //this constructor should have number of single and double beds.
  122. public Room(String string) {
  123. setBed(string);
  124.  
  125.  
  126. }
  127.  
  128.  
  129. //number of beds
  130.  
  131. // lets make methods to get/set singular beds.
  132.  
  133.  
  134. public void setBed(String s) {
  135. size = s;
  136. beds.add(new Bed(s));
  137. }
  138.  
  139.  
  140. public Bed getBed(int i) {
  141. // arrayLists index at 0. careful here.
  142. return beds.get(i);
  143. }
  144.  
  145.  
  146. // perhaps a method to get overall size of list
  147. public int totalBeds() {
  148. return beds.size();
  149. }
  150.  
  151.  
  152. }
  153.  
  154.  
  155. }
  156.  
  157.  
  158.  
  159. public class Bed {
  160.  
  161.  
  162. private String size;
  163.  
  164.  
  165. public Bed(String s) {
  166. setSize(s);
  167.  
  168.  
  169. }
  170.  
  171.  
  172. // check inputs
  173. public void setSize(String s) {
  174. size = s.toLowerCase();
  175. if (size != "double" || size != "single") {
  176. throw new IllegalArgumentException("Invalid bed type");
  177. // maybe catch later on to prevent crashing
  178. }
  179. }
  180.  
  181.  
  182. public String getSize() {
  183. return size;
  184. }
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191. // else, set s to either double or single.
  192.  
  193.  
  194. // maybe make enumerated? not sure yet.
  195. // throw exception if not equal to double or single?
  196.  
  197.  
  198. // method for max occupancy. loop, adding each beds value together
  199.  
  200.  
  201. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement