我怎样才能获得数组对象的平均值并将它们显示在android文本视图上?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论