forked from kiba518/CSharpClassicProgram
-
Notifications
You must be signed in to change notification settings - Fork 0
/
矩形.txt
57 lines (53 loc) · 958 Bytes
/
矩形.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System;
class Rectangle
{
private float length=1.0f;
private float width=1.0f;
public float SetLength(float length)
{
this.length=length;
if((length<0.0f)||(length>2.0f))
{
Console.WriteLine ("长的取值范围应在1.0-2.0之内,请重新设值。");
return 0.0f;
}
return width;
}
public float SetWidth(float width)
{
this.width=width;
if((width<0.0f)||(width>2.0f))
{
Console.WriteLine ("宽的取值范围应在1.0-2.0之内,请重新设值。");
return 0.0f;
}
return width;
}
public float GetLength(float length)
{
return length;
}
public float GetWidth(float width)
{
return width;
}
public float perimeter()
{
return length*2+width*2;
}
public float area()
{
return length*width;
}
}
class Rectangle_Test
{
public static void Main()
{
Rectangle r1=new Rectangle ();
r1.SetLength (1.8f);
r1.SetWidth (1.2f);
Console.WriteLine (r1.perimeter ());
Console.WriteLine (r1.area ());
}
}���