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