Design a program, the program has three classes, triangle,lader,circle,

Source: Internet
Author: User

//This program writes out three classes, triangle,lader,circle, where the triangle class has a,b,c edges with type double and perimeter, area properties,
With perimeter, area, and modification of the three-side function, there is a Boolean class that determines whether a triangle can be formed.
The Lader class has the upper bottom and high, area properties of type Double, with the ability to return an area
The Circlle class has a radius, perimeter, and area of type Double. Has the ability to return the perimeter area.
//Triangle Classclasstriangle{ Public DoubleA; Public Doubleb; Public DoubleC; Publictriangle () {a=0.0; b=0.0; C=0.0; }//The following is the value of the Reference object PublicTriangleDoubleADoubleBDoublec) { This. a=A; This. b=b; This. c=C;} Private BooleanisTrue () {if(A+b>c&&a+c>b&&b+c>a)return true; Else return false; } Public DoubleGetperimeter () {if( This. IsTrue ())returna+b+C; Else return-1; } Public DoubleGetarea () {Doubles= (A+B+C)/2; if( This. IsTrue ())returnMath.sqrt (s* (s-a) * (s-b) * (S-c)); Else return-1; } Public Static voidMain (string[] args) {triangle T=Newtriangle (); System.out.println (T.getperimeter ()); System.out.println (T.getarea ()); Triangle Q=NewTriangle (1.2,1.2,1.2); System.out.println (Q.getperimeter ()); System.out.println (Q.getarea ()); }}//Lader class classLader {DoubleSD;Doublexd;Doubleheight;Doublearea;//The following is a reference object Lader (DoubleSdDoubleXdDoubleheight) { This. sd=SD; This. xd=xd; This. height=height;} Public voidArea () { area=1.0/2* (SD+XD) *height; System.out.println ("Trapezoid area is:" +Area );}}//Circle Class classCircle {DoubleR;DoubleCircle;Doubles; Circle (DoubleR) { This. r=R;} voidArea () {Circle=2*math.pi*R;s=math.pi*math.pow (R, 2); System.out.println ("The circumference of the circle is:" +circle); System.out.println ("The area of the circle is:" +s);}}

Design a program, the program has three classes, triangle,lader,circle,

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.