Java 使用ArrayList上方法的返回值

Java 使用ArrayList上方法的返回值,java,arraylist,methods,Java,Arraylist,Methods,昨天我发布了一个关于ArrayList没有打印方法输出的问题,这只是一个语法错误。然而,今天,我遇到了一个类似的问题,并修复了这个错误。如果有人能告诉我这个代码有什么问题,我将不胜感激 我的问题是ArrayList打印的是[0.0,0.0,2.75],而不是我预期的价格列表 import java.util.ArrayList; public class TransitCalculatorTwo { int numberDays; int numberRides

昨天我发布了一个关于ArrayList没有打印方法输出的问题,这只是一个语法错误。然而,今天,我遇到了一个类似的问题,并修复了这个错误。如果有人能告诉我这个代码有什么问题,我将不胜感激

我的问题是ArrayList打印的是[0.0,0.0,2.75],而不是我预期的价格列表

    import java.util.ArrayList;

    public class TransitCalculatorTwo {
    int numberDays;
    int numberRides;
    int numberPlanSeven;
    int numberPlanThirty;
    double totalPriceSeven;
    double totalPriceThirty;
    double pricePerRideSeven;
    double pricePerRideThirty;
    double SinglePrice = 2.75;
    double sevenDayPrice = 33.0;
    double thirtyDayPrice = 127.00;


    public int numberPlanSeven(int numberDays) {
        int planSeven = (int) Math.ceil (numberDays / 7.0);
        return planSeven;
    }
    public int numberPlanThirty(int numberDays) {
        int planThirty = (int) Math.ceil (numberDays / 30.0);
        return planThirty;
    }

    public double totalPriceSeven (int numberPlanSeven, double sevenDayPrice) {
        double totalSeven = numberPlanSeven * sevenDayPrice;
        return totalSeven;
    }

    public double totalPriceThirty (int numberPlanThirty, double thirtyDayPrice) {
        double totalThirty = numberPlanThirty * thirtyDayPrice;
        return totalThirty;
    }

    public double pricePerRideSeven (double totalPriceSeven, int numberRides) {
        double ppRideSeven = totalPriceSeven / numberRides;
        return ppRideSeven;
    }
    public double pricePerRideThirty (double totalPriceThirty, int numberRides) {
        double ppRideThirty = totalPriceThirty / numberRides;
        return ppRideThirty;
    }

    public ArrayList<Double> comparePrice() {
        ArrayList<Double> prices = new ArrayList<Double>(); for (int i=0; i<1; i++) {
            prices.add(pricePerRideSeven);
            prices.add(pricePerRideThirty);
            prices.add(SinglePrice);
        }
        return prices;

    }

    public static void main (String[]args) {
        TransitCalculatorTwo customer = new TransitCalculatorTwo();

        customer.pricePerRideSeven(66.0, 50);
        customer.pricePerRideThirty(127.00, 50);

        System.out.println(customer.comparePrice());

    }
}
import java.util.ArrayList;
公共类TransitCalculator 2{
整数天;
整数;
整数规划偶数;
整数植物密度;
双倍总价七元;
双倍总价30元;
双倍价格;七倍价格;
双倍价格30美元;
双单件价格=2.75;
双倍七日价格=33.0;
双倍30天价格=127.00;
公共整数计划偶数(整数天){
int planSeven=(int)Math.ceil(numberDays/7.0);
返回计划7;
}
公共整数planthirty(整数天){
int planThirty=(int)Math.ceil(numberDays/30.0);
回植率;
}
公共双倍总价七(整数计划偶数,双倍七日价格){
double Total Seven=NumberPlan偶数*sevenDayPrice;
返回总数7;
}
公共双倍总价三十(整数第三,双倍三十天价格){
double Total Three=第三个数量*第三十天价格;
返回总数为30;
}
公共双倍价格PerrideSeven(双倍总价Seven,整数){
double ppRideSeven=总价格七/数字三;
第七次返回;
}
公共双价PerrideThree(双价TotalPriceThree,整数){
double PPrideThree=总价格30/个位数;
三十分钟后返回;
}
公共ArrayList comparePrice(){

ArrayList prices=new ArrayList();for(int i=0;i您没有在main中构建的对象中设置变量值。您正在为局部变量而不是对象参数设置值。您的代码必须如下所示:

public double pricePerRideSeven (double totalPriceSeven, int numberRides) {
    this.pricePerRideSeven = totalPriceSeven / numberRides;
    return this.pricePerRideSeven;
}

public double pricePerRideThirty (double totalPriceThirty, int numberRides) {
    this.pricePerRideThirty = totalPriceThirty / numberRides;
    return pricePerRideThirty;
}