heres the steps i have done so far Here are the steps to complete this assignment in
Question:
heres the steps i have done so far
Here are the steps to complete this assignment in C# using Visual Studio:
- Open Visual Studio and create a new Windows Forms App project.
- Add a ListBox control to the form by dragging it from the Toolbox onto the form.
- Create an abstract class called Shape by right-clicking on the project in Solution Explorer, selecting Add, and then selecting Class. In the new class file, add the following code:
public abstract class Shape { private static int shapeCount = 0; public static int ShapeCount { get { return shapeCount; } } public abstract double Area { get; } protected Shape() { shapeCount++; } }
Create a class called Circle that inherits from Shape. In the same class file as Shape, add the following code:
public class Circle : Shape { private double radius; public Circle(double radius) { this.radius = radius; } public double Radius { get { return radius; } } public double Diameter { get { return radius * 2; } } public override double Area { get { return Math.PI * radius * radius; } } public void ChangeRadius(double newRadius) { radius = newRadius; } }
Create a class called Rectangle that inherits from Shape. In the same class file as Shape, add the following code:
public class Rectangle : Shape { private double length; private double width; public Rectangle(double length, double width) { this.length = length; this.width = width; } public double Length { get { return length; } } public double Width { get { return width; } } public override double Area { get { return length * width; } } }
this is where i need help with, i have no clue where this code goes the one below, i tried adding it to the forms class, but it gives me an error, please do step by step for all this code for me, it would be alot of greate help
private void DisplayArea(Shape shape) { listBox1.Items.Add("Area: " + shape.Area); MessageBox.Show("Area: " + shape.Area); }
In the form's class file, add the following method:
private void DisplayArea(Shape shape) { listBox1.Items.Add("Area: " + shape.Area); MessageBox.Show("Area: " + shape.Area); }
- Add two buttons to the form by dragging Button controls from the Toolbox onto the form.
- For Button 1, set the Text property to "Create Circle" and add the following code to its Click event:
Circle circle = new Circle(5); listBox1.Items.Add("Circle created with radius " + circle.Radius); DisplayArea(circle); listBox1.Items.Add("Changing radius to 10"); circle.ChangeRadius(10); listBox1.Items.Add("New radius: " + circle.Radius); listBox1.Items.Add("New diameter: " + circle.Diameter); DisplayArea(circle); listBox1.Items.Add("Total shapes created: " + Shape.ShapeCount);
For Button 2, set the Text property to "Create Rectangle" and add the following code to its Click event:
Rectangle rectangle = new Rectangle(3, 4); listBox1.Items.Add("Rectangle created with dimensions " + rectangle.Length + " x " + rectangle.Width); DisplayArea(rectangle); listBox1.Items.Add("Total shapes created: " + Shape.ShapeCount);
Create an interface called IMover by right-clicking on the project in Solution Explorer, selecting Add, and then selecting Interface. In the new interface file, add the following code:
public interface IMover { string Move(); }
Create an interface called IGlow with two methods: Glow, which returns a string, and Calculate, which also returns a string:
public interface IGlow { string Glow(); string Calculate(); }
Create a base class called Animal with a method called Eat that takes in a string and returns a formatted string:
public class Animal { public string Eat(string food) { return quot;This animal eats a(n) {food}"; } }
make a class called Hawk
- Extends the animal class
- Implements iMover
- Move will
- Display "I ZOOM!" in a message box
- Return "I ZOOM!"
make a class called PurpleMold
- Implements iMover and IGlow
- Move will display in a message box and return "squirch squirch"
- Calculate will return "Computation not possible: too hard"
- Glow will display "Purple iridescence: powered up!" in a message box and return this same message
Using the interfaces and classes
using System; using System.Windows.Forms; public interface IMover { string Move(); } public interface IGlow { string Glow(); } public class Animal { public string Eat(string food) { return quot;Eating {food}..."; } } public class Hawk : Animal, IMover { public string Move() { MessageBox.Show("I ZOOM!"); return "I ZOOM!"; } } public class PurpleMold : IMover, IGlow { public string Move() { MessageBox.Show("squirch squirch"); return "squirch squirch"; } public string Glow() { MessageBox.Show("Purple iridescence: powered up!"); return "Purple iridescence: powered up!"; } public string Calculate() { return "Computation not possible: too hard"; } }
Using the interfaces and classes
On the form
- create a method called MoveIt that takes in anything that uses IMover
- execute the move method
- create a method called BopIt that takes in anything that uses IGlow
- execute the glow method
- add the response from Calculate to the list box ("Calculate has returned : " and the value)
- create a button that will
- Display a divider in the list box (space, line, whatever)
- Display in the listbox "Purple mold is created"
- Create a purple mold
- Display in list box: asking mold to move
- Send mold to the moveit
- Display in the list box: bopping mold
- Send mold to the bopit method
- Display a divider in the list box (space, line, whatever)
- Display in the listbox "Hawk is created"
- Create a hawk
- Display in the list box tossing hawk into the air
- Send the hawk to the moveIt method
- Display in the list box "Feeding hawk a well-balanced meal"
- Using the hawk's eat method display the results in the list box sending in "mouse"
using System; using System.Windows.Forms; public interface IMover { string Move(); } public interface IGlow { string Glow(); } public class Animal { public string Eat(string food) { return "Eating " + food; } } public class Hawk : Animal, IMover { public string Move() { MessageBox.Show("I ZOOM!"); return "I ZOOM!"; } } public class PurpleMold : IMover, IGlow { public string Move() { MessageBox.Show("squirch squirch"); return "squirch squirch"; } public string Calculate() { return "Computation not possible: too hard"; } public string Glow() { MessageBox.Show("Purple iridescence: powered up!"); return "Purple iridescence: powered up!"; } } public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void MoveIt(IMover mover) { mover.Move(); } private void BopIt(IGlow glower) { glower.Glow(); } private void button1_Click(object sender, EventArgs e) { listBox1.Items.Add("--------------------"); listBox1.Items.Add("Purple mold is created"); PurpleMold mold = new PurpleMold(); listBox1.Items.Add("Asking mold to move"); MoveIt(mold); listBox1.Items.Add("Bopping mold"); BopIt(mold); listBox1.Items.Add("--------------------"); listBox1.Items.Add("Hawk is created"); Hawk hawk = new Hawk(); listBox1.Items.Add("Tossing hawk into the air"); MoveIt(hawk); listBox1.Items.Add("Feeding hawk a well-balanced meal"); string result = hawk.Eat("mouse"); listBox1.Items.Add("Hawk eat result: " + result); } }
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill