Basic <identifier> expected problem

I am having trouble getting this to compile and understanding why and what it needs as a remedy?

Any help you can gice would be great! Thx, -Alex

These are the errors compiled so far, the original code follows

--Configuration: <Default>--

E:\Comp Prog\Conversion.java:53: <identifier> expected

public static void showKilometers(double)

^

E:\Comp Prog\Conversion.java:69: ')' expected

^

2 errors

Process completed.

//** Jason ManleyCis 111 Chapter 5 / Ass 8 July 18, 2007 --This program prompt user for a distance in metters. It will then prompt user for convertion into Km, Inches, and feet or to Quit.*//

import java.util.Scanner;

publicclass Conversion

{

publicstaticvoid main(String[]args)

{

Double metersToBeConverted ;

int conversionSelection;// 4 = Exit

Double resultInKilometers;

Double resultInInches;

Double resultInFeet;

Scanner keyboard =new Scanner(System.in);

System.out.println("Enter the distance to be converted in meters : ");

metersToBeConverted = keyboard.nextInt();

System.out.println("Enter (1) for the distance in Kilometers");

System.out.println("Enter (2) for the distance in inches");

System.out.println("Enter (3) for the distance in feet");

System.out.println("Enter (4) to exit.");

conversionSelection = keyboard.nextInt();

menu();

}

publicstaticvoid menu()

{

if (conversionSelection == 1)

showKilometers();

elseif (conversionSelection == 2)

showInches();

elseif (conversionSelection == 3)

showFeet();

else System.exit(0);

}

publicstaticvoid showKilometers(metersToBeConverted)

{

resultInKilometers = metersToBeConverted * .001;

System.out.println( metersToBeConverted +" meters is equivalent to " + resultInKilometers +" Kilometers.");

}

publicstaticvoid showInches(metersToBeConverted)

{

resultInInches = metersToBeConverted * 39.37;

System.out.println( metersToBeConverted +" meters is equivalent to " + resultInInches +" Inches.");

}

publicstaticvoid showFeet()metersToBeConverted

{

resultInFeet = metersToBeConverted * 3.21;

System.out.println( metersToBeConverted +" meters is equivalent to " + resultInFeet +" Feet.");

}

}

[3978 byte] By [alexerosa] at [2007-11-27 11:15:50]
# 1

Do you know the difference between double and Double?

BigDaddyLoveHandlesa at 2007-7-29 14:15:37 > top of Java-index,Java Essentials,New To Java...
# 2

This

public static void showKilometers(metersToBeConverted)

is not a valid method signature. You need to delcare what type of variable metersToBeConverted is.

For example

public static void main(String[] args)

means that the parameter names args is of a String array type

You have this same problem elsewher

cotton.ma at 2007-7-29 14:15:37 > top of Java-index,Java Essentials,New To Java...
# 3

public static void showInches(metersToBeConverted)

{

...

}

DON'T do this.

Instead, pass variables to your functions as parameters:

public static void showInches(double inputMeters)

{

...

}

PatrickFinnigana at 2007-7-29 14:15:37 > top of Java-index,Java Essentials,New To Java...
# 4

I messed around with your code and got it to compile:

//** Jason ManleyCis 111 Chapter 5 / Ass 8 July 18, 2007 --This program prompt user for a distance in metters. It will then prompt user for convertion into Km, Inches, and feet or to Quit.*//

import java.util.Scanner;

public class Conversion {

public static void main(String[]args) {

int metersToBeConverted;

int conversionSelection; // 4 = Exit

Scanner keyboard = new Scanner(System.in);

System.out.println("Enter the distance to be converted in meters : ");

metersToBeConverted = keyboard.nextInt();

System.out.println("Enter (1) for the distance in Kilometers");

System.out.println("Enter (2) for the distance in inches");

System.out.println("Enter (3) for the distance in feet");

System.out.println("Enter (4) to exit.");

conversionSelection = keyboard.nextInt();

menu(conversionSelection, metersToBeConverted);

}

public static void menu(int conversionSelection, int inputMeters) {

if (conversionSelection == 1)

showKilometers(inputMeters);

else if (conversionSelection == 2)

showInches(inputMeters);

else if (conversionSelection == 3)

showFeet(inputMeters);

else System.exit(0);

}

public static void showKilometers(double inputMeters) {

double resultInKilometers = inputMeters * .001;

System.out.println(inputMeters + " meters is equivalent to " + resultInKilometers + " Kilometers.");

}

public static void showInches(double inputMeters) {

double resultInInches = inputMeters * 39.37;

System.out.println(inputMeters + " meters is equivalent to " + resultInInches + " Inches.");

}

public static void showFeet(double inputMeters) {

double resultInFeet = inputMeters * 3.21;

System.out.println(inputMeters + " meters is equivalent to " + resultInFeet + " Feet.");

}

}

Do you see how I am passing variables by reference to your functions? If needed, ask questions and we can help you understand this concept better.

Message was edited by:

PatrickFinnigan

PatrickFinnigana at 2007-7-29 14:15:37 > top of Java-index,Java Essentials,New To Java...
# 5

> Do you see how I am passing variables by reference to

> your functions?

Nooooooooooooooooooooooo!

You are passing variables by value to those methods. All parameter passing in Java is by value not reference. Always.

cotton.ma at 2007-7-29 14:15:37 > top of Java-index,Java Essentials,New To Java...
# 6

> > Do you see how I am passing variables by reference

> to

> > your functions?

>

> Nooooooooooooooooooooooo!

>

> You are passing variables by value to those methods.

> All parameter passing in Java is by value not

> reference. Always.

<always />

<this_thread>

<joke belief="mine" truth="not" oops="almost" />

</this_thread>

georgemca at 2007-7-29 14:15:37 > top of Java-index,Java Essentials,New To Java...
# 7

thank you, i do now. I really apreciate your help!-Alex

alexerosa at 2007-7-29 14:15:37 > top of Java-index,Java Essentials,New To Java...
# 8

thank you, . I really apreciate your help,i needed the detailed explanation!-Alex

alexerosa at 2007-7-29 14:15:37 > top of Java-index,Java Essentials,New To Java...
# 9

Thank you for the fix, with the rest of the stars I think I can quit banging my head on the keyboard, I spent hours on this...someday I'll realize how stupid i am, until then i keep hitting compile haha!-alex

alexerosa at 2007-7-29 14:15:37 > top of Java-index,Java Essentials,New To Java...
# 10

No problem! Glad I could help.

@ other posters:

</stupidity>

<save_face_attempt>

You guys are right, sorry for the brain-****. I was thinking C...

</save_face_attempt>

by the way, what programs are you using to code in? I'd say get an IDE like NetBeans or Eclipse if you don't have one already.

Message was edited by:

PatrickFinnigan

Message was edited by:

PatrickFinnigan

PatrickFinnigana at 2007-7-29 14:15:37 > top of Java-index,Java Essentials,New To Java...