The ladder area of Java object-oriented exercises

Source: Internet
Author: User

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

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.