Write a Java class called HotelRoom that represents a hotel room. The class will contain the following attributes: •RoomNo (int) •PhoneNumber (string) •Capacity (int) – Number of people that room can accommodate. •Grade (int) – Grade of room ranging 1-5, 5 being most valuable. Your class should have a constructor that takes a single parameter: RoomNo. The necessary accessors (i.e. get methods) and mutators (i.e. set methods) for class variables: Room number only accessor Phone number both mutator and accessor Capacity both mutator and accessor Grade both mutator and accessor 2.Write a Java class called Hotel that represents a hotel. The class will contain the following attributes: •Name (string) •ReceptionPhone (string) •RoomList (ArrayList of HotelRoom's) hotel class should have a constructor that takes two parameters: Hotel name and reception phone. The necessary accessors (i.e. get methods) and mutators (i.e. set methods) for class variables: Hotel name only accessor Reception phone both mutator and accessor 2)  Hotel class should have a public method addRoom that gets as parameter a Room object, and adds this Room object to RoomList: public void addRoom(HotelRoom room) Hotel class should have a public method getRoomCount that returns the number of rooms in the hotel (i.e. number of elements of RoomList): public static int getRoomCount() Hotel class should have a public method getRoom that returns the room from the room list given the index: public static HotelRoom getRoom(int index) Hotel class should have one public method in addition to the accessors and mutators: public String toString() It returns the information about the hotel rooms in the following format. ATTENTION: In this class, the toString method only returns the string representation of the rooms in the hotel, not whole information.  3) Write a Java application class that does the following: •Input a text file name entered by the user from keyboard. •Create a Hotel object that contains information read from a text file, using the readHotelmethod. Write a private static readHotel method that gets a file name as a parameter, reads the information about the hotel and rooms of the hotel from an input file and returns a Hotel object. In this method, create Hotel and HotelRoom objects as the input file is read, and insert HotelRoom objects to the ArrayList in the hotel object. private static Hotel readHotel(String filename) Format of the input file is assumed to be: a. The first line is the name of the hotel, b. The second line is the reception phone number of the hotel. Then several times c.Room no d.Phone number of rooms, e.The capacity of the room,   3 f.Quality (Grade) of room. Sample input file with two rooms (green text are comments, they do not exist in the actual input file): Examine the provided sample text file hotel.txt. hotel.txt = Crappy Hotel 911 101 91101 1 2 102 91102 2 1 103 91103 3 3 201 91201 4 2 202 91202 2 1 301 NoPhone 1 1

Programming with Microsoft Visual Basic 2017
8th Edition
ISBN:9781337102124
Author:Diane Zak
Publisher:Diane Zak
Chapter9: Sequential Access Files And Menus
Section: Chapter Questions
Problem 4MQ2
icon
Related questions
Question

Write a Java class called HotelRoom that represents a hotel room. The class will contain the following attributes:

•RoomNo (int)

•PhoneNumber (string)

•Capacity (int) – Number of people that room can accommodate.

•Grade (int) – Grade of room ranging 1-5, 5 being most valuable.

Your class should have a constructor that takes a single parameter: RoomNo. The necessary accessors (i.e. get methods) and mutators (i.e. set methods) for class variables:

Room number only accessor

Phone number both mutator and accessor

Capacity both mutator and accessor Grade both mutator and accessor

2.Write a Java class called Hotel that represents a hotel. The class will contain the following attributes:

•Name (string)

•ReceptionPhone (string)

•RoomList (ArrayList of HotelRoom's)

hotel class should have a constructor that takes two parameters: Hotel name and reception phone. The necessary accessors (i.e. get methods) and mutators (i.e. set methods) for class variables:

Hotel name only accessor

Reception phone both mutator and accessor

2)
  •  Hotel class should have a public method addRoom that gets as parameter a Room object, and adds this Room object to RoomList:

public void addRoom(HotelRoom room)

  • Hotel class should have a public method getRoomCount that returns the number of rooms in the hotel (i.e. number of elements of RoomList): public static int getRoomCount()
  • Hotel class should have a public method getRoom that returns the room from the room list given the index: public static HotelRoom getRoom(int index)

Hotel class should have one public method in addition to the accessors and mutators: public String toString() It returns the information about the hotel rooms in the following format.

ATTENTION: In this class, the toString method only returns the string representation of the rooms in the hotel, not whole information. 

3) Write a Java application class that does the following:

