❔ Interface c#
Im trying to make an interface method in order to calculate area of circles and triangles. However I get 4 errors that are attached. How do I solve this?
namespace Övning_2._4_Clipart
{
public partial class Form1 : Form
{
List<Figur> FigurLista = new List<Figur>();
double summa = 0; public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { listBox1.Items.Clear(); double bredd = double.Parse(textBox1.Text); double höjd = double.Parse(textBox2.Text); Figur nyFigur = new Triangel(bredd, höjd); IArea triangeln = new AreaTriangel(bredd, höjd); double resultat = triangeln.TriangelArea;
FigurLista.Add(nyFigur); textBox1.Clear(); textBox2.Clear(); foreach (Figur f in FigurLista) { listBox1.Items.Add(f); } } private void button2_Click(object sender, EventArgs e) { listBox1.Items.Clear(); double bredd = double.Parse(textBox1.Text); double höjd = double.Parse(textBox2.Text); Figur nyFigur = new Cirkel(bredd, höjd); IArea cirkeln = new AreaCirkel(bredd, höjd); double resultat = cirkeln.CirkelArea; FigurLista.Add(nyFigur); textBox1.Clear(); textBox2.Clear(); foreach (Figur f in FigurLista) { listBox1.Items.Add(f); } } private void button3_Click(object sender, EventArgs e) { listBox1.Items.Clear(); double bredd = double.Parse(textBox1.Text); double höjd = double.Parse(textBox2.Text); Figur nyFigur = new Linje(bredd, höjd); FigurLista.Add(nyFigur); textBox1.Clear(); textBox2.Clear(); foreach (Figur f in FigurLista) { listBox1.Items.Add(f); } } private void button4_Click(object sender, EventArgs e) { double bredd = double.Parse(textBox1.Text); double höjd = double.Parse(textBox2.Text); foreach (Figur f in FigurLista) {
} } } } using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Övning_2._4_Clipart { class Triangel : Figur { public Triangel (double bredd, double höjd) : base(bredd, höjd) { } public override string ToString() { return "Triangel: " + this.Bredd + "x" + this.Höjd; } class AreaTriangel : IArea { double bredd, höjd; public AreaTriangel(double bredd, double höjd) { this.bredd = bredd; this.höjd = höjd; } public double CirkelArea() { return 0; } public double TriangelArea() { return (bredd * höjd) / 2; } } } } using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class AreaCirkel : IArea { double bredd, höjd; public AreaCirkel (double bredd, double höjd) { this.bredd = bredd; this.höjd = höjd; }
public double CirkelArea() { return (Math.PI * bredd * bredd); } //public double TriangelArea() { return (bredd * höjd) / 2; } public double TriangelArea() { return 0; } } } } using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Övning_2._4_Clipart { public interface IArea { double CirkelArea(); double TriangelArea(); //double Summa(); } }
double summa = 0; public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { listBox1.Items.Clear(); double bredd = double.Parse(textBox1.Text); double höjd = double.Parse(textBox2.Text); Figur nyFigur = new Triangel(bredd, höjd); IArea triangeln = new AreaTriangel(bredd, höjd); double resultat = triangeln.TriangelArea;
FigurLista.Add(nyFigur); textBox1.Clear(); textBox2.Clear(); foreach (Figur f in FigurLista) { listBox1.Items.Add(f); } } private void button2_Click(object sender, EventArgs e) { listBox1.Items.Clear(); double bredd = double.Parse(textBox1.Text); double höjd = double.Parse(textBox2.Text); Figur nyFigur = new Cirkel(bredd, höjd); IArea cirkeln = new AreaCirkel(bredd, höjd); double resultat = cirkeln.CirkelArea; FigurLista.Add(nyFigur); textBox1.Clear(); textBox2.Clear(); foreach (Figur f in FigurLista) { listBox1.Items.Add(f); } } private void button3_Click(object sender, EventArgs e) { listBox1.Items.Clear(); double bredd = double.Parse(textBox1.Text); double höjd = double.Parse(textBox2.Text); Figur nyFigur = new Linje(bredd, höjd); FigurLista.Add(nyFigur); textBox1.Clear(); textBox2.Clear(); foreach (Figur f in FigurLista) { listBox1.Items.Add(f); } } private void button4_Click(object sender, EventArgs e) { double bredd = double.Parse(textBox1.Text); double höjd = double.Parse(textBox2.Text); foreach (Figur f in FigurLista) {
} } } } using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Övning_2._4_Clipart { class Triangel : Figur { public Triangel (double bredd, double höjd) : base(bredd, höjd) { } public override string ToString() { return "Triangel: " + this.Bredd + "x" + this.Höjd; } class AreaTriangel : IArea { double bredd, höjd; public AreaTriangel(double bredd, double höjd) { this.bredd = bredd; this.höjd = höjd; } public double CirkelArea() { return 0; } public double TriangelArea() { return (bredd * höjd) / 2; } } } } using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class AreaCirkel : IArea { double bredd, höjd; public AreaCirkel (double bredd, double höjd) { this.bredd = bredd; this.höjd = höjd; }
public double CirkelArea() { return (Math.PI * bredd * bredd); } //public double TriangelArea() { return (bredd * höjd) / 2; } public double TriangelArea() { return 0; } } } } using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Övning_2._4_Clipart { public interface IArea { double CirkelArea(); double TriangelArea(); //double Summa(); } }
4 Replies
double resultat = cirkeln.CirkelArea;
thats not how you invoke a method
try adding ()
to make it an actual method call(Side note: WTF are those namespaces...?)
Literally "assignment 2.4 clipart"
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.