Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using an abstract class with only pure virtual functions, create three small cla

ID: 3552072 • Letter: U

Question

Using an abstract class with only pure virtual functions, create three small classes unrelated by inheritance---clases Building, Car and Bicycle. Give each class some uique appropriate attributes and behaviors that it does not have in common with other classes. Write an abstract class CarbonFootprint with only a pure virtual getCarbonFootPrint method. Have each of the classes inherit from that abstract class and implement the getCarbonFootprint method to calculate the appropriate cabon footprint for that class.

Write an application that creates objects of each of the three classes, places pointers to those objects in a vector of CarbonFootprint pointers, then iterates through the vector, polymorphically invoking each objetc's CarbonFootprint method. For each object, print some identifying information and the object's carbon footprint.

Explanation / Answer

import java.util.Scanner;

/* Program that calculates user's carbon footprint

given a set of inputs. Provides a cohesive

breakdown of user's carbon usage.

*/

public class FootprintCalculator

{


public static void main(String args[])

{

//private automobile usage

System.out.println("Liters Used Per Year by Automobile: ");

Scanner sc = new Scanner(System.in);

double lpy = sc.nextDouble();

System.out.println("Kilometers driven per day: ");

double kmpd = sc.nextDouble();

System.out.println("Automobile Fuel Efficiency in Km/liter: ");

double fe = sc.nextDouble();

double pau = carbonPrivateAutoUsage(lpy, kmpd, fe);


//private automobile ownership

System.out.println("Age of car in years: ");

int age = sc.nextInt();

double pao = carbonPrivateAutoOwnership(age);


//public transportation

System.out.println("Kilometers travelled with public transportation per year: ");

double kmt = sc.nextDouble();

double pt = carbonPublicTransport(kmt);


//air travel

System.out.println("Kilometers travelled in short-haul air travel per year: ");

double sh = sc.nextDouble();

System.out.println("Kilometers travelled in long-haul air travel per year: ");

double lh = sc.nextDouble();

double at = carbonAirTransport(lh, sh);



//total carbon footprint

double tcf = (pau + pao + pt + at) / 1000;

double tc = (pau + pao + pt + at); //used for calculating the percentage breakdown


//print report

System.out.println("You produce an annual total of " + tcf + " metric tons of CO2 per year for your personal transport.");

System.out.println();

System.out.println("The breakdown is as follows:");

System.out.println(" Private Automobile Usage: " + pau / tc * 100 + "%");

System.out.println(" Private Automobile Ownership: " + pao / tc * 100 + "%");

System.out.println(" Public Transport: " + pt / tc * 100 + "%");

System.out.println(" Air Transport: " + at / tc * 100 + "%");


}


public static double carbonPrivateAutoUsage(double lpy, double kmpd, double fe)

{

lpy = 365 * kmpd / fe;

double pau = lpy * 12.85;

return pau;

}


public static double carbonPrivateAutoOwnership(double age)

{

double manufacture = 120 * 26.3 * 1.94;

double maintenance = 3.8 * 26.3 * 1.94 * age;

double pao = manufacture / age + maintenance;

return pao;

}


public static double carbonPublicTransport(double kmt)

{

double pt = .18 * kmt;

return pt;

}


public static double carbonAirTransport(double lh, double sh)

{

sh = sh * 0.10;

lh = lh * 0.2;

double at = lh + sh;

return at;

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote