Advertisement
Guest User

Untitled

a guest
Jan 21st, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. public class Room {
  5. private int numOfBeds;
  6. private Guest[] allGuests;
  7. private int numOfGuests;
  8.  
  9. public Room(int numOfBeds) {
  10. this.numOfBeds = numOfBeds;
  11. this.allGuests = new Guest[numOfBeds];
  12. this.numOfGuests = 0;
  13. }
  14.  
  15. public Room(Room otherRoom) {
  16. this.numOfBeds = otherRoom.getNumOfBeds();
  17. this.allGuests = new Guest[this.numOfBeds];
  18. for (int i = 0; i < otherRoom.getNumOfGuests(); i++) {
  19. this.allGuests[i] = new Guest(otherRoom.allGuests[i]);
  20. }
  21. }
  22.  
  23. public Room(String fileName) throws FileNotFoundException {
  24. File f = new File(fileName);
  25. Scanner sc = new Scanner(f);
  26. this.numOfBeds = sc.nextInt();
  27. this.numOfGuests = sc.nextInt();
  28. this.allGuests = new Guest[this.numOfBeds];
  29. for (int i = 0; i < this.getNumOfGuests(); i++) {
  30. this.allGuests[i] = new Guest(sc);
  31. }
  32. sc.close();
  33. }
  34.  
  35. public Room(Scanner sc) throws FileNotFoundException {
  36. this.numOfBeds = sc.nextInt();
  37. this.numOfGuests = sc.nextInt();
  38. this.allGuests = new Guest[this.numOfBeds];
  39. for (int i = 0; i < this.getNumOfGuests(); i++) {
  40. this.allGuests[i] = new Guest(sc);
  41. }
  42. }
  43.  
  44. public int getNumOfBeds() {
  45. return this.numOfBeds;
  46. }
  47.  
  48. public int getNumOfGuests() {
  49. return this.numOfGuests;
  50. }
  51.  
  52. public void setNumOfGuests(int number) {
  53. this.numOfGuests = number;
  54. }
  55.  
  56. public Guest[] getGuests() {
  57. return this.allGuests;
  58. }
  59.  
  60. public void addGuest(Guest guest) {
  61. this.allGuests[this.numOfGuests] = new Guest(guest);
  62. this.numOfGuests++;
  63. }
  64.  
  65. public void displayGuest(Guest guest) {
  66. System.out.println("Name: " + guest.getGuestName());
  67. System.out.println("Passport ID: " + guest.getPassportNumber());
  68. }
  69.  
  70. public void saveRoom(PrintWriter pw) throws FileNotFoundException {
  71. pw.println(this.numOfBeds);
  72. pw.println(this.getNumOfGuests());
  73. for (int i = 0; i < this.getNumOfGuests(); i++) {
  74. this.allGuests[i].saveGuest(pw);
  75. }
  76. }
  77.  
  78. public void saveRoom(String fileName) throws FileNotFoundException {
  79. File f = new File(fileName);
  80. PrintWriter pw = new PrintWriter(f);
  81. pw.println(this.numOfBeds);
  82. pw.println(this.numOfGuests);
  83. for (int i = 0; i < this.numOfGuests; i++) {
  84. this.allGuests[i].saveGuest(pw);
  85. }
  86. pw.close();
  87. }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement