printReport(); printReport(double kgCO2, double kgCO2Car, double kgC02OnBus, double totalHaul, double overallTotal); double x = printReport(); double x = printReport(double kgCO2, double kgCO2Car, double kgC02OnBus, double totalHaul, double overallTotal);
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();
printReport();
}
public static double carbonPrivateAutoUseage() {
Scanner userInput = new Scanner (System.in);
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;
}
public static double carbonPrivateAutoOwnership() {
Scanner userInput = new Scanner (System.in);
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;
}
public static double carbonPublicTransport() {
Scanner userInput = new Scanner (System.in);
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;
}
public static double carbonAirTransport() {
Scanner userInput = new Scanner (System.in);
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;
}
public static double carbonTotal(double kgCO2, double kgCO2Car, double kgC02OnBus, double totalHaul) {
double overallTotal = (kgCO2 + kgCO2Car + kgC02OnBus + totalHaul)/1000;
return overallTotal;
}
// This is the one I'm having trouble calling to my main.
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);
}
}
Yeah, and I realize my code is a little redundant with a Scanner in the first 4 methods, but I can't figure out how to put the Scanner userInput into the parameters. Thank you for taking a look over this!

New Topic/Question
Reply



MultiQuote





|