Home > Net >  Error what to change in novice for help (image)
Error what to change in novice for help (image)

Time:11-23

C #, interface area computation (stealth), keyboard input length and width, it is concluded that area
Using System;
using System.Collections.Generic;
Using System. Linq;
Using System. The Text;
Using System. The Threading. The Tasks;
The implementation of the namespace interface
{
Interface IShape
{
Int Length {get; The set; }
Int Width {get; The set; }
Void Area ();
}

The class Test: IShape
{
Public int Chang=0;
Public int Kuan=0;

Public int Length
{
The get {return Length; }
The set {Length=value; }
}

Public int Width
{
The get {return Width; }
The set {Width=value; }
}

Public void Area ()
{var Area=Length * Width; Console. WriteLine (Area);
}
}

Class Program
{
The static void Main (string [] args)
{

The Test cm=new Test ();
IShape x=cm;
Console. WriteLine (" please enter the rectangular wide: "); Cm. Kuan=the Convert. ToInt32 (Console. ReadLine ()); Console. WriteLine (" please enter a long rectangular: "); Cm. Chang=the Convert. ToInt32 (Console. ReadLine ()); Console. WriteLine (" the area of the rectangle is: "); Console. WriteLine (x.G etArea ()); Console.ReadLine();
}
}
}

CodePudding user response:

IShape class does not define the method GetArea, you look at the x class definition

CodePudding user response:

Your IShape is defined in the interface Area () method, which is not GetArea () method, it is good to change
And the Console. WriteLine (x.G etArea ()); This code is also wrong,
Area () method does not return any data, you write directly x.A rea ()

CodePudding user response:

Redesign the best IShape interface, area and perimeter should be the inherent nature of a geometry, and is a read-only,
 using System; 
using System.Collections.Generic;
Using System. Linq;
Using System. The Text;
Using System. The Threading. The Tasks;

The namespace ConsoleApplication1
{
Class Program
{
The static void Main (string [] args)
{
//get the length and width of the
Console. WriteLine (" please enter length: ");
Double length=double. Parse (Console. ReadLine ());
Console. WriteLine (" please enter the width: ");
Double width=double. Parse (Console. ReadLine ());

//calculate area and perimeter
IShape rectangle=new rectangle (length, width);
Console. WriteLine (" rectangular Area: {0} ", a rectangle, Area);
Console. WriteLine (" rectangular circumference: {0} ", a rectangle, generating);

//get the radius
Console. WriteLine (" please enter the radius: ");
Double radius=double. Parse (Console. ReadLine ());

//calculate area and perimeter
IShape circle=new circle (radius);
Console. WriteLine (" circle Area: {0} ", circle, Area);
Console. WriteLine (" circumference: {0} ", circle, generating);
The Console. ReadKey ();
}
}

Public interface IShape
{
///& lt; Summary>
///area
///& lt;/summary>
Double Area {get; }

///& lt; Summary>

///circumference///& lt;/summary>
Double generating {get; }
}

Public class Rectangle: IShape
{
///& lt; Summary>
///length
///& lt;/summary>
Private double length;
Public double Length
{
The get {return length; }
The set {length=value; }
}

///& lt; Summary>
///width
///& lt;/summary>
Private double width;
Public double Width
{
The get {return width; }
The set {width=value; }
}

///& lt; Summary>
///area
///& lt;/summary>
Public double Area
{
The get {return length * width; }
}

///& lt; Summary>

///circumference///& lt;/summary>
Public double generating
{
The get {return 2 * (length + width); }
}

///& lt; Summary>
///constructor
///& lt;/summary>
///& lt; Param name="length" & gt;
///& lt; Param name="width" & gt;
Public Rectangle (double length, double width)
{
This. Length=length;
this.width=width;
}
}

Public class Circle: IShape
{
///& lt; Summary>
///radius
///& lt;/summary>
Private double radius;
Public double Radius
{
The get {return radius; }
The set {radius=value; }
}

///& lt; Summary>
///area
///& lt;/summary>
Public double Area
{
The get {return math.h radius, PI * * radius; }
}

///& lt; Summary>

///circumference///& lt;/summary>
Public double generating
{
The get {math.h return 2 * PI * radius; }
}

///& lt; Summary>
///constructor
///& lt;/summary>
///& lt; Param name="radius" & gt;
Public Circle radius, (double)
{
Enclosing the radius=radius;
}
}
}

CodePudding user response:

Console. WriteLine (x.G etArea ()); Here to the Console. WriteLine (x.A rea);

CodePudding user response:

Can we change the place a lot of
 
Using System;
using System.Collections.Generic;
Using System. Linq;
Using System. The Text;
Using System. The Threading. The Tasks;
The implementation of the namespace interface
{
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  •  Tags:  
  • C#
  • Related