•Input a text file name entered by the user from keyboard.

•Create a Hotel object that contains information read from a text file, using the readHotelmethod. Write a private static readHotel method that gets a file name as a parameter, reads the information about the hotel and rooms of the hotel from an input file and returns a Hotel object. In this method, create Hotel and HotelRoom objects as the input file is read, and insert HotelRoom objects to the ArrayList in the hotel object. private static Hotel readHotel(String filename) Format of the input file is assumed to be:

a. The first line is the name of the hotel, b. The second line is the reception phone number of the hotel. Then several times

c.Room no

d.Phone number of rooms, e.The capacity of the room,

 

3 f.Quality (Grade) of room. Sample input file with two rooms (green text are comments, they do not exist in the actual input file): Examine the provided sample text file hotel.txt.

hotel.txt =

Crappy Hotel
911
101
91101
1
2
102
91102
2
1
103
91103
3
3
201
91201
4
2
202
91202
2
1
301
NoPhone
1
1

Your program code may look as follows:
. comment lines containing your name, surname, student-id and department
import java.util.Scanner;
import java.util.ArrayList;
import java.io.*;
public class Hw5_Lastname_Firstname
{
public static void main (String(] args) throws IOException
{
Hotel hotel = readHotel(infileName);
}
private static Hotel readHotel(String infileName) throws IOException
{
Hotel myHotel = new Hotel(hotelName,reception Phone);
return myHotel;
}
} // end class Hw5_Lastname_Firstname
class HotelRoom
{
....
class Hotel
{
....
| }
Transcribed Image Text:Your program code may look as follows: . comment lines containing your name, surname, student-id and department import java.util.Scanner; import java.util.ArrayList; import java.io.*; public class Hw5_Lastname_Firstname { public static void main (String(] args) throws IOException { Hotel hotel = readHotel(infileName); } private static Hotel readHotel(String infileName) throws IOException { Hotel myHotel = new Hotel(hotelName,reception Phone); return myHotel; } } // end class Hw5_Lastname_Firstname class HotelRoom { .... class Hotel { .... | }
Sample Run:
(User inputs are shown in blue.)
Enter file name: hotel.txt
HotelName : Crappy Hotel
HotelPhone: 911
ROOMS :
RoomNo: 101
PhoneNum: 91101
Сaраcity: 1
Grade: 2
RoomNo: 102
PhoneNum: 91102
Сaраcity: 2
Grade: 1
RoomNo: 103
PhoneNum: 91103
Сараcity: 3
Grade: 3
RoomNo: 201
PhoneNum: 91201
Сaрacity: 4
Grade: 2
RoomNo: 202
PhoneNum: 91202
Сарасcity: 2
Grade: 1
RoomNo: 301
PhoneNum : NoPhone
Сарасcity: 1
Grade: 1
Transcribed Image Text:Sample Run: (User inputs are shown in blue.) Enter file name: hotel.txt HotelName : Crappy Hotel HotelPhone: 911 ROOMS : RoomNo: 101 PhoneNum: 91101 Сaраcity: 1 Grade: 2 RoomNo: 102 PhoneNum: 91102 Сaраcity: 2 Grade: 1 RoomNo: 103 PhoneNum: 91103 Сараcity: 3 Grade: 3 RoomNo: 201 PhoneNum: 91201 Сaрacity: 4 Grade: 2 RoomNo: 202 PhoneNum: 91202 Сарасcity: 2 Grade: 1 RoomNo: 301 PhoneNum : NoPhone Сарасcity: 1 Grade: 1
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 5 images

Blurred answer
Knowledge Booster
void method
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
Computer Science
ISBN:
9780357392676
Author:
FREUND, Steven
Publisher:
CENGAGE L
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning