3 Replies - 2475 Views - Last Post: 27 October 2009 - 11:15 AM Rate Topic: -----

#1 Myntal  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 06-October 09

Returning values to main method.

Posted 27 October 2009 - 10:20 AM

Ok, so I need to recall mpg1 and dist1 to my main method, yet it says "calcMPG(int, double) in CarV3 cannot be applied to ()." Help would be nice.

public class CarV3
{	
	CarV3()
	{
	}
		
	public int calcDistance(int sMiles1, int eMiles1)
	{
		int dist1 = sMiles1 - eMiles1;
		return dist1;
	}
	
	public double calcMPG(int dist1, double gals1)
	{
		double mpg1 = dist1 / gals1;
		return mpg1;
	}
	
	public static void main(String[] args)
	{		
		int sMiles1 = 17235;
		int eMiles1 = 17562;
		double gals1 = 14.7;	
		
		
		System.out.println("						 Gas Mileage Calculations");
		System.out.println("Type of car   Start Miles   End Miles   Distance   Gallons   Miles/Gal");
		System.out.println("======================================================================");
		
		double mpg1 = calcMPG();


	}
}


Is This A Good Question/Topic? 0
  • +

Replies To: Returning values to main method.

#2 Locke  Icon User is offline

  • Sarcasm Extraordinaire!
  • member icon

Reputation: 521
  • View blog
  • Posts: 5,596
  • Joined: 20-March 08

Re: Returning values to main method.

Posted 27 October 2009 - 10:22 AM

You can't call the calcMPG() method using no arguments. You created a method with 2 arguments of type int, double.

So you have to call it using 2 parameters, one of int type, one of double type.

This post has been edited by Locke: 27 October 2009 - 10:23 AM

Was This Post Helpful? 0
  • +
  • -

#3 Myntal  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 06-October 09

Re: Returning values to main method.

Posted 27 October 2009 - 10:28 AM

I think I did what you said, and now I am getting .class expeceted.

int dist1 = calcDistance(int sMiles1, int eMiles1);
double mpg1 = calcMPG(int dist1, double gals1);


Was This Post Helpful? 0
  • +
  • -

#4 Locke  Icon User is offline

  • Sarcasm Extraordinaire!
  • member icon

Reputation: 521
  • View blog
  • Posts: 5,596
  • Joined: 20-March 08

Re: Returning values to main method.

Posted 27 October 2009 - 11:15 AM

You need to instantiate an object of your CarV3 class to call the methods.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1