前提・実現したいこと
それぞれのgetFuelConsumptionOldRegulations()とgetFuelConsumptionNewRegulations()を出力したい
発生している問題・エラーメッセージ
OldRegulations:0.0 NewRegulations:0.0 OldRegulations:0.0 NewRegulations:0.0 OldRegulations:0.0 NewRegulations:0.0 OldRegulations:0.0 NewRegulations:0.0
該当のソースコード
java
1class FuelConsumptionCalculation { 2 private float fuelConsumptionOldRegulation = 0; 3 private float fuelConsumptionNewRegulation = 0; 4 private SimpleCar[] cars; 5 6 FuelConsumptionCalculation() { 7 8 } 9 FuelConsumptionCalculation(SimpleCar[] cars) { 10 this.cars =cars; 11 } 12private void calculateFuelConsumption() { 13 for(int i=0;i<cars.length;i++) { 14 this.fuelConsumptionOldRegulation += cars[i].calculateFuelConsumptionOldRegulations(); 15 this.fuelConsumptionNewRegulation += cars[i].calculateFuelConsumptionNewRegulations(); 16 } 17 } 18 19 float getFuelConsumptionOldRegulations() { 20 return this.fuelConsumptionOldRegulation; 21 } 22 float getFuelConsumptionNewRegulations() { 23 return this.fuelConsumptionNewRegulation; 24 } 25 public static void main(String[] args) { 26 SimpleCar[] cars = { 27 new DeluxeCar("Honda",14f,10.5f), 28 new SimpleCar("Nissan",13.0f), 29 new AdvancedCar("Toyota",15.5f,9.5f), 30 new DeluxeCar("Van",10.5f,6f) 31 }; 32 33 for(int i=0;i<cars.length;i++){ 34 System.out.println( "OldRegulations:" + cars[i].calculateFuelConsumptionOldRegulations() + " NewRegulations:" + cars[i].calculateFuelConsumptionNewRegulations() + "\n"); 35 } 36 } 37 } 38class SimpleCar { 39private String carname; 40private int distance; 41private float Fueleco; 42public SimpleCar(){ 43this.distance =0; 44this.Fueleco = 0; 45} 46 public SimpleCar(String name,float fc) { 47 this.carname= name; 48 this.Fueleco = fc; 49 } 50 public void setReport(int kilo){ 51 this.distance = kilo; 52 } 53 public float calculateFuelConsumptionOldRegulations(){ 54 return this.distance/this.Fueleco; 55 } 56 public float calculateFuelConsumptionNewRegulations() { 57 return this.distance/this.Fueleco; 58 } 59 60} 61class AdvancedCar extends SimpleCar{ 62private int begintime,finshtime; 63private float FuelecoAir; 64public AdvancedCar(){ 65super(); 66this.begintime = 0; 67this.finshtime = 0; 68this.FuelecoAir = 0; 69 70} 71 public AdvancedCar(String name1,float fc1,float fca1){ 72 super(name1,fc1); 73 this.FuelecoAir = fca1; 74 } 75 public void setReport(int btime1,int ftime1,int kilo1){ 76 super.setReport(kilo1); 77 this.begintime = btime1; 78 this.finshtime = ftime1; 79 } 80 public float calculateFuelConsumptionOldRegulations() { 81 return super.calculateFuelConsumptionOldRegulations() + (this.finshtime-this.begintime)/this.FuelecoAir; 82 } 83 84 public float calculateFuelConsumptionNewRegulations() { 85 return super.calculateFuelConsumptionNewRegulations()+ (this.finshtime-this.begintime)/this.FuelecoAir; 86 } 87 public float calculateAirFuelConsumption(){ 88 return (this.finshtime-this.begintime)/this.FuelecoAir; 89 } 90 91 } 92 93class DeluxeCar extends AdvancedCar{ 94private int passengers,begintime1,finshtime1; 95private float FuelecoAir1; 96public DeluxeCar(){ 97super(); 98this.passengers=0; 99this.begintime1=0; 100this.finshtime1=0; 101} 102 public DeluxeCar(String name2,float fc2,float fca2){ 103 super(name2,fc2,fca2); 104 this.FuelecoAir1 = fca2; 105 } 106 public void setReport(int btime2,int ftime2,int kilo2,int ptime){ 107 super.setReport(btime2,ftime2,kilo2); 108 this.passengers= ptime; 109 this.begintime1 = btime2; 110 this.finshtime1 = finshtime1; 111 } 112 public float calculateFuelConsumptionOldRegulations() { 113 return super.calculateFuelConsumptionOldRegulations(); 114 } 115 116 public float calculateFuelConsumptionNewRegulations() { 117 return super.calculateFuelConsumptionNewRegulations()+(this.passengers/this.FuelecoAir1)- super.calculateAirFuelConsumption(); 118 } 119} 120 121
わからないこと
setReport()をどのように扱うか
補足情報(FW/ツールのバージョンなど)
jdk-14.0.1
> それぞれのgetFuelConsumptionOldRegulations()とgetFuelConsumptionNewRegulations()を出力したい
まずは試してみましょう。
> setReport()をどのように扱うか
wa3 さんの目的次第です。
アカウント作り直しかと思いましたが、何かの課題なんじゃない?
https://gist.github.com/yamika/84475cbe867e088347545d0f474f6813
ここ最近、連続して同じようなテーマの質問が連発してるし。
https://teratail.com/questions/266465