Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

help please  RSS feed

 
Daniel valdez
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
im taking a class and this is the question (((Write a program that prompts the user to enter the mass of a person in kilograms and outputs the equivalent weight in pounds. Output both the mass and the weight rounded to two decimal places. (Note that for standard Earth gravity, 1 kilogram = 2.2 pounds.) Format your output with two decimal places.
)))


this is what i wrote but get like 10 erros can someone hep me out ?


importjava.util.Scanner; // Scanner is in java.util

PublicClassMassConversionTool
{
publicstaticvoidmain(String args[]
)
{
System.out.println("")
;
doublenumber_of_kilograms;

Scanner keyboard = newScanner(System.in);

System.out.println(" ");

number_of_kilograms = keyboard.nextDouble();

doublenumber.of.pounds;

number_of_pounds = number_of_kilograms * 2.204;

System.out.println
(number_of_kilograms + " kilograms = "+
number_of_pounds + " pounds");

}//end method main(String[])
}//end class MassConversionTool))



these are the errors




----jGRASP exec: javac -g publicclassMassConversionTool.java
publicclassMassConversionTool.java:6: error: class, interface, or enum expected
importjava.util.Scanner; // Scanner is in java.util
^
publicclassMassConversionTool.java:8: error: class, interface, or enum expected
PublicClassMassConversionTool
^
publicclassMassConversionTool.java:15: error: class, interface, or enum expected
doublenumber_of_kilograms;
^
publicclassMassConversionTool.java:17: error: class, interface, or enum expected
Scanner keyboard = newScanner(System.in);
^
publicclassMassConversionTool.java:19: error: class, interface, or enum expected
System.out.println(" ");
^
publicclassMassConversionTool.java:21: error: class, interface, or enum expected
number_of_kilograms = keyboard.nextDouble();
^
publicclassMassConversionTool.java:23: error: class, interface, or enum expected
doublenumber.of.pounds;
^
publicclassMassConversionTool.java:25: error: class, interface, or enum expected
number_of_pounds = number_of_kilograms * 2.204;
^
publicclassMassConversionTool.java:27: error: class, interface, or enum expected
System.out.println
^
publicclassMassConversionTool.java:31: error: class, interface, or enum expected
}//end method main(St



please help


 
fred rosenberger
lowercase baba
Bartender
Posts: 12542
48
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The first thing you need to do is format this code better. Use proper indentation. Follow coding idioms. For example, the close-paren you have on the line by itself is just wrong. Nobody would ever do that in real production code. also, what is "publicstaticvoidmain"? Is your space key broken, or do you not realize that should be

public static void main

Those are four words that NEED to be separate.

What you really need to do is write less code before you compile. You should have gotten no further than about this far before you compile the first time:



Once you get this much to compile and run, then add the SMALLEST piece you can to it...Maybe add in the import line (and JUST the import line). Make sure that compiles. If not, then you know the problem is on that one line. Yes, you won't see any difference when you run it (assuming it works), but at least you know nothing has gone horribly wrong.

Then once that's all done and working, add another line or two. I guarantee you that no matter how often you recompile and test, you will not be doing it enough.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!