Object-oriented-encapsulation-Automotive

Source: Internet
Author: User

1 /*2 * Write Java applications as required. (1) Create a class called a motor vehicle:3 * Properties: Vehicle grade (String), speed (int), load capacity (double)4 * Function: Speed up (auto increase), deceleration (speed reduction), modify the license plate number, check the load capacity of the vehicle. 5 * Write two construction methods: a non-formal parameter, in the method of the license plate number Set "XX1234", Speed6 * The degree is set to 100, the load weight is set to 100, and the other can assign values to all properties of the object;7 * (2) Create a main class: Create two motor vehicle objects in the main class. 8 * When creating the first call to the parameterless constructor method, call the member method to make its license plate "Liao A9752" and let it accelerate. 9 * Create a second time call parameters of the construction method, so that its license plate is "Liao B5086", the speed of 150, the load is ten,Ten * And let it slow down. Output of two vehicles all information One      */ A     //License plate -     //Tank Capacity -     Private DoubleYouxrl=40; the     //total number of miles -     Private DoubleZonglc=0; -     //hundred kilometers fuel consumption -     Private Doubleyouh=10; +     //Current Oil content -     Private DoubleDangqyl=0; +      A      PublicString Getchep () { at         returnCheP; -     } -  -      Public voidSetchep (String cheP) { -CheP =CheP; -     } in  -      Public DoubleGetyouxrl () { to         returnYouxrl; +     } -  the      Public voidSETYOUXRL (DoubleYOUXRL) { *YOUXRL =Youxrl; $     }Panax Notoginseng  -      Public DoubleGETZONGLC () { the         returnZONGLC; +     } A  the      Public voidSETZONGLC (DoubleZONGLC) { +ZONGLC =ZONGLC; -     } $  $      Public DoubleGetyouh () { -         returnYouh; -     } the  -      Public voidSetyouh (DoubleYouh) {Wuyi         if(youh>0) the         { -Youh =Youh; Wu         } -         Else About         { $SYSTEM.OUT.PRINTLN ("Incorrect input"); -         } -     } -  A      Public DoubleGetdangqyl () { +         returnDangqyl; the     } -  $      Public voidSetdangqyl (Doubledangqyl) { theDangqyl =Dangqyl; the     } the     PrivateString CheP; the      PublicCar1 (String cheP) { -         Super(); inCheP =CheP; the     } the     //method: Refueling About      Public voidJiayou (DoubleYoul) the     { the         if(youl<0) the         { +System.out.println ("Don't Steal my Oil"); -         } the         Else if(Youl> (youxrl-dangqyl))Bayi         { theDangqyl=Youxrl; theSYSTEM.OUT.PRINTLN ("Tank is full"); -         } -         Else the         { thedangqyl+=Youl; theSYSTEM.OUT.PRINTLN ("Oil Volume:" +Youl); the         } -     } the          //current increase in oil content the         //refueling method of overloading, one full of D the          Public Doublejiayou ()94         { the             //return value () to calculate the             Doublertn=youxrl-Dangqyl; theJiayou (RTN);//98             returnRtn; About         } -         //Driving101          Public voidXingshi (DoubleLingcheng)102         {103             if(lingcheng>0)104             { the             //Current Oil content106dangqyl-=lingcheng*youh/100;107             //Total Mileage108zonglc+=Lingcheng;109             } the             Else111             { theSYSTEM.OUT.PRINTLN ("Car can't open like this");113             } the         } the      the          Public Static voidMain (string[] args) {117         //TODO Auto-generated method stubs118Car1 car=NewCar1 ("Lu C12345");119CAR.SETYOUXRL (50); -SYSTEM.OUT.PRINTLN ("Tank capacity =" +CAR.GETYOUXRL ());121Car. Jiayou (40);122System.out.println ("Current capacity" +car.getdangqyl ());123 car. Jiayou ();124System.out.println ("Current capacity" +car.getdangqyl ()); theCar.setyouh (7);126Car. Xingshi (-100);127SYSTEM.OUT.PRINTLN ("Current oil volume" +car.getdangqyl ()); -SYSTEM.OUT.PRINTLN ("Total mileage" +CAR.GETZONGLC ());129}

Object-oriented-encapsulation-Automotive

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.