C# Create a class called RoomInfo: It includes the following private variables f
ID: 3920628 • Letter: C
Question
C#
Create a class called RoomInfo: It includes the following private variables for class: • length (double) • width (double) • hasTV (bool) • houseSize(static double) It also includes the following functions for class: • Constructors • Properties for each variable • calcRoomSize: this function calculates the room size and update the house size. • Create a class called RoomInfoDemo: It includes the following functions: 1. main function: • create an array of four RoomInfo objects • call getData function for each room • Display room and house size • Display number of rooms have TV 2. getData function: • pass the object into this function via parameter • prompt user to enter the length and width for each room • prompt user to enter: ‘Y’ if there is a TV in the room or ‘N’ if there is none, and save the result in the “hasTV” variable.
Explanation / Answer
using System;
namespace Room Application
{
class RoomInfo
{
//data members
private double length;
private double width;
private bool hasTV;
private static double houseSize;
//constructor....
//parameter constructor sets values..
public RoomInfo(double l,double w,bool h)
{
length = l;
width = w;
hasTV = h;
}
//default constructor
public RoomInfo()
{
length = 1;
width = 1;
}
//method cal room size
public void calcRoomSize()
{
houseSize = length*width;
}
//getdata methods
public double getLength()
{
return length;
}
public double getwidth()
{
return width;
}
public bool gethasTV()
{
return hasTV;
}
public double getHousesSize()
{
return houseSize;
}
//setter methods
public setLength(double l)
{
length = l;
}
public setwidth(double l)
{
width = l;
}
public sethasTV(bool l)
{
hasTV = l;
}
}
class RoomInfoDemo()
{
static void Main(string[] args)
{
//creating array of four room objects
RoomInfo r[] = RoomInfo[4];
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.