Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: modular programming, converting to degrees

  1. #1
    Member
    Join Date
    Mar 2011
    Posts
    66
    My Mood
    Relaxed
    Thanks
    12
    Thanked 4 Times in 4 Posts

    Default modular programming, converting to degrees

    Hi everyone, I've been given an assignment for practice and it has to do with calculating the sine again but this time I have to use modular programming. I already have a working inlined program, so I'm pretty sure I'll be able to do it.

    Apparently when I tried to convert degrees to radians using a subroutine, I get an error when I run it.

    Original Code
    import java.io.*;
     
    public class HW6X
    {
     
    public static void main(String args[]) throws IOException
    {
    BufferedReader keybd = new BufferedReader(new InputStreamReader(System.in));
     
    double x;
    int maxe;
     
    System.out.println("Enter a value in degrees: ");
    x = Double.parseDouble(keybd.readLine());
     
    System.out.println(convert(x));
     
    }
     
    public static double convert(double x)
    {
            x = x * Math.PI / 180;
            return x;
    }
    }

    Error:
    Exception in thread "main" java.lang.NoClassDefFoundError: HW6X/java
    Caused by: java.lang.ClassNotFoundException: HW6X.java
            at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
            at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    Could not find the main class: HW6X.java.  Program will exit.

    I tried googling this problem and others have said that it has to do with the classpath. I'm not sure what they meant by this, if it's the reason for the error. I think if I find out why this doesn't work, then I'll be able to do the rest of the program without any problem.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: modular programming, converting to degrees

    Did you google classpath? Do you know what it is?

    Recommended reading: http://download.oracle.com/javase/tu...ems/index.html
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. The Following User Says Thank You to KevinWorkman For This Useful Post:

    Actinistia (April 13th, 2011)

  4. #3
    Member
    Join Date
    Mar 2011
    Posts
    66
    My Mood
    Relaxed
    Thanks
    12
    Thanked 4 Times in 4 Posts

    Default Re: modular programming, converting to degrees

    Quote Originally Posted by KevinWorkman View Post
    Did you google classpath? Do you know what it is?

    Recommended reading: http://download.oracle.com/javase/tu...ems/index.html
    WOW, major face palm! I just realized that I made a HUGE mistake and I think I tried to run the program with .java at the end instead of the file name. Thank you for the recommended reading, it helped me learn about classpath and how important it is! Sorry for wasting your time, I can't believe that I did such a beginner mistake (although I am a beginner).

Similar Threads

  1. degrees?
    By rbread80 in forum Java Theory & Questions
    Replies: 2
    Last Post: December 8th, 2010, 09:09 PM
  2. help w/ conversion of degrees(CtoF, FtoC)
    By robertsbd in forum What's Wrong With My Code?
    Replies: 12
    Last Post: November 8th, 2010, 01:38 PM
  3. Converting Cases Help
    By Bradshjo in forum What's Wrong With My Code?
    Replies: 6
    Last Post: September 27th, 2010, 12:07 PM
  4. Magic square class (modular math problem)
    By mjpam in forum What's Wrong With My Code?
    Replies: 1
    Last Post: June 30th, 2010, 10:56 AM
  5. Replies: 4
    Last Post: May 1st, 2009, 03:32 PM