5.02 java例题 汽油检测
Posted f9801
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了5.02 java例题 汽油检测相关的知识,希望对你有一定的参考价值。
package woxihuan; public class Car { // 汽车的油量监控系统 // 定义一个类Car // Car: 品牌, 平均油耗, 邮箱容量 // 什么牌子的车行驶了多少公里, 消耗汽油多少L, 邮箱还剩多少L //get public Car(String _name, Double _sal, int _volume, Double _distance) { name = _name; sal = _sal; volume = _volume; distance = _distance; operation = sal * distance; operation1 = volume - operation; } //set public Car() { name = "奥迪"; sal = 13.5; volume = 90; distance = 1.5; operation = sal * distance; operation1 = volume - operation; } private String name; //品牌 private double sal;//油耗 private int volume;//容量 private double distance;//行驶了多少公里 private double operation;//运算消耗汽油 private double operation1;//运算油箱还剩多少 public void result() { System.out.println(name + "行驶了" + distance + "km,消耗汽油:" + operation + "L,油箱还剩:" + operation1 + "L。" ); } public String getName() { return name; } public void setName(String name) { this.name = name; } }
package woxihuan; public class Che { 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("奥迪r8"); e2.result(); } }
以上是关于5.02 java例题 汽油检测的主要内容,如果未能解决你的问题,请参考以下文章