前提・実現したいこと
Honda OldRegulations:136.92857 NewRegulations:126.42857
Nissan OldRegulations:26.923077 NewRegulations:26.923077
Toyota OldRegulations:117.40323 NewRegulations:12.903226
Van OldRegulations:104.09524 NewRegulations:80.09524
と出力させたい。
発生している問題・エラーメッセージ
FuelConsumptionCalculation.java:16: エラー: クラス SimpleCarのメソッド setReportは 指定された型に適用できません。 cars[i].setReport(); ^ 期待値: int 検出値: 引数がありません 理由: 実引数リストと仮引数リストの長さが異なります FuelConsumptionCalculation.java:41: エラー: クラス FuelConsumptionCalculationのコンストラクタ FuelConsumptionCalculationは指定された型に適用できません。 FuelConsumptionCalculation f = new FuelConsumptionCalculation(cars); ^ 期待値: 引数がありません 検出値: SimpleCar[] 理由: 実引数リストと仮引数リストの長さが異なります FuelConsumptionCalculation.java:82: エラー: superの呼出しはコンストラクタの先頭文である必要があります super(kilo1); ^ FuelConsumptionCalculation.java:103: エラー: superの呼出しはコンストラクタの先頭文 である必要があります super(kilo2,btime2,ftime2);
該当のソースコード
java
1 2 3class FuelConsumptionCalculation { 4 private float fuelConsumptionOldRegulation = 0; 5 private float fuelConsumptionNewRegulation = 0; 6 private SimpleCar[] cars; 7 8 void FuelConsumptionCalculation() { 9 SimpleCar[] cars ={ 10 new DeluxeCar("Honda",14f,10.5f), 11 new SimpleCar("Nissan",13.0f), 12 new AdvancedCar("Toyota",15.5f,9.5f), 13 new DeluxeCar("Van",10.5f,6f) 14 }; 15 for(int i=0;i<cars.length;i++){ 16 cars[i].setReport(); 17 } 18 } 19 void FuelConsumptionCalculation(SimpleCar[] cars) { 20 this.cars = cars; 21 } 22 private void calculateFuelConsumption() { 23 for(int i=0;i<cars.length;i++) { 24 this.fuelConsumptionOldRegulation += cars[i].calculateFuelConsumptionOldRegulations(); 25 this.fuelConsumptionNewRegulation += cars[i].calculateFuelConsumptionNewRegulations(); 26 } 27} 28 float getFuelConsumptionOldRegulations() { 29 return this.fuelConsumptionOldRegulation; 30 } 31 float getFuelConsumptionNewRegulations() { 32 return this.fuelConsumptionNewRegulation; 33 } 34 static void main(String[] args) { 35 SimpleCar[] cars = { 36 new DeluxeCar("Honda",14f,10.5f), 37 new SimpleCar("Nissan",13.0f), 38 new AdvancedCar("Toyota",15.5f,9.5f), 39 new DeluxeCar("Van",10.5f,6f) 40 }; 41 FuelConsumptionCalculation f = new FuelConsumptionCalculation(cars); 42 System.out.println(this.carname "OldRegulations:" + f.getFuelConsumptionOldRegulations() + " NewRegulations:" + f.getFuelConsumptionNewRegulations() + "\n"); 43 } 44} 45class SimpleCar { 46String carname; 47int distance; 48float Fueleco; 49public SimpleCar(){ 50this.distance =0; 51this.Fueleco = 0; 52} 53 public SimpleCar(String name,float fc) { 54 this.carname= name; 55 this.Fueleco = fc; 56 } 57 public void setReport(int kilo){ 58 this.distance = kilo; 59 } 60 public float calculateFuelConsumptionOldRegulations(){ 61 return this.distance/this.Fueleco; 62 } 63 public float calculateFuelConsumptionNewRegulations() { 64 return this.distance/this.Fueleco; 65 66 } 67} 68class AdvancedCar extends SimpleCar{ 69int begintime,finshtime; 70float FuelecoAir; 71public AdvancedCar(){ 72super(); 73this.begintime = 0; 74this.finshtime = 0; 75this.FuelecoAir = 0; 76} 77 public AdvancedCar(String name1,float fc1,float fca1){ 78 super(name1,fc1); 79 this.FuelecoAir = fca1; 80 } 81 public void setReport(int kilo1,int btime1,int ftime1){ 82 super(kilo1); 83 this.begintime = btime1; 84 this.finshtime = ftime1; 85 } 86 public float calculateFuelConsumptionOldRegulations() { 87 return super.calculateFuelConsumptionOldRegulations() + this.FuelecoAir*(this.finshtime-this.begintime); 88 } 89 90 public float calculateFuelConsumptionNewRegulations() { 91 return super.calculateFuelConsumptionNewRegulations() + this.FuelecoAir*(this.finshtime-this.begintime); 92 } 93} 94class DeluxeCar extends AdvancedCar{ 95int passengers; 96public DeluxeCar(){ 97super(); 98} 99 public DeluxeCar(String name2,float fc2,float fca2){ 100 super(name2,fc2,fca2); 101 } 102 public void setReport(int kilo2,int btime2,int ftime2,int ptime){ 103 super(kilo2,btime2,ftime2); 104 this.passengers= ptime; 105 } 106 107 108 public float calculateFuelConsumptionOldRegulations() { 109 return (super.calculateFuelConsumptionOldRegulations()); 110 } 111 112 public float calculateFuelConsumptionNewRegulations() { 113 return (super.calculateFuelConsumptionNewRegulations()+ this.FuelecoAir*this.passengers); 114 } 115} 116 117
わからないこと
setReport()をどうよびだして calculateFuelConsumption()反映させるか
補足情報(FW/ツールのバージョンなど)
jdk14.0.1