我怎样才能获得数组对象的平均值并将它们显示在android文本视图上?

发布于 2025-01-09 12:12:08 字数 1606 浏览 1 评论 0原文

House[] Houses= 新房子[3];

    int houseNum=0;
    while(fsc.hasNext()){
        Houses[houseNum] = new House(); // creates hous einto array
        Houses[houseNum].setAddress(fsc.nextLine());
        Houses[houseNum].setCity(fsc.nextLine());
        Houses[houseNum].setValue(fsc.nextDouble());
        fsc.nextLine();
        Houses[houseNum].setYearBuilt(fsc.nextInt());
        fsc.nextLine();
        Houses[houseNum].setPropertyTaxes(fsc.nextDouble());
        fsc.nextLine();
        Houses[houseNum].setSquareFootage(fsc.nextInt());
        fsc.nextLine();
        tv.append(Houses[houseNum].getAddress() + "\n" );
        tv.append(Houses[houseNum].getCity() + "\n" );
        tv.append(Houses[houseNum].getValue() + "\n" );
        tv.append(Houses[houseNum].getYearBuilt() + "\n" );
        tv.append(Houses[houseNum].getPropertyTaxes() + "\n" );
        tv.append(Houses[houseNum].getSquareFootage() + "\n" );


        houseNum++;

我正在使用adroid

     double sumFootage = 0;                               
    for(int i=0; i < houseNum ; i++){                     
        sumFootage += Houses[houseNum].getSquareFootage();
    }                                                     
    double averageFootage= sumFootage/houseNum;           
    tv.append("Average Footage:" + averageFootage);       

studio 以文本形式显示它。我对如何执行以下操作感到困惑: 在 TextView 中显示三栋房屋的平均平方英尺(作为实数)。将该值显示为小数点后三位(例如,1000.321)。 显示相对于这三个建筑面积的财产税的加权平均值 房屋数据下方的 TextView 中的房屋(作为实数)。 我收到的错误消息

House[] Houses= new House[3];

    int houseNum=0;
    while(fsc.hasNext()){
        Houses[houseNum] = new House(); // creates hous einto array
        Houses[houseNum].setAddress(fsc.nextLine());
        Houses[houseNum].setCity(fsc.nextLine());
        Houses[houseNum].setValue(fsc.nextDouble());
        fsc.nextLine();
        Houses[houseNum].setYearBuilt(fsc.nextInt());
        fsc.nextLine();
        Houses[houseNum].setPropertyTaxes(fsc.nextDouble());
        fsc.nextLine();
        Houses[houseNum].setSquareFootage(fsc.nextInt());
        fsc.nextLine();
        tv.append(Houses[houseNum].getAddress() + "\n" );
        tv.append(Houses[houseNum].getCity() + "\n" );
        tv.append(Houses[houseNum].getValue() + "\n" );
        tv.append(Houses[houseNum].getYearBuilt() + "\n" );
        tv.append(Houses[houseNum].getPropertyTaxes() + "\n" );
        tv.append(Houses[houseNum].getSquareFootage() + "\n" );


        houseNum++;

}

     double sumFootage = 0;                               
    for(int i=0; i < houseNum ; i++){                     
        sumFootage += Houses[houseNum].getSquareFootage();
    }                                                     
    double averageFootage= sumFootage/houseNum;           
    tv.append("Average Footage:" + averageFootage);       

i am using adroid studio to display this in text. i am confused on how to do the follwoing:
Display the average square footage of the three houses (as a real number) in the TextView . Display this value to three decimal places (e.g., 1000.321).
Display the weighted average of the property taxes with respect to the square footage for the three
houses (as a real number) in the TextView below the house data.
error message i get

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文