Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

COS 160 Using a Scanner to read input. Working with variables and expressions. Energy Audit You are going to write a program to perform an

COS 160

Using a Scanner to read input. Working with variables and expressions.

Energy Audit

You are going to write a program to perform an energy audit of the electricity used by a computer. Your main method should be organized into three sections: 1. input values, 2. calculations, and 3. printing results. Separate these sections in your code with a comment at the start of each section and a blank line between sections.

Part 1 (10 points) Prompting for and reading user input values

First you will ask the user for some information about how often they use their computer. Get the 3 values shown below. For each value, print a prompt and then read the value using a Scanner. Use scnr.nextDouble(); to get input values. You can copy and paste these variable declarations into your program.

double usageHoursPerDay; // hours computer is on per day double usageDaysPerWeek; // days computer is used per week double usageWeeksPerYear; // weeks computer is used per year

Next ask them how many watts per hour their computer uses. Suggest 100 for a desktop and 30 for a laptop if they don't know.

double wattsPerHour; // watts used by computer per hour

Part 2 (10 points) Calculations

In the second section calculate the values shown below. In your program you should be writing mathematical expressions using the variables from the first and second sections. Use type double for all calculations.

First add these two constants to your program. You will need them for the calculations.

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

Now calculate these values:

double usageHoursPerYear = // hours computer is on per year double usageWattHoursPerYear = // this is just multiplying by wattsPerHour double usageKWHPerYear = // divide by 1000 to convert to KILO-WATT-HOURS double costPerYear = // use the first constant in your calculation double lbsCO2PerYear = // use the second constant in your calculation

Part 3 (10 points) Printing the energy audit

Print your energy audit that shows the calculated results. Format it neatly like this:

Computer Energy Audit: You use your computer for 2000.0 hours per year. It will use 200.0 KWH/year. Which will cost 28.999999999999996 $/year for electricity. Generating that electricity will produce 117.63 lbs of CO2 pollution.

(Later in this class we will learn how to round off and format printed values so you don't print all those excessive digits of precision.) Run these two test cases:

A typical business computer: 8 hours/day, 5 days/week, 50 weeks/year, 100 watts/hour (The output should match the example above. CHECK THAT YOUR RESULTS MATCH!!!)

A typical student laptop: 3 hours/day, 6 days/week, 30 weeks/year, 30 watts/hour

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Inductive Databases And Constraint Based Data Mining

Authors: Saso Dzeroski ,Bart Goethals ,Pance Panov

2010th Edition

1489982175, 978-1489982179

More Books

Students also viewed these Databases questions