Lecture notes for the Introduction to multidisciplinary Computer Science II by James Tam Return to the course web page

CPSC 219: Assignment 3

New Concepts to be applied for the assignment

Introduction

Although there are many ways in which the impact of one's lifestyle can have an impact on the earth one of the simplest approaches is to calculate the tons of carbon that get generated on a yearly basis as you go about your everyday activities. For this assignment you will be writing a program that will ask the user a number of questions about his or her lifestyle. In some cases the questions will require a specific answer (e.g., How many miles do you drive each year?) while other cases the program will allow the user to select an option from a series of choices (e.g., What category of accommodation do you live: small house, medium house, large house). As the user answers these questions the program will calculate a tally of the tons of carbon generated each year. Note: this program is simply a tool to calculate a value...how you use and interpret these numbers is entirely up to you!

How the calculations are to be performed

The questions are categorized into 6 categories and each group consists of one or more questions. The answer to each question will either directly determine the tons of carbon generated or be used in conjunction with the answer from another question. The tons of carbon generated should be calculated and specified as a yearly figure.

Category I: Electricity usage

For this question the user will be given the choice of either entering the kilowatt hours used per year or estimating that value by specifying the size of their accommodation.

(Exact value):

10 kWh = 0.01 tons of carbon

(Estimate):

Small house / apartment: 1.58 tons
Medium sized house: 2.53 tons
Large house: 3.69 tons
 

Category II: Heating

Small house / apartment: 2.44 tons
Medium sized house: 3.65 tons
Large house: 5.48 tons

Category III: Transportation

Question 1: Bus travel

Every 100 miles traveled by bus each year will generate 0.01 tons of carbon.

Question 2: Train travel

Every 100 miles traveled by train each year will generate 0.01 tons of carbon.

Question 3: Vehicle type and mileage

This question actually consists of two sub questions: one is about the size of the person's vehicle, the other relates to mileage. The number of tons of carbon generated yearly for all the combinations of answers are shown in the table below.

 

Small car

Medium sized car

Large car

Low mileage (~6000 miles/year)

2.32

2.6

3.58

Average mileage (~9000 miles/year)

3.48

3.9

5.36

High mileage (~12000 miles/year)

4.64

5.2

7.15

Category IV: Food

Question 1: Amount of organic food consumed

None: 0.7 tons

Some: 0.5 tons

Most: 0.2 tons

All: 0 tons

Question 2: Amount of meat and dairy consumed

Above average: 0.6 tons

Average: 0.4 tons

Below average: 0.25 tons

Lacto-vegetarian: 0.1 tons

Vegan: 0 tons

Question 3: Source and season of the food

Mostly out of country and out of season: 0.5 tons

Average amount of locally produced food: 0.3 tons

Above average amounts of locally produced food: 0.2

Almost all food is locally produced: 0.1 tons

Question 4: Packaging and processing (how much of your food consists of ready-to-eat meals)

Above average: 0.6 tons

Average: 0.4 tons

Below average: 0.2 tons

Very little: 0.05 tons

Question 5: Wastage (what proportion of the food that you buy ends up getting thrown out)

Above average (30%+ wasted): 0.39 tons

Average (~20%  wasted) 0.35 tons

Below average (~10% wasted) 0.32 tons

Almost none1: 0.29 tons

1 Apparently some wastage is unavoidable as food is produced.

Category V: Composting

None: 0.2 tons

Some: 0.1 tons

Everything: 0 tons

Category VI: Spending, consumption and recycling

This category relates to the amount spent on leisure, things for your accommodations, clothing, hygiene, books etc. The category consists of two questions: one question asks how much is spent on consumption, the other asks how much of those goods and its packaging is recycled.   The number of tons of carbon generated yearly for all the combinations of answers are shown in the table below.

  No recycling Recycle paper, glass and metal Recycle all plastics Recycle everything
Above average consumption 5 4.93 4.86 4.79
Average consumption levels 3.4 3.33 3.26 3.19
Below average consumption levels 2.4 2.33 2.26 2.19
Much below average consumption levels 1.4 1.33 1.26 1.19

For each question, the program should check for invalid input (e.g., selecting a non-existent menu option or a numerical option outside a range of values that makes sense for a questions) and handle the error according to the principles of good design (I'll talk about this in lecture).  [Example] Also the user should have the option of skipping any question so they can proceed with the remaining questions (remember: programs should never make the user feel 'trapped' and force them to give an answer). [Example] Also if the answer to one question has an impact on another question this should be reflected by the program e.g., if the user chooses not to answer the question about the size of the vehicle that they drive then it makes no sense to ask what their yearly mileage is. As each question is answered the program should not only show the number of tons of carbon that get generated according to the answer to that specific question (so they get immediate feedback about how their lifestyle has an impact) but also the running total of the tons of carbon produced should also be shown each step of the way (even if the result is currently zero). When all the questions have been answered a grand total should then be calculated and displayed.

Finally your program must be written using principles of good Object-Oriented designs (at least two classes: a driver class with a main method and another class whose methods will implement the above functionality). For this assignment it is likely that your main method will now just instantiate an instance of the other class and perhaps include a few method calls to an instance of class.

One approach to the assignment: The disadvantage to this approach is that data which probably should be attributes of the other class ("Footprint" in the example) such as the tons generated are no longer encapsulated with the definition of the class Footprint disallowing the ability to employ Object-Oriented approaches such as information hiding.
  public class Driver
  {
         public static void main (String [] args)
         {
                  float carbonHeating;
                  Footprint aFootprint = new Footprint ();
                      :        :                :        :

                  aFootprint.introduction();    // Describe how the program works
                  carbonHeating = aFootprint.processHeatingQuestion();  // Prompt for their heating info, generate the tons of carbon based on their answer.
                      etc.
          }
   }

Another (better) approach to the assignment:
 public class Driver
 { 
        public static void main (String [] args)
        {

                  Footprint aFootprint = new Footprint ();

                  aFootprint.start ();
        }
 }

public class Footprint
 {
        private
float carbonHeating;

              :            :
        public void start ()
        {
                introduction();
                carbonHeating = processHeatingQuestion();

                Etc.
        }   

}

You cannot implement a solution to assignment that employs only a single class nor can you implement a solution that uses static methods - aside from the 'main' method.  (If you don't know what I mean by  implementing a program using only static method calls then that's a good thing - overuse of static methods is regarded as bad style in terms of the Object-Oriented approach as you will see later in the term).

Submitting your work:

  1. Assignments (source code/'dot-java' files) must be electronically submitted according to [the assignment submission requirements].
  2. As a reminder, you are not allowed to work in groups for this class. Copying the work of another student will be regarded as academic misconduct (cheating).  For additional details about what is and is not okay for this class please refer to the following [link].
  3. Before you submit your assignment to help make sure that you haven't missed anything here is a [checklist] of items to be used in marking.

References for the material used in the design of this assignment

  1. Government of Canada, Environment Canada: http://www.ec.gc.ca/education/default.asp?lang=en&n=27763D25-6
  2. Carbon footprint: http://www.carbonfootprint.com
  3. Global footprint network: http://www.footprintnetwork.org/en/
  4. Carbon independent: http://www.carbonindependent.org/