Answer on Question #59720 - Programming & Computer Science - C# | Completed
Task:
Write a main() that creates a hotel room with room number 123, with a capacity of 4, and a rate of 150.00. Suppose a person checks in. The program should ask the user to enter the number of guests to occupy the room. Change the status of the room to reflect the number of guests that just checked in. Display the information about the room in a nicely formatted way. Now assume that the guests check out. Change the status of the room appropriately and display the information about the room. Next, change the room rate to 175.00. Finally, assume that another person checks in. Ask the user to enter the number of guests to occupy the room. Change the room's status accordingly and display the new information about the room.
Answer:
using System;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Room
{
public Room()
{
Number = 123;
Capacity = 4;
Rate = 150;
Checked = false;
}
public int Number { get; set; }
public int Capacity { get; set; }
public double Rate { get; set; }
public Boolean Checked { get; set; }
public override string ToString()
{
String s = "";
s = Checked ? "checked." : "unchecked.";
return "Number of the room : " + Number.ToString() + ", capacity : " + Capacity.ToString() + ", rate : " + Rate.ToString() + ", room is " + s;
}
}
class Program
{
static void Main(string[] args)
{
Room room = new Room();
}
int num_of_guests;
Console.Write("Enter number of guests: ");
num_of_guests = Convert.ToInt32(Console.ReadLine());
room.Capacity = num_of_guests;
room.Checked = true;
Console.WriteLine(room.ToString());
room.Checked = false;
room.Rate = 175.00;
Console.Write("Enter number of guests: ");
num_of_guests = Convert.ToInt32(Console.ReadLine());
room.Capacity = num_of_guests;
room.Checked = true;
Console.WriteLine(room.ToString());
Console.Read();
}
Comments