Write a program to input the cost of fuel put in the car each day of the (working)
week, then compute the total cost and the average cost, and display the results of
the two computations
You should write two classes to model the system. An application class Driver
containing the main method, and a class StatisticsCalculator storing five attributes, one
for each day of the (working) week, storing the cost of fuel for that day. Such class will
have the responsibility to compute the two required numerical outputs: the total cost of
fuel and the average daily expenditure (as results of methods with the same name). The
class will also have its own constructor to set up the values of the class attributes.
各位爹妈,我求解Java
答案:2 悬赏:60 手机版
解决时间 2021-05-06 17:25
- 提问者网友:寂寞梧桐
- 2021-05-05 17:04
最佳答案
- 五星知识达人网友:洒脱疯子
- 2021-05-05 17:56
那到底是每个工作日??还是每周呢??而且描述的我不知道从何下手
全部回答
- 1楼网友:纵马山川剑自提
- 2021-05-05 19:10
class StatisticsCalculator {
double d1,d2,d3,d4,d5;
StatisticsCalculator( double d1, double d2, double d3, double d4, double d5 ) {
this.d1 = d1;
this.d2 = d2;
this.d3 = d3;
this.d4 = d4;
this.d5 = d5;
}
double totalCost()
{
return d1+d2+d3+d4+d5;
}
double averageCost()
{
return totalCost() / 5;
}
}
public class Driver {
public static void main(String[] args) {
StatisticsCalculator sc = new StatisticsCalculator( 1, 2, 3, 4, 5 );
System.out.println( "Total cost is: " + sc.totalCost() );
System.out.println( "Average cost is: " + sc.averageCost() );
}
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