SHARE
TWEET

Untitled

a guest Dec 10th, 2018 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class FootprintCalculator {
  4.    
  5.     public static void main(String[] args) {
  6.         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.");
  7.         carbonPrivateAutoUseage();
  8.         carbonPrivateAutoOwnership();
  9.         carbonPublicTransport();
  10.         carbonAirTransport();
  11.        
  12.         double kgCO2 = carbonPrivateAutoUseage();
  13.         double kgCO2Car = carbonPrivateAutoOwnership();
  14.         double kgC02OnBus = carbonPublicTransport();
  15.         double totalHaul = carbonAirTransport();
  16.         double overallTotal = carbonTotal(kgCO2, kgCO2Car, kgC02OnBus, totalHaul);
  17.         printReport(kgCO2, kgCO2Car, kgC02OnBus, totalHaul, overallTotal);
  18.     }
  19.    
  20.     public static Scanner userInput = new Scanner(System.in);
  21.    
  22.     // Total amount of carbon produce per year by driving a car
  23.     public static double carbonPrivateAutoUseage() {
  24.         System.out.println("How many liters of gasoline do you use per day?");
  25.         double litersPerDay = userInput.nextDouble();
  26.         System.out.println("How many kilometers do you drive per day?");
  27.         double kmPerDay = userInput.nextDouble();
  28.         double fuelEfficiency = kmPerDay/litersPerDay;
  29.         double litresUsedPerYear = 365 * (kmPerDay/fuelEfficiency);
  30.         double kgCO2 = 12.85 * litresUsedPerYear;
  31.         return kgCO2;
  32.     }
  33.    
  34.     // Total amount of carbon produced per year from owning a car
  35.     public static double carbonPrivateAutoOwnership() {
  36.         System.out.println("How old is your car?");
  37.         double ageOfCar = userInput.nextDouble();
  38.         double kgC02PerGJ = 1.94;
  39.         double carbonManufactureCar = (kgC02PerGJ*120) + ((3.8*kgC02PerGJ)*ageOfCar);
  40.         double kgCO2Car = carbonManufactureCar/ageOfCar;
  41.         return kgCO2Car;
  42.     }
  43.    
  44.     // Total amount of carbon produced per year by public transport
  45.     public static double carbonPublicTransport() {
  46.         System.out.println("How many kilometers do you ride the bus per day?");
  47.         double busRide = userInput.nextDouble();
  48.         double kgC02OnBus = (0.18*busRide) * 365;
  49.         return kgC02OnBus;
  50.     }
  51.    
  52.     // Total amount of carbon produced per year by air transport
  53.     public static double carbonAirTransport() {
  54.         System.out.println("How many kilometers in total have you flown on domestic flights this year?");
  55.         double domesticFlight = userInput.nextDouble();
  56.         System.out.println("How many kilometers in total have you flown on international flights this year?");
  57.         double internationalFlight = userInput.nextDouble();
  58.         double smallHaul = 0.10*domesticFlight;
  59.         double bigHaul = 0.2*internationalFlight;
  60.         double totalHaul = smallHaul+bigHaul;
  61.         return totalHaul;
  62.     }
  63.    
  64.     // Total amount of carbon produced per year in metric tons
  65.     public static double carbonTotal(double kgCO2, double kgCO2Car, double kgC02OnBus, double totalHaul) {
  66.         double overallTotal = (kgCO2 + kgCO2Car + kgC02OnBus + totalHaul)/1000;
  67.         return overallTotal;
  68.     }
  69.    
  70.     public static void printReport(double kgCO2, double kgCO2Car, double kgC02OnBus, double totalHaul, double overallTotal){
  71.         System.out.println("You produce an annual total of metric " + overallTotal + " tons of CO2 per year for your personal transport.");
  72.         System.out.println("The breakdown is as follows:");
  73.         System.out.println("Private Automobile Usage          " + kgCO2);
  74.         System.out.println("Private Automobile Ownership      " + kgCO2Car);
  75.         System.out.println("Public Transport                  " + kgC02OnBus);
  76.         System.out.println("Air Transport                     " + totalHaul);
  77.        
  78.     }
  79. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top