Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- public class Room {
- private int numOfBeds;
- private Guest[] allGuests;
- private int numOfGuests;
- public Room(int numOfBeds) {
- this.numOfBeds = numOfBeds;
- this.allGuests = new Guest[numOfBeds];
- this.numOfGuests = 0;
- }
- public Room(Room otherRoom) {
- this.numOfBeds = otherRoom.getNumOfBeds();
- this.allGuests = new Guest[this.numOfBeds];
- for (int i = 0; i < otherRoom.getNumOfGuests(); i++) {
- this.allGuests[i] = new Guest(otherRoom.allGuests[i]);
- }
- }
- public Room(String fileName) throws FileNotFoundException {
- File f = new File(fileName);
- Scanner sc = new Scanner(f);
- this.numOfBeds = sc.nextInt();
- this.numOfGuests = sc.nextInt();
- this.allGuests = new Guest[this.numOfBeds];
- for (int i = 0; i < this.getNumOfGuests(); i++) {
- this.allGuests[i] = new Guest(sc);
- }
- sc.close();
- }
- public Room(Scanner sc) throws FileNotFoundException {
- this.numOfBeds = sc.nextInt();
- this.numOfGuests = sc.nextInt();
- this.allGuests = new Guest[this.numOfBeds];
- for (int i = 0; i < this.getNumOfGuests(); i++) {
- this.allGuests[i] = new Guest(sc);
- }
- }
- public int getNumOfBeds() {
- return this.numOfBeds;
- }
- public int getNumOfGuests() {
- return this.numOfGuests;
- }
- public void setNumOfGuests(int number) {
- this.numOfGuests = number;
- }
- public Guest[] getGuests() {
- return this.allGuests;
- }
- public void addGuest(Guest guest) {
- this.allGuests[this.numOfGuests] = new Guest(guest);
- this.numOfGuests++;
- }
- public void displayGuest(Guest guest) {
- System.out.println("Name: " + guest.getGuestName());
- System.out.println("Passport ID: " + guest.getPassportNumber());
- }
- public void saveRoom(PrintWriter pw) throws FileNotFoundException {
- pw.println(this.numOfBeds);
- pw.println(this.getNumOfGuests());
- for (int i = 0; i < this.getNumOfGuests(); i++) {
- this.allGuests[i].saveGuest(pw);
- }
- }
- public void saveRoom(String fileName) throws FileNotFoundException {
- File f = new File(fileName);
- PrintWriter pw = new PrintWriter(f);
- pw.println(this.numOfBeds);
- pw.println(this.numOfGuests);
- for (int i = 0; i < this.numOfGuests; i++) {
- this.allGuests[i].saveGuest(pw);
- }
- pw.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement