The Artima Developer Community
Sponsored Link

Java Answers Forum
Simple Assingment Help

3 replies on 1 page. Most recent reply: Feb 18, 2003 7:51 AM by Taylor

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
Taylor

Posts: 2
Nickname: grayrace
Registered: Feb, 2003

Simple Assingment Help Posted: Feb 17, 2003 11:57 PM
Reply to this message Reply
Advertisement
Hi all,

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.


E. Nielsen

Posts: 9
Nickname: en
Registered: Feb, 2003

Re: Simple Assingment Help Posted: Feb 18, 2003 3:31 AM
Reply to this message Reply
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);
}

public void convertToCels() {
this.cel = (int) ((5 * (this.fahrsaved - 32)) / 9);
}

public void displayFahrAndCels() {
JOptionPane.showMessageDialog(
null,
"The Fahrenheit Temp is: " + this.fahrsaved + " degrees");
JOptionPane.showMessageDialog(
null,
"The Celsius Temp is: " + this.cel + " degrees");
}

public static void main(String[] args) {
A131TJudd test = new A131TJudd();
test.promptFahr();
test.convertToCels();
test.displayFahrAndCels();
System.exit(0);
}
}
---

E. Nielsen

Posts: 9
Nickname: en
Registered: Feb, 2003

Re: Simple Assingment Help Posted: Feb 18, 2003 3:35 AM
Reply to this message Reply
Hmmm...

Also make sure that . (current directory) is in your classpath.

-en

Taylor

Posts: 2
Nickname: grayrace
Registered: Feb, 2003

Re: Simple Assingment Help Posted: Feb 18, 2003 7:51 AM
Reply to this message Reply
Thanks Neilsen, I was able to figure it out based on your advice.

Taylor

Flat View: This topic has 3 replies on 1 page
Topic: cannot connect file dialog Previous Topic   Next Topic Topic: Error executing J2EE server ...

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use