Problem w/ Parameters & Calling Methods

  • (2 Pages)
  • +
  • 1
  • 2

24 Replies - 682 Views - Last Post: 30 September 2012 - 10:47 PM Rate Topic: -----

#16 fromTheSprawl  Icon User is offline

  • Monomania
  • member icon

Reputation: 513
  • View blog
  • Posts: 2,056
  • Joined: 28-December 10

Re: Problem w/ Parameters & Calling Methods

Posted 30 September 2012 - 08:33 PM

Can you post the set of questions that get outputted? Your methods are designed to take input per call, but I don't see any redundancies in a glance.
Was This Post Helpful? 0
  • +
  • -

#17 Collectionize  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 30-September 12

Re: Problem w/ Parameters & Calling Methods

Posted 30 September 2012 - 08:41 PM

Ah, it just repeats it twice. I think it's because I called it then assigned it to a variable, but it still prints out what the method does. Does that sound right or am I just mumbling words?

carbonPrivateAutoUseage (method has these sets of questions)
How many liters of gasoline do you use per day?
How many kilometers do you drive per day?

carbonPrivateAutoOwnership
(method has this question)
How old is your car?

carbonPublicTransport (method has this question)
How many kilometers do you ride the bus per day?

carbonAirTransport (method has these sets of questions)
How many kilometers in total have you flown on domestic flights this year?
How many kilometers in total have you flown on international flights this year?
Was This Post Helpful? 0
  • +
  • -

#18 fromTheSprawl  Icon User is offline

  • Monomania
  • member icon

Reputation: 513
  • View blog
  • Posts: 2,056
  • Joined: 28-December 10

Re: Problem w/ Parameters & Calling Methods

Posted 30 September 2012 - 09:47 PM

It repeats everything twice?
Was This Post Helpful? 0
  • +
  • -

#19 Collectionize  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 30-September 12

Re: Problem w/ Parameters & Calling Methods

Posted 30 September 2012 - 10:01 PM

Yeah, it repeats the set of questions twice.
Was This Post Helpful? 0
  • +
  • -

#20 fromTheSprawl  Icon User is offline

  • Monomania
  • member icon

Reputation: 513
  • View blog
  • Posts: 2,056
  • Joined: 28-December 10

Re: Problem w/ Parameters & Calling Methods

Posted 30 September 2012 - 10:03 PM

Can we see your updated code? :)
Was This Post Helpful? 0
  • +
  • -

#21 Collectionize  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 30-September 12

Re: Problem w/ Parameters & Calling Methods

Posted 30 September 2012 - 10:25 PM

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);
		
	}
}

BTW, thank you so much for helping me!
Was This Post Helpful? 0
  • +
  • -

#22 fromTheSprawl  Icon User is offline

  • Monomania
  • member icon

Reputation: 513
  • View blog
  • Posts: 2,056
  • Joined: 28-December 10

Re: Problem w/ Parameters & Calling Methods

Posted 30 September 2012 - 10:34 PM

Oh, you should now remove lines 7 to 10, because they're not used anymore. And you're welcome. ^^
Was This Post Helpful? 0
  • +
  • -

#23 Collectionize  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 30-September 12

Re: Problem w/ Parameters & Calling Methods

Posted 30 September 2012 - 10:41 PM

Thank you so much once again! Gosh, if it wasn't for you I'd probably be spending another day trying to figure this out. =) Have a nice night!
Was This Post Helpful? 0
  • +
  • -

#24 fromTheSprawl  Icon User is offline

  • Monomania
  • member icon

Reputation: 513
  • View blog
  • Posts: 2,056
  • Joined: 28-December 10

Re: Problem w/ Parameters & Calling Methods

Posted 30 September 2012 - 10:42 PM

Hey, no problem, glad I could help. It's morning here, so good night there. ^^
Was This Post Helpful? 0
  • +
  • -

#25 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8342
  • View blog
  • Posts: 31,880
  • Joined: 06-March 08

Re: Problem w/ Parameters & Calling Methods

Posted 30 September 2012 - 10:47 PM

This is ridiculous :)

		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);



If these method return a value why do you call them once without storing the value returned and an another time saving the value returned ????
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2