Package Woxihuan; Public classCar {//oil Monitoring system for automobiles//define a class of car//Car: Brand, average fuel consumption, mailbox capacity//What brand of car drove how many kilometers, consumption of gasoline how much L, Mailbox left how much l//Get         PublicCar (String _name, Double _sal,int_volume, Double _distance) {Name=_name; Sal=_sal; Volume=_volume; Distance=_distance; Operation= Sal *distance; Operation1= Volume-operation; }        //Set         PublicCar () {name="Audi"; Sal=13.5; Volume= -; Distance=1.5; Operation= Sal *distance; Operation1= Volume-operation; }                PrivateString name;//Brand        Private DoubleSal//Fuel Consumption        Private intVolume//capacity        Private DoubleDistance//How many kilometres did you drive?        Private DoubleOperation;//operation consumption of gasoline        Private DoubleOperation1;//How much is left in the arithmetic tank?                 Public voidresult () {System. out. println (name +"it's moving."+ Distance +"km, petrol consumption:"+ Operation +"L, the tank is still left:"+ Operation1 +"L. " ); }                 PublicString GetName () {returnname; }         Public voidsetName (String name) { This. Name =name; }}
Package Woxihuan; Public classChe { Public Static voidMain (string[] args) {//GetCar e =NewCar ("Audi A3",8.2, -,2.6);                E.result (); //SetCar e2 =NewCar (); E2.setname ("Audi R8");                            E2.result (); }}
5.02 Java Example Gasoline detection