2016/1/18 correction Supplement 2016/1/17 rectangle area 1, construction method initialize length and width, 2, define member method to find rectangular area

Source: Internet
Author: User

1  PackageCaipiao;2 3 Importjava.util.*;//introduce Java tools. Util is the abbreviation of utiliy, meaning for multipurpose,4                         //tool nature of the package this package is mainly stored in: collection classes (such as ARRAYLIST,HASHMAP, etc.),5                         //the random number generation class, the property file reads the class, the timer class and so on class. 6  Public classJuXing1 {//These classes are extremely handy for Java programming, and these classes are often used in everyday Java programming. 7     //Properties8     Private DoubleChang; //Privatization 9     Private DoubleKuan; //Privatization Ten      One      Public DoubleGetchang () {//used to read into can be adjusted Getchang is the method name verb plus noun Note writing standard case A         returnChang; -     } -     //Write Changes the     voidSetchang (DoubleChang) { //validation method takes into account whether the long data is valid for negative data  -         if(chang>0) {//Add Validation -              This. chang=Chang; -         } +         Else{ -SYSTEM.OUT.PRINTLN ("Invalid length entered"); +         } A     } at      Public DoubleGetkuan () { //and the same as on the Kuan Privatization transfer read  -         returnKuan; -     } -     voidSetkuan (DoubleKuan) { //Verify the validity of wide data  -         if(kuan>0){ -              This. kuan=Kuan; This is a pointer to a property name defined in this class, especially if the parameter name and the defined property name  are the same in         } -         Else{ toSYSTEM.OUT.PRINTLN ("Input width is invalid"); +         } -     } the      *      Public DoubleMianji () { $         returnchang*Kuan;Panax Notoginseng     } -      the     //constructor method without parameter default construction method + JuXing1 () { A          the     } +     //Assigning a value to a property -      PublicJuXing1 (DoubleChangDoubleKuan) { $ Setchang (Chang); $ Setkuan (Kuan); -     } -     //method for process-oriented writing the      Public DoubleGetmianji (DoubleChangDoubleKuan) { -         returnchang*Kuan;Wuyi     } the     //Object-oriented approach -      Public DoubleGetmianji () { Wu         return  This. chang*Kuan; - } About  $  -}

You need to validate the output by referencing properties and methods under the Main method

1  Public Static void Main (string[] args) {2 JuXing1 jj=new  JuXing1 (); 3        Jj.setchang (+); 4        Jj.setkuan (+); 5 System.out.println (Jj.getmianji ()); 6 }

2016/1/18 correction Supplement 2016/1/17 rectangle area 1, construction method initialize length and width, 2, define member method to find rectangular area

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.