# Help with error in running program

Dianne Calhoun

Greenhorn

Posts: 29

posted 14 years ago

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).]

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).]

Thanks, Dianne

Marilyn de Queiroz

Sheriff

Posts: 9066

12

posted 14 years ago

Rather than

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

try

C:\myjava\assignment2\problem1>java TestRational

They both compile, but when I run theTestRational.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

JavaBeginnersFaq

"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt