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