Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class FootprintCalculator {
- public static void main(String[] args) {
- System.out.println("We will calculate the CO2 emissions for your transportation in a year. After answering a few of the following questions that appear. Please answer with numbers.");
- carbonPrivateAutoUseage();
- carbonPrivateAutoOwnership();
- carbonPublicTransport();
- carbonAirTransport();
- double kgCO2 = carbonPrivateAutoUseage();
- double kgCO2Car = carbonPrivateAutoOwnership();
- double kgC02OnBus = carbonPublicTransport();
- double totalHaul = carbonAirTransport();
- double overallTotal = carbonTotal(kgCO2, kgCO2Car, kgC02OnBus, totalHaul);
- printReport(kgCO2, kgCO2Car, kgC02OnBus, totalHaul, overallTotal);
- }
- public static Scanner userInput = new Scanner(System.in);
- // Total amount of carbon produce per year by driving a car
- public static double carbonPrivateAutoUseage() {
- System.out.println("How many liters of gasoline do you use per day?");
- double litersPerDay = userInput.nextDouble();
- System.out.println("How many kilometers do you drive per day?");
- double kmPerDay = userInput.nextDouble();
- double fuelEfficiency = kmPerDay/litersPerDay;
- double litresUsedPerYear = 365 * (kmPerDay/fuelEfficiency);
- double kgCO2 = 12.85 * litresUsedPerYear;
- return kgCO2;
- }
- // Total amount of carbon produced per year from owning a car
- public static double carbonPrivateAutoOwnership() {
- System.out.println("How old is your car?");
- double ageOfCar = userInput.nextDouble();
- double kgC02PerGJ = 1.94;
- double carbonManufactureCar = (kgC02PerGJ*120) + ((3.8*kgC02PerGJ)*ageOfCar);
- double kgCO2Car = carbonManufactureCar/ageOfCar;
- return kgCO2Car;
- }
- // Total amount of carbon produced per year by public transport
- public static double carbonPublicTransport() {
- System.out.println("How many kilometers do you ride the bus per day?");
- double busRide = userInput.nextDouble();
- double kgC02OnBus = (0.18*busRide) * 365;
- return kgC02OnBus;
- }
- // Total amount of carbon produced per year by air transport
- public static double carbonAirTransport() {
- System.out.println("How many kilometers in total have you flown on domestic flights this year?");
- double domesticFlight = userInput.nextDouble();
- System.out.println("How many kilometers in total have you flown on international flights this year?");
- double internationalFlight = userInput.nextDouble();
- double smallHaul = 0.10*domesticFlight;
- double bigHaul = 0.2*internationalFlight;
- double totalHaul = smallHaul+bigHaul;
- return totalHaul;
- }
- // Total amount of carbon produced per year in metric tons
- public static double carbonTotal(double kgCO2, double kgCO2Car, double kgC02OnBus, double totalHaul) {
- double overallTotal = (kgCO2 + kgCO2Car + kgC02OnBus + totalHaul)/1000;
- return overallTotal;
- }
- public static void printReport(double kgCO2, double kgCO2Car, double kgC02OnBus, double totalHaul, double overallTotal){
- System.out.println("You produce an annual total of metric " + overallTotal + " tons of CO2 per year for your personal transport.");
- System.out.println("The breakdown is as follows:");
- System.out.println("Private Automobile Usage " + kgCO2);
- System.out.println("Private Automobile Ownership " + kgCO2Car);
- System.out.println("Public Transport " + kgC02OnBus);
- System.out.println("Air Transport " + totalHaul);
- }
- }
Add Comment
Please, Sign In to add comment