Public classjuxing {//Write a rectangle class that takes the length and width as the attribute of the rectangle class, initializes the length and width in the construction method, and defines a member method to find the rectangular area intChang; intKuan; intMianji; Doubles; DoubleC; intn = 4; String tuxing= "Rectangle"; voidXingzhuang () {//No return no parameterstuxing= "Rectangle"; } voidDjxDoublem) {//no return value, there are parameters???? m= C-2; System.out.println ("Diagonal =" +m); } DoubleMianji (intChangintKuan) {//There are return values, parameters returnMianji= chang*Kuan; } BooleanBianshu () {//There are return values, no parameters Booleanb =true; if(n = = 4) {System.out.println ("There are four sides" +b); }Else{System.out.println ("Not quadrilateral."); } returnb; } Public Static voidMain (string[] args) {juxing JX=Newjuxing (); Jx.chang= 10; Jx.kuan= 5; Jx.s= jx.chang*Jx.kuan; Jx.mianji= Jx.chang *Jx.kuan; JX.C= 2 * (Jx.chang +Jx.kuan); JX.DJX (JX.C); System.out.println ("Graphics:" +jx.tuxing); System.out.println ("area =" +jx.s); System.out.println ("Area of the rectangle =" +Jx.mianji); System.out.println ("Perimeter =" +jx.c); //System.out.println ("diagonal =" +jx.m); if(Jx.bianshu ()) {System.out.println ("This figure is quadrilateral."); }Else{System.out.println ("This figure is not quadrilateral."); } } }
0117 Object-oriented OOP exercises on methods, classes, construction methods, and permission modifiers