As you'll see from my poor excuse for code I'm new to the Java world. I'm taking a class at the local Junior college. I'm getting the fallowing error at runtime:
C:\>java A131TJudd Exception in thread "main" java.lang.NoClassDefFoundError: A131TJudd
And here's my source:
import javax.swing.*;
public class A131TJudd { int fahrsaved = 0; int cel = 0;
public A131TJudd(int fahr) { fahrsaved = fahr; }
public int promptFahr(){ String s = JOptionPane.showInputDialog ("Please enter a Fahrenheight Value:"); fahrsaved = Integer.parseInt(s); return fahrsaved; }
public void convertToCels(){ cel =(int)((5/9)*(fahrsaved-32)); }
public void displayFahrAndCels(){ JOptionPane.showMessageDialog (null, "The Fahrenheit Temp is: " + fahrsaved + "degrees"); JOptionPane.showMessageDialog (null, "The Celsius Temp is: " + cel + "degrees"); }
public void main(String[] args){ A131TJudd test = new A131TJudd(promptFahr()); test.convertToCels(); test.displayFahrAndCels(); System.exit(0); } }
Any help would be apprecated. Mostly just tell me how my bass ackward code can be fixed. Thanks.
Well, first of all - you probably need to compile your source e.g.: c:\javac A131TJudd (I do assume that A131TJudd.java is placed in C:\).
Then you can run the compiled A131TJudd.class with c:\java A131TJudd.
But first... there are some small errors in your source: The main method needs to be static. (And you can not use a non-static method (promptFahr) inside a static method - you are calling a method on an instance you are about to create...) And you got a rounding error in convertToCels (5/9) equals 0.
regards -en --- import javax.swing.*;
public class A131TJudd { private int fahrsaved; private int cel;
public A131TJudd() { }
public void promptFahr() { String s = JOptionPane.showInputDialog("Please enter a Fahrenheight Value:"); this.fahrsaved = Integer.parseInt(s); }