これは私の最初の投稿なので、正しく行われなかった場合は申し訳ありません。このプログラムは私のAPコンピュータサイエンスコース用です(コードのサンプルは必要ありません。これが発生する理由の説明だけです)。オブジェクトから変数を取得しようとすると、変数が存在しないというエラーが表示されます(NetBeansIDE)。前もって感謝します!
これはコードです:
public class AnnualFuelTester
{
public static void main(String [] args)
{
AnnualFuelUse Fill1 = new AnnualFuelUse(1, 1, 45023, 45231, 10.00, 2.95);
AnnualFuelUse Fill2 = new AnnualFuelUse(2, 4, 45231, 45480, 11.70, 2.99);
AnnualFuelUse Fill3 = new AnnualFuelUse(3, 8, 45480, 45659, 9.30, 3.03);
AnnualFuelUse [] FillArray = {Fill1, Fill2, Fill3};
System.out.println("Fillup Days Start Miles Distance Gallons Consumed MpG Fuel Price Cost");
**int temp = Fill1.distance;**
System.out.printf ("%4.1f %4.1f %4.1f %4.1f %4.1f %4.1f %4.1f %4.1f", );
}
}
(編集:) AnnualFuelUse:
public class AnnualFuelUse
{
private int dist = 0;
private double MpG = 0;
private double CoT = 0;
private double totals = 0;
private double projection = 0;
private double min = 0;
private double max = 0;
Annual_Fuel_Use(int fillTemp, int daysTemp, int startTemp, int stopTemp, double gallTemp, double priceTemp){
int fillNumber = fillTemp;
int daysSinceLastFill = daysTemp;
int startMiles = starttemp;
int stopMiles = stoptemp;
int distance = Annual_FuelUse.travelDistance(startMiles, stopMiles);
double fuelConsumed = galltemp;
double mPG = AnnualFuelUse.milesPerGal(dist, fuelConsumed);
double pricePerGallon = pricetemp;
double tripCost = AnnualFuelUse.costOfTrip(pricePerGallon, fuelConsumed);
}
public double getMilesPerGal(){
return MpG;
}
public int getTravelDistance(){
return dist;
}
public double getCostOfTrip(){
return CoT;
}
public double getTotals(){
return totals;
}
public double getProjection(){
return projection;
}
public int travelDistance(int distance1, int distance2){
dist = distance2 - distance1;
return dist;
}
public double milesPerGal(int travelDistance, double fuelConsumed){
MpG = travelDistance / fuelConsumed;
return MpG;
}
public double costOfTrip(double pricePerGal, double fuelConsumed){
CoT = pricePerGal * fuelConsumed;
return CoT;
}
public double totals(double dat1, double dat2, double dat3){
totals = dat1 + dat2 + dat3;
return totals;
}
public double projection(int days,double projected){
projection = (projected / days) * 365;
return projection;
}
public double dataMin(int dat1, int dat2, int dat3){
if (dat1 <= dat2){
min = dat1;
}
if (min <= dat3){
return min;
} else {
return dat3;
}
}
public double dataMax(int dat1, int dat2, int dat3){
if (dat1 >= dat2){
max = dat1;
}
if (max >= dat3){
return max;
} else {
return dat3;
}
}
}