In c# \"Create a program named TilingDemo that instantiates an array of 10 Room
ID: 3883159 • Letter: I
Question
In c# "Create a program named TilingDemo that instantiates an array of 10 Room objects and demonstrates its methods. The Room constructor requires parameters for length and width fields; use a variety of values when constructing the objects. The Room class also contains a field for floor area of the Room and number of boxes of tile needed to tile the room. Both of these values are computed by calling private methods. A room requires one box of tile for every 12 full square feet plus a box for any partial square footage over 12, plus one extra box for waste from irregular cuts. In other words, a 122 square foot room requires 12 boxes—10 boxes for the first 120 square feet, 1 box for the 2 extra square feet over 120, and 1 box for waste. Include read-only properties to get a Room’s values."
Farrell, Joyce. Microsoft Visual C# 2015: An Introduction to Object-Oriented Programming (Page 418).
Thank you in advance for your help.
Explanation / Answer
TilingDemo.cs
--------------------------------------
using System;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TilingDemo
{
class TilingDemo
{
static void Main(string[] args)
{
Write("Enter the length of the room >> ");
int x = Convert.ToInt32(ReadLine());
Write("Enter the height of the room >> ");
int y = Convert.ToInt32(ReadLine());
Room inputfeet = new Room(x,y);
WriteLine("The square feet of your room is {0} and you are going to need {1} boxes.",inputfeet.getFloorArea(), inputfeet.getBoxes());
Console.Write("Click enter to escape...");
Console.ReadLine();
}
}
}
---------------------------------------------------------------------
Room.cs
-----------------------------------
using System;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TilingDemo
{
class Room
{
int width { get; }
int length { get; }
int floorArea;
int boxes;
public Room(int length, int width)
{
this.length = length;
this.width = width;
}
public int getFloorArea()
{
floorArea = length * width;
return floorArea;
}
private int cBoxes(int squareFeet)
{
int quad = squareFeet / 12;
int remainder = squareFeet % 12;
int extra;
if (remainder == 0)
{
extra = 0;
}
else
{
extra = 1;
}
return quad + extra + 1;
}
public int getBoxes()
{
return cBoxes(floorArea);
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.