把注释和关键步骤作业写出来import java.util.Scanner;public class TestOdometer {\x09public static void main(String[] args){\x09\x09double journey;\x09\x09double efficiency;\x09\x09Odometer odometer = new Odometer();\x09\x09Scanner scan = n
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/19 16:37:53
把注释和关键步骤作业写出来import java.util.Scanner;public class TestOdometer {\x09public static void main(String[] args){\x09\x09double journey;\x09\x09double efficiency;\x09\x09Odometer odometer = new Odometer();\x09\x09Scanner scan = n
把注释和关键步骤作业写出来
import java.util.Scanner;
public class TestOdometer {
\x09public static void main(String[] args){
\x09\x09double journey;
\x09\x09double efficiency;
\x09\x09Odometer odometer = new Odometer();
\x09\x09Scanner scan = new Scanner(System.in);
\x09\x09System.out.println("请输入旅行距离:");
\x09\x09journey = scan.nextDouble();
\x09\x09odometer.getFuel(journey);
\x09\x09System.out.println(odometer);
\x09\x09System.out.println("请输入燃油效率:");
\x09\x09efficiency = scan.nextDouble();
\x09\x09odometer.setEfficiency(efficiency);
\x09\x09System.out.println(odometer);
\x09}
}
public class Odometer {
\x09private double journey,surplusJourney;
\x09private double fuel;
\x09private double efficiency;
\x09public Odometer(){
\x09\x09journey = 0;
\x09\x09fuel = 60;
\x09\x09efficiency = 50;
\x09}
\x09public void setdistance(){
\x09\x09journey = 0;
\x09}
\x09//设置燃油效率
\x09public void setEfficiency(double e){
\x09\x09efficiency = e;
\x09}
\x09//返回剩余燃油
\x09public double getFuel(double f){
\x09\x09journey += f;
\x09\x09fuel -= f / efficiency;
\x09\x09return fuel;
\x09}
\x09//返回剩余燃油可行驶里程
\x09public double getSurplusJourney(){
\x09\x09surplusJourney = fuel * efficiency;
\x09\x09return surplusJourney;
\x09}
\x09public String toString(){
\x09\x09return "剩余燃油可走的路程:" + getSurplusJourney();
\x09}
}
急,马上要用
把注释和关键步骤作业写出来import java.util.Scanner;public class TestOdometer {\x09public static void main(String[] args){\x09\x09double journey;\x09\x09double efficiency;\x09\x09Odometer odometer = new Odometer();\x09\x09Scanner scan = n
public class Odometer {
\x09\x09//journey初始位置,surplusJourney剩余燃油可行驶里程
\x09\x09private double journey,surplusJourney;
\x09\x09//剩余燃油
\x09\x09private double fuel;
\x09\x09//燃油效率
\x09\x09private double efficiency;
\x09\x09//构造方法,在创建Odometer对象时设置初值
\x09\x09public Odometer(){
\x09\x09\x09journey = 0;//初始位置为0
\x09\x09\x09fuel = 60;//初始燃料为60
\x09\x09\x09efficiency = 50;//初始效率为50%
\x09\x09}
\x09\x09
\x09\x09//设置初始位置
\x09\x09public void setdistance(){
\x09\x09\x09journey = 0;
\x09\x09}
\x09\x09//设置燃油效率
\x09\x09public void setEfficiency(double e){
\x09\x09\x09efficiency = e;
\x09\x09}
\x09\x09//返回剩余燃油
\x09\x09public double getFuel(double f){
\x09\x09\x09journey += f;
\x09\x09\x09fuel -= f / efficiency;
\x09\x09\x09System.out.println("剩余燃料:"+fuel);
\x09\x09\x09return fuel;
\x09\x09}
\x09\x09//返回剩余燃油可行驶里程
\x09\x09public double getSurplusJourney(){
\x09\x09\x09surplusJourney = fuel * efficiency;
\x09\x09\x09return surplusJourney;
\x09\x09}
\x09\x09//输出剩余燃油可走的路程
\x09\x09public String toString(){
\x09\x09\x09return "剩余燃油可走的路程:" + getSurplusJourney();
\x09\x09}
}
public class TestOdometer {
\x09public static void main(String[] args){
\x09\x09//输入的旅行距离
\x09\x09double journey;
\x09\x09//输入的燃油效率
\x09\x09double efficiency;
\x09\x09//创建Odometer对象,调用Odometer的构造方法设置初始值
\x09\x09Odometer odometer = new Odometer();
\x09\x09//从控制台输入旅行距离
\x09\x09Scanner scan = new Scanner(System.in);
\x09\x09System.out.println("请输入旅行距离:");
\x09\x09journey = scan.nextDouble();
\x09\x09//返回剩余燃料
\x09\x09odometer.getFuel(journey);
\x09\x09//输出剩余燃料按照50%的 效率可行驶的路程
\x09\x09System.out.println(odometer);
\x09\x09//输入新的燃油效率
\x09\x09System.out.println("请输入燃油效率:");
\x09\x09efficiency = scan.nextDouble();
\x09\x09odometer.setEfficiency(efficiency);
\x09\x09//输出剩余燃料按照新的效率可行驶的路程
\x09\x09System.out.println(odometer);
\x09}
}
这样看得懂不?