Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

COMSATS University Islamabad, Lahore Campus

Department of Computer Science

Assignment 3 – Semester Fall 2022


Course Title: Object Oriented Programming Course Code: CSC241 Credit Hours: 4(3,1)
Course Instructor/s: Ms. Muntaha Iqbal Program Name: BSE, BCS
Semester: 2nd Section: C, Repeaters Batch SP22-BSE, BCS Repeaters
Total Marks: 10 Obtained Marks: Date: December 22, 2022
Student’s Name: Reg. No.
Important Instruction:

• Student is himself/herself responsible for successful submission of assignment on Google Classroom


• Your submission must include the following in a single pdf file.
1. Code of all classes
2. Snapshot of the output of the submitted code.
• Copied assignments will get zero credit.
• Deadline: December 27, 2022, at 11:30 PM

Question 1:
Apply the concepts of Arrays and write down the Code.
Learning Outcome: CLO2-->SO3-->C3 (Apply)

Due to ever increasing use of fossil fuels (petrol, diesel, etc.) in our daily lives, the amount of
greenhouse gases i.e. Carbon Dioxide (CO2) in the atmosphere is rapidly increasing, which is
causing global warming. Scientists have associated values called “Carbon Footprint” to almost
all human activities. For example each square feet of a covered area generates about 0.005 tons
of CO2 annually. A car generates 0.0000292 tons of CO2 for each mile it is driven.

In order to handle the “Carbon Footprint”, your job is to create an interface called
CarbonFootPrintProducer that shall contain a method declaration called getCarbonFootPrint(),
that shall return a double value indicating the amount of CO2 generated by an instance of the
implementing class.

Your next job is to create two classes i.e. House and Car, both shall implement
CarbonFootPrintProducer interface. House must have an attribute coveredArea, while Car
must have an attribute milesDriven, both public. Create fully parametrized constructor in each
subclass. Both subclasses must contain their own getCarbonFootPrint() implementation that
shall calculate the CO2. For the calculation of CO2, use the following formulas.

CO2 produced by House = coveredArea * 0.005


CO2 produced by a Car = milesDriven * 0.0000292
Create a class CarbonFootPrintTest. Define static method calculateTotalFootPrint(ArrayList
<CarbonFootPrintProducer> entities) method that shall calculate and return total CO2 of
passed collection using polymorphism. Also define the main method in test class that shall
create one object of House and Car passing user given coveredArea and milesDriven,
respectively, to the constructor. Add both objects in an ArrayList and print total CO2 generated
by House and Car using calculateTotalFootPrint method.

Sample runs of the program is given below.

Enter miles by a Car: 100


Enter Covered Area of a House: 1000
The total Carbon Foot Print is 5.002920 tone(s) of CO2

You might also like