Project Overview: Java Program Government and organizations have become increasi
ID: 3912071 • Letter: P
Question
Project Overview: Java Program
Government and organizations have become increasingly concerned with carbon footprint (annual releases of carbon dioxide in the atmosphere). Create a Java program that using Interfaces to calculates the carbon foot print of various objects, much often design is left up to the programmer however good object oriented design is required. As we learned Interfaces allow us to specify similar behavior for seemingly unrelated classes. We will use Interfaces in this project to link a building and automobile and food.
Project Requirements
Create three class Home, Auto and Food .
Provide each class with accessor and mutator methods.
Provide additional instance variables related to calculating the Carbon Footprint (CO2 emmission) (See http://www.carbonglobe.com/carbon-footprint-formula.php for formula for each type). Home ClassInstance variables
Catagory of home (Condo, private home, trailer etc)
Type of Fuel (Electric, Gas, Oil)
Average monthly cost
Cost per unit of full so either in per Kilowatt/Hour for electricity, per 1000 cubic feet for gas, or per gallon for oil)
Use type of fuel category field in a method to determine emission factor.
Vehicle ClassInstance variables
Make, model and year of vehicle (each its own instance variable)
Number of miles driven per week
Fuel efficiency in miles per gallon
Food class Instance variables
Name of food
Dollars spent on food
Category of food.
Use the food category field to in an method to determine the emission factor.
Create an Interface called CarbonFootprint with one method getCarbonFootprint that returns a double representing the carbon footprint in pounds.
The three classes,Home, Auto and Food, must implement the CarbonFootprint Inteface.
Create a main application class Reads data from a file that contains the data required to create at least 3 instances of each of our three classes (so at least 9 object total)
The file format is left up to the developer but must be included in the submission.
Since the type and amount of data differ for each category, it may be wise to use the first field on a given line to identity the category.
Create objects based on the data from the file and place those object in an Array/ArrayList of the CarbonFootprint Interface type.
Iterate through the Array/ArrayList calling the getCarbonFootprint method polymorphically and the catagory and type of item such as:
My private home's carbon footprint is 20555.43 lbs per year.
My 2001 Toyota Camry's carbon footprint is 14234.56 lbs per year.
An Apple's carbon footprint is 1238.22 lbs per year.
The remaining design details are left up to the developer, including how to structure the application, how many classes to develop and the interrelationship of those classes. Use the techniques you've learned in this course, including good object oriented design.
Submission Requirements - Follow the submission requirements posted on elearning. MAKE SURE YOU TURN IN A COPY OF THE TEXT FILE THAT POPULATES THE OBJECTS
*******************************************************************
Grading Sheet
Total Score: (100 points total): _________ Name: _____________________________
NOTE all items on grade sheet refer to correct implementation of the item.
Functionality - the program handles the following as specified_______ (6 pts) Three classes
_______ (6 pts) Each class has instance variable related to only that class
_______ (6 pts) Each class has access and mutator methods
_______ (6 pts) Each class has at least one other method related to only that class
_______ (6 pts) Each class has additional instance variable related to Carbon footprint calculation.
_______ (6 pts) All three class implement the CarbonFootprint Interface
_______ (10 pts) getCarbonFootprint method implemented correctly
_______ (8 pts) Interface called CarbonFootprint created with appropriate method.
Main application
_______ (10 pts) Reads footprint classes' data from a file
_______ (8 pts) Create 3 object of each class, (9 total objects)
_______ (8 pts) Footprint object placed in an Array, Array type is Interface type
_______ (8 pts) Polymorphic iteration of array that produces requried output.
Other Issues
_______ (up to -40 pts) file not included in submission
_______ (up to -20 pts) Poorly documented including Javadoc HTML file (correct format and tags)
_______ (up to -20 pts) Poor programming style (formatting, variable names, no magic numbers etc)
_______ (up to -30 pts) Poor Program structure (separate classes, good object oriented design and driver program, )
Explanation / Answer
INterface:
/*CarbonFootprint interface. File CarbonFootprint.java*/
public interface CarbonFootprint{
double getCarbonFootprint();//calculates the carbon footprint
}//end of interface
BIke:
/*Bike.java: Bike class*/
public class Bike implements CarbonFootprint{
private double yearlyMiles;
private final int caloriesPerMile = 34;
//constructor
public Bike( double miles ){
yearlyMiles = miles;
}//end of constructor
public double getYearlyMiles(){
return yearlyMiles;
}
public void setYearlyMiles( double miles ){
yearlyMiles = miles;
}
@Override
public String toString(){
return String.format("%s: %.2f",
"Yearly miles are ", getYearlyMiles() );
}
@Override
public double getCarbonFootprint(){
return yearlyMiles * caloriesPerMile;
}
}//endnof Bike class
Building:
/*Building.java: Building class*/
public class Building implements CarbonFootprint{
private double averageMonthlyKwh;
private final int months = 12;
//private double carbonFootprint;
//constructor
public Building( double monthlyConsumption ){
averageMonthlyKwh = monthlyConsumption;
}//end of constructor
public void setAverageMonthlyKwh( double monthlyConsumption ){
averageMonthlyKwh = monthlyConsumption;
}
public double getAverageMonthlyKwh(){
return averageMonthlyKwh;
}
@Override
public String toString(){
return String.format("%s: %.2f ",
"the monthly consumption is ", getAverageMonthlyKwh() );
}
@Override
public double getCarbonFootprint(){
return getAverageMonthlyKwh() * months;
}
}//end of Building class
Car:
/*Car.java: Car class*/
public class Car implements CarbonFootprint{
private double averageYearlyMiles;
private double averageMPG;
private final int kgCO2PerMile = 9;
//constructor
public Car( double miles, double MPG ){
averageYearlyMiles = miles;
averageMPG = MPG;
}//end of constructor
public void setAverageYearlyMiles( double miles ){
averageYearlyMiles = miles;
}
public void setAverageMPG( double MPG ){
averageMPG = MPG;
}
public double getAverageYearlyMiles(){
return averageYearlyMiles;
}
public double getAverageMPG(){
return averageMPG;
}
@Override
public String toString(){
return String.format( "%s: %.2f %s: %.2f ",
"Average yearly miles is ", getAverageYearlyMiles(),
"Average MPG is ", getAverageMPG() );
}
@Override
public double getCarbonFootprint(){
return (( getAverageYearlyMiles() * getAverageMPG() ) * kgCO2PerMile );
}
}//end of Car class
Test Class:
/*CarbonFootprintInterfaceTest.java: testing the interface*/
import java.util.ArrayList;
public class CarbonFootprintInterfaceTest{
public static void main( String[] args ){
ArrayList< CarbonFootprint > categories = new ArrayList< CarbonFootprint >();//creates array of objects of type CarbonFootprint
categories[0] = new Bike( 200.00 );
categories[1] = new Building( 4000.52 );
categories[2] = new Car( 5845.25, 20.5 );
System.out.println(" Data of each object: ");
for( CarbonFootprint currentObject : categories ){
System.out.printf("%s %s: %.2f ",
categories.toString(),
"Carbon footprint is ", categories.getCarbonFootprint());
}//end for loop
}//end of main
}//end of CarbonFootprintInterfaceTest
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.