Write Java applications as required.
(1) Create a class called a motor vehicle:
Property: Car Grade (String), speed (int), load capacity (double)
Function: Speed up (auto increase), deceleration (speed reduction), modify the license plate number, check the load capacity of the vehicle.
Write two construction methods: a non-formal parameter, in the method of the license plate number Set "XX1234", speed
is set to 100, the load weight is set to 100, and the other can assign values to all properties of the object;
(2) Create the main class:
Create two motor vehicle objects in the main class.
When you create the first one, call the parameterless constructor, calling the Member method to make its license plate "Liao
A9752 "and let it accelerate.
Create the second time call the constructor method of the parameter, so that its license plate is "Liao B5086", the speed of 150,
Load is 200 and let it slow down.
Output of two vehicles all information
Public classJidongche {String Chepai; PublicString Getchepai () {returnChepai; } Public voidSetchepai (String chepai) { This. Chepai =Chepai; } intChesu; DoubleZaizhong; Public voidJiasu (inta) {Chesu+=A; System.out.println ("Accelerate" +a+ "after speed changes" +Chesu); } Public voidJiansu (intb) {Chesu-=b; if(chesu>=0) {System.out.println ("Deceleration" +b+ "after speed changed to" +Chesu); } Else{System.out.println ("Deceleration" +b+ "speed changed to 0"); }} jidongche () {Chepai= "XX1234"; Chesu=100; Zaizhong=100; } jidongche (String A,intBDoublec) {Chepai=A; Chesu=b; Zaizhong=C; } Public Static voidMain (string[] args) {Jidongche J1=NewJidongche (); J1.setchepai ("Liao A9752"); System.out.println (J1.chepai); System.out.println ("The second car's license plate is" +j1.chepai+ "Speed is" +j1.chesu+ "load capacity is" +J1.zaizhong); J1.jiasu (30); Jidongche J2=NewJidongche ("Liao B5086", 150,200); System.out.println ("The second car's license plate is" +j2.chepai+ "Speed is" +j2.chesu+ "load capacity is" +J2.zaizhong); J2.jiansu (30); }}
Java Object-oriented exercises 9