I need help finishing this coding assignment! Below are the directions of the as
ID: 3588187 • Letter: I
Question
I need help finishing this coding assignment!
Below are the directions of the assignment along with a code to start off with
The code must be done in C# and must be EXTREAMLY easy to understand as I am a begnner!
Thanks for the help!
------------------------------------------------------------------------------------------------
Directions
You need to implement a WinForm application that icludes Rectangle back-end class that is testable by frmRectangleTest class.
Description by example using Console app: RectangleTest below
------------------------------------------------------
Thank you so much for all the help mates!
Explanation / Answer
Hi,
All you need to write is the rectangle class, here it is,
class Rectangle
{
public double Length; // Length of the rectangle
public double Width; // Breadth of the rectangle
public void setLength( double length )//setter for length
{
Length = length;
}
public void setWidth( double width )//setter for width
{
Width = width;
}
public double getLength()//getter for length
{
return Length;
}
public double getWidth()//getter for width
{
return Width;
}
public String toString() {//to string method to print
return "length of the rectangle:" + this.Length + ",, "
+ "width of the rectangle::" + this.Width ;
}
i have added comments to help you understand
this is the full program plugged in with the above class
using System.IO;
using System;
class Program
{
class Rectangle
{
public double Length; // Length of the rectangle
public double Width; // Breadth of the rectangle
public void setLength( double length )//setter for length
{
Length = length;
}
public void setWidth( double width )//setter for width
{
Width = width;
}
public double getLength()//getter for length
{
return Length;
}
public double getWidth()//getter for width
{
return Width;
}
public String toString() {//to string method to print
return "length of the rectangle:" + this.Length + ",, "
+ "width of the rectangle::" + this.Width ;
}
}
static void Main()
{
Rectangle rectangle = new Rectangle();
int choice = GetMenuChoice();
while ( choice != 3 )
{
try
{
switch (choice)
{
case 1:
Console.Write( "Enter length: " );
rectangle.Length = Convert.ToDouble( Console.ReadLine() );
break;
case 2:
Console.Write( "Enter width: " );
rectangle.Width = Convert.ToDouble( Console.ReadLine() );
break;
}
Console.WriteLine(rectangle.ToString());
}
catch ( ArgumentOutOfRangeException ex )
{
Console.WriteLine( ex.Message );
}
Console.WriteLine();
choice = GetMenuChoice();
}
}
// displays a menu and returns the chosen value
private static int GetMenuChoice()
{
Console.WriteLine( "1. Set Length" );
Console.WriteLine( "2. Set Width" );
Console.WriteLine( "3. Exit" );
Console.Write( "Choice: " );
return Convert.ToInt32( Console.ReadLine() );
}
}
Thumbs up if this was helpful, otherwise let me know in comments
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.