Write a Java application that has 2 classes Mianji, the main class a. The specific requirements are as follows: The Mianji class has a type of double for the bottom, bottom , high, area properties, with the ability to return an area, including a construction method to initialize the bottom, bottom, and high. The main class A is used to test the functionality of class Mianji .
Double shangdi;double xiadi;double gao;double Mianji; Mianji (double shangdi,double xiadi,double Gao) {//Use parameters to initialize the property//this represents the current class this. Shangdi=shangdi;this. Xiadi=xiadi;this. Gao=gao;} The named verb of the method + the first letter of the noun verb lowercase//void indicates no return value if a return value is required, precede the method name with the type of the return value double Getmianji () { // Calculates the area mianji= ((this. Shangdi+this. Xiadi) *this. Gao)/2; SYSTEM.OUT.PRINTLN ("The output area of the method is" +mianji);//Returns the statement return method to the end of return, the following statement does not execute return this. Mianji;} Test public static void main (string[] args) {Mianji tixing=new Mianji (2,8,5);d ouble Mj=tixing.getmianji (); System.out.println ("The area received is" +MJ);}
Run results
The ladder area of Java object-oriented exercises