Assignment 1: Input, Output, Variables.
COMP102/112 2022 Tri 1: Assignment 1
Due 17 Mar 10am
The goal of this assignment is for you to be able to construct programs in Java that
- use methods to get simple user input
- use variables for storing values, and expressions for computing values,
- use methods for text output.
Resources and links
Download the zip file for assignment 1 and extract it to an
folder in your home folder. It should contain templates for the Java program that will be marked. Note this file is different from the zip file for the lab exercises.
Read through the whole assignment to see what you need to do.
- Your calculator program:
Do not rename this file.
When you have submitted this file, check that you can read the file listed on the submission page, and complete the submission process.
Calculate Carbon Emissions
Many of our daily activities have an environmental impact by emitting greenhouse gases, especially carbon dioxide (CO2
For this question, you have to create a
program that calculates carbon emissions
caused by two of our daily activities: electricity use and food waste.
- If you are using a computer in a lab, you can run the
CarbonEmissionsCalculator demo to see what your program should do (look in the
- Or, you can watch the video demonstrating what your CarbonEmissionsCalculator program should do.
Carbon emissions for these factors can be calculated using the following simple formula:
Carbon Emissions(kg CO2-e)
Quantity of electricity or food waste
Emission factor (kg CO2-e/unit)
The emission factor helps us convert daily activities to the amount of carbon emission, measured in kg or tonnes of CO2
equivalent. (The "equivalent" is is because most emissions factors incorporate climate-changing non-CO2
gases as well as CO2
The emission factors of electricity use and food waste are:
- EMISSION_FACTOR_POWER: 0.0977 kg CO2-e (CO2equivalent) per kilowatt-hour of electricity
- EMISSION_FACTOR_WASTE: 0.299 kg CO2-e (CO2equivalent) per kg of food waste
For example, consuming 50 kWh of electricity will produce
50(kWh) * 0.0977(kg CO2-e/kWh) = 4.885(kg CO2-e)
Note, these numbers are included as constants in the template code you are given.
The emission factors were obtained from the Summary of Emission Factors 2020
, provided by The Ministry for the Environment.
method so that it:
- Asks the user for the monthly consumption of electricity (kwh) and the weekly food waste (kg)
- Computes and prints the carbon emissions in kg resulting from electricity use (for the month) and food waste (for the week).
- Calculates and prints the average daily carbon emissions from the two sources combined.
According to the data from the Global Carbon Atlas, the typical Kiwi generates about 266.5 kg of carbon dioxide emissions a year from electricity use and about 18 kg of emissions from food waste. Extend your calculator so that it compares the carbon emissions for a household and the NZ average emissions.
method so that it:
- Asks for the electricity use (for the month) and food waste (for the week) for the household and calculates and prints the emissions as in the Core
- Asks the user for the number of individuals in the household.
- Calculates and prints a comparison to the NZ average. For example, it might print "Emissions are 120% of NZ average" if the individuals in the household generate 1.2 times the NZ average, or "Emissions are 82% of the NZ average" if they only generate 82% of the NZ average.
- Ensure that all the results are printed out with exactly 2 decimal places.
- Based on data in the Summary of Emission Factors 2020 file, add more factors/actions that generate carbon, design a more interesting and realistic calculator for carbon emissions that would be more helpful to people trying to reduce their carbon footprint.
To go further
- What is a variable? Can you explain why we need them and why they are different from the variables that Mathematicians use?
- What are some of the ways that your programs calculate a new value out of old values? Can you construct a collection of examples? (They are all called "expressions").