Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Console Practical Assessment #3

Create a new console application

Create a class to capture properties for a "Hotel".

This class should have the following properties:
Name
Address
HasPool (this should be a boolean)
RoomCount
HasAvailability (this should be a boolean)
AverageRoomCost (double)

Create a List or Array of these objects (at least 3). Be sure to give each object instance values for all their properties.

Loop through all of the objects in your List or Array and output the object in the following format:

Embassy Suites, 100 Main St Los Angele CA 90010, Does Have availability in the total rooms of 123
Embassy Suites, 100 Main St Los Angele CA 90010, Does Not Have availability in the total rooms of 123

*Bonus
Create a second loop but only display Hotels that have availability with rooms costing less than $100

What I have tried:

C#
class Program
{
    static void Main(string[] args)
    {
        Hotel EmbassySuites = new Hotel();

        EmbassySuites.Name = "EmbassySuites";
        EmbassySuites.Address = "100 Main St Los Angele CA 90010";
        EmbassySuites.HasPool = true;
        EmbassySuites.RoomCount = 123;
        EmbassySuites.HasAvailability = true;
        EmbassySuites.AverageRoomCost = 100.00;


        Console.WriteLine("Hotel's Name is: " + EmbassySuites.Name);
        Console.WriteLine("Hotel's Address is: " + EmbassySuites.Address);
        Console.WriteLine("Does Hotel have pool?: " + EmbassySuites.HasPool);
        Console.WriteLine("Hotel's RoomCount is: " + EmbassySuites.RoomCount);
        Console.WriteLine("Does the Hotel have availability?: " + EmbassySuites.HasAvailability);
        Console.WriteLine("Hotel's average room cost: " + EmbassySuites.AverageRoomCost);

        Console.ReadLine();
    }

    class Hotel
    {
        public string Name { get; set; }
        public string Address { get; set; }
        public bool HasPool { get; set; }
        public int RoomCount { get; set; }
        public bool HasAvailability { get; set; }
        public double AverageRoomCost { get; set; }

        public bool CheckPool()
        {
            if (this.HasPool == true)
            {
              this.HasPool = true;
              return this.HasPool;
            }
            else
            {
              this.HasPool = false;
                return this.HasPool;
            }
        }
    }
}
Posted
Updated 27-Oct-16 20:06pm
v2

So you have done the first bit - well done.
Now look at the second part, and start working on that, because what you have done so far is the trivial bit, and we are not here to do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!

If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!
 
Share this answer
 
Comments
Rahul VB 30-Oct-16 10:40am    
Correct as usual :D. My 5!
Your CheckPool is doing a lot of redundant things. If a variable is true then there is no point setting it to be true again, likewise for false, so strip those

C#
public bool CheckPool()
{
    if (this.HasPool == true)
    {
        return this.HasPool;
    }
    else
    {
        return this.HasPool;
    }
}



Now you can see that all it really does is return HasPool so you can get rid of the "if"

C#
public bool CheckPool()
{
    return this.HasPool;
}



There is no point in having a function that simply returns a property so get rid of "CheckPool" altogether and have your code look at HasPool instead.

As already said though we're not going to do your homework for you. This is quite a simple exercise so if you can't do it then you need to go back over what you've already been taught until you understand it. Google "c# for loops" and "c# array" to see how you do arrays and loops.
 
Share this answer
 
v2
Comments
Rahul VB 30-Oct-16 10:39am    
That's a perfect 5! from my side especially for your explanation on :
public bool CheckPool()
{
return this.HasPool;
}

Well said.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900