Win a copy of Zero to AI - A non-technical, hype-free guide to prospering in the AI era this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Help with error in running program

 
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).]
 
Sheriff
Posts: 9099
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
 
Enjoy the full beauty of the english language. Embedded in this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic