gpt4 book ai didi

java - 电费/能源账单计算器 : Java

转载 作者:行者123 更新时间:2023-11-30 08:33:06 25 4
gpt4 key购买 nike

我无法弄清楚这个用于计算计算机能源成本的小型电力/能源计算器到底出了什么问题。

如果有任何帮助,我将不胜感激。

程序:

import java.util.Scanner;

public class ElectricityCalculations {
public static void main (String [] args) {
Scanner scnr = new Scanner(System.in);
double usageHoursPerDay = 0; // Hours computer is on per day
double usageDaysPerWeek = 0; // Days computer is used per week
double usageWeeksPerYear = 0; // Weeks computer is used per year
double wattsPerHour = 0; // Watts used by computer per hour
final double COST_PER_KWH = 0.145; // Prices of power per kilowatt hour
final double LBS_CO2_PER_KWH = 0.58815; // Pounds of CO2 generated per KWH
double usageHoursPerYear = 0; // Amount of hours on per year
double usageWattHoursPerYear = 0; // Amount of watt hours consumed per year
double usageKWHPerYear = 0; // Amount of KWH used in a year
double costPerYear = 0; // Total cost per year
double lbsCO2PerYear = 0; // Total amount of CO2 in pounds released per year

// Input Values
System.out.println("How many hours is your computer on per day?");
usageHoursPerDay = scnr.nextDouble();
System.out.println("How many days per week is your computer used?");
usageDaysPerWeek = scnr.nextDouble();
System.out.println("How many weeks per year is your computer used?");
usageWeeksPerYear = scnr.nextDouble();
System.out.println("How many watts per hour does your computer use? (Suggestive value for desktop: 100, laptop: 30).");
wattsPerHour = scnr.nextDouble();

// Calculations
usageHoursPerYear = usageHoursPerDay * 365;
usageWattHoursPerYear = wattsPerHour * 8760; // 8760 is the number of hours in a year
usageKWHPerYear = usageWattHoursPerYear / 1000;
costPerYear = usageKWHPerYear * COST_PER_KWH;
lbsCO2PerYear = LBS_CO2_PER_KWH * usageKWHPerYear;

// Printing Energy Audits
System.out.println("Computer Energy Audit");
System.out.println("You use your computer for " + usageHoursPerYear + " hours per year.");
System.out.println("It will use " + usageWattHoursPerYear + " KWH/year.");
System.out.println("Whih will cost " + costPerYear + "$/year for electricity.");
System.out.println("Generating that electricity will produce " + lbsCO2PerYear + " lbs of CO2 pollution.");

return;
}
}

输入:

8 小时/天

5 天/周

50 周/年

100 瓦/小时

我的(错误输出):

计算机能源审计:

您每年使用计算机的时间为 2920.0 小时。

年用电876000.0千瓦时。

Whih 每年的电费为 127.02 美元。

发电将产生 515.2194 磅的二氧化碳污染。

正确的输出:

计算机能源审计:

您每年使用计算机的时间为 2000.0 小时。

它将使用 200.0 千瓦时/年。

每年的电费为 28.999999999999996 美元。

发电会产生 117.63 磅的二氧化碳污染。

最佳答案

您将每周的天数和每年的周数作为输入,但忘记在计算中使用它们。此外,您不是打印 KWH,而是显示存储瓦时的变量。

// Calculations
usageHoursPerYear = usageHoursPerDay * usageDaysPerWeek * usageWeeksPerYear; //calculate based on time used, not 365 days in the year
usageWattHoursPerYear = wattsPerHour * usageHoursPerYear; //use variable from above line
usageKWHPerYear = usageWattHoursPerYear / 1000;
costPerYear = usageKWHPerYear * COST_PER_KWH;
lbsCO2PerYear = LBS_CO2_PER_KWH * usageKWHPerYear;

// Printing Energy Audits
System.out.println("Computer Energy Audit");
System.out.println("You use your computer for " + usageHoursPerYear + " hours per year.");
System.out.println("It will use " + usageKWHPerYear + " KWH/year."); //changed to correct variable
System.out.println("Whih will cost " + costPerYear + "$/year for electricity.");
System.out.println("Generating that electricity will produce " + lbsCO2PerYear + " lbs of CO2 pollution.");

关于java - 电费/能源账单计算器 : Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39629275/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com