Hello Java NG,
I not sure if this is the right NG for this type of question but if not
please let me know which is, TIA
Any way first off let me say I'm a student and this WAS last weeks lab,
turned in, graded and passed so I'm not trying to get someone to do my lab
assignments, but after I got this back I was reading about the DecimalFormat
and I tried to format my output but I keep getting an error message. can
anyone please tell me what I'm doing wrong
Thanks Jim
Error Message=========================================== ======
C:\Lab3\Variables.java:47: non-static variable Fmt cannot be referenced from
a static context
System.out.println( NumInFeet +" is converted to " +
Fmt.format(NumInMeters) + " Meters" );
^
1 error
Tool completed with exit code 1
End Error Message=========================================== ==
Below is the code
import java.io.*; // needed for BufferedReader, InputStreamReader, etc.
import java.text.DecimalFormat; // needed for the DecimalFormat method
//Part A
************************************************** **************************
***
public class Variables
{
//Declare a new instance of DecimalFormat
public DecimalFormat Fmt = new DecimalFormat("0.###");
// Create a BufferedReader for keyboard input
private static BufferedReader stdin =
new BufferedReader( new InputStreamReader( System.in ) );
public static void main ( String [] args ) throws IOException
{
//Declare variables, note the use of doubles here and float in
part B
int NumInFeet;
double NumInMeters;
final double FEETTOMETERS = 0.3048;
// Prompt the user
System.out.print( "Enter a measurement in feet to convert to
meters: " );
// Read a line of text from the user.
String input = stdin.readLine();
//convert the input to integer value
NumInFeet = Integer.parseInt( input ); // converts a String
into an int value
//perform the math comversion on the user input
NumInMeters = NumInFeet * FEETTOMETERS;
// Display the answer back to the user.
System.out.println( NumInFeet +" is converted to " +
Fmt.format(NumInMeters) + " Meters" );
}
}