package woxihuan; public class Car { // Car fuel monitoring system // Define a class Car // Car: brand, average fuel consumption, mailbox capacity // What brand of car traveled how many kilometers, how many L of gasoline consumed, how many L left in the mailbox // get public Car(String _name, Double _sal, int _volume, Double _distance) { name = _name; salt = _salt; volume = _volume; distance = _distance; operation = sal * distance; operation1 = volume - operation; } //set public Car() { name = " Audi " ; sal = 13.5 ; volume = 90; distance = 1.5; operation = sal * distance; operation1 = volume - operation; } private String name; // Brand private double sal; // Fuel consumption private int volume; // Capacity private double distance; // How many kilometers traveled private double operation; // Calculation consumption of gasoline private double operation1; // Calculation fuel tank remaining How many public void result() {System.out .println (name + " Driving " + distance + " km, gas consumption: " + operation + " L, fuel tank remaining: " + operation1 + " L. " ); } public String getName() { return name; } public void setName(String name) { this.name = name; } }
package woxihuan; public class What { public static void main(String[] args) { //get Car e = new Car("奥迪a3" ,8.2 , 55 ,2.6); e.result(); //set Car e2 = new Car(); e2.setName( " Audi r8 " ); e2.result(); } }