Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help with error in running program

 
Dianne Calhoun
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is what I'm doing for this assignment:
Create a class called Rational for performing arithmetic
with factions. Write a driver program to test your class.
Use integer variables to represent the private instance variables
of the class, numerator and denominator. These instance variables
are not changed by any of the methods other than the constructor
method. (Immutable object)
The following methods are part of the class.
/** Constructor that initialized values of rational number */
public Rational(int numerator, int denominator);
/** Add other rational number and this rational number
* and return new Rational number. Do not change this rational
* number.
*/
public Rational add(Rational other);
/** Substract other rational number from this rational number
* and return new Rational number. Do not change this rational
* number.
*/
public Rational subtract(Rational other);
/** Print numerator = ... denominator = ... for this rational
* number.
*/
public void print();
/** Print rational number = xx.xx */
public void printfloat();
------------------------
The test class will be of form:
public class TestRational {
// main
public static void main(String[] args) {
// create and test Rational objects here
}
}
______________________________End of instructions
--------------------------------------------------------------------
Here are my programs
End of Rational.java
End Test Rational.java
They both compile, but when I run the TestRational.java it gives me the following error, and I'm wondering if anyone can help explain what it is. This is only my fourth java program I've written, so I'm really new to Java, and to programming. Any help will be appreciated.
C:\myjava\assignment2\problem1>java TestRational.java
Exception in thread "main" java.lang.NoClassDefFoundError: TestRational/java
------------------

[This message has been edited by Dianne Calhoun (edited September 30, 2001).]
 
Marilyn de Queiroz
Sheriff
Posts: 9063
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They both compile, but when I run the TestRational.java, it gives
me the following error, ....

C:\myjava\assignment2\problem1>java TestRational.java
Exception in thread "main" java.lang.NoClassDefFoundError:
TestRational/java


Rather than

C:\myjava\assignment2\problem1>java TestRational.java

try

C:\myjava\assignment2\problem1>java TestRational
 
Dianne Calhoun
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, I knew that I just had a momentary lapse of memory. Comes from being frustrated working on these programs all weekend. Sometimes it just takes someone else looking.
------------------
Thanks, Dianne
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic