Question
Governments and companies worldwide are becoming increasingly concerned with carbon footprints from buildings burring various types of fuels for heat, vehicles burning fuels for power,
Governments and companies worldwide are becoming increasingly concerned with carbon footprints from buildings burring various types of fuels for heat, vehicles burning fuels for power, and the like. Many scientists blame these greenhouse gases for the phenomenon called global warming. Create the three small classes unrelated by inheritanceclasses Building, Car and Bicycle.
Write the interface CarbonFootprint with a getCarbonFootprintmethod. Have each of your classes implement that interface, so that its getCarbonFootprint method calculates an appropriate carbon footprint for that class.
Write the application that creates objects of each of the three classes, places references to those objects in an array, then iterates through the array, polyorphically involking each object's getCarbonFootprint method. For each object, print some identifying information and the object's carbon footprint.
Class Buiding:
instance variables:
square feet Boolean values for each of these wood, basement, concreate, steel
constant variables
wood frame = 50 basement = 20 concrete = 47 steel = 17
Method:
Constructor that accepts all the instance variables getCarbonFootprint- outputs the carbon footprint by adding all the constant values who have a true value together and multiplying by square footage:
square footage * (wood frame + basement + concrete + steel)assuming all are true
Class Car:
instance variable:
gallons
constant variable:
CO2 yields
Method:
Constructor that accepts gallons getCarbonFootprint- outputs the carbon footprint by multiplying gallons by CO2 yields
class Bicycle:
Method:
getCarbonFootprint- outputs the carbon footprint as 0
interface CarbonFootprint
This will contain a single method header for getCarbonFootprint
CarbonFootprintDriver
Create the array to store CarbonFootprints of size 3. Add one or more of each element to the list Output the carbon footprint for each item in the array Building conditions are displayed with correct formatting (commas between items, with in front of the first item
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started