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 2 of 2

Thread: I dont know why its giving me this error with eclipse!

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default I dont know why its giving me this error with eclipse!

    import java.util.Scanner;
    /**
       This class converts between two units.
    */
    public class ConversionCalculator
    {
       public static void main(String[] args)
       {
          Scanner in = new Scanner(System.in);
     
          System.out.println("Convert from:");
          String fromUnit = in.nextLine();
          System.out.println("Convert to: ");
          String toUnit = in.nextLine();
     
          UnitConverter from = new UnitConverter(fromUnit);
          UnitConverter to = new UnitConverter(toUnit);
          System.out.println("Value:");
          double val = in.nextDouble();
          double meters = from.toMeters(val);
          double converted = to.fromMeters(meters);
          System.out.println(val + " " + fromUnit + " = " + converted + " " + toUnit);
       }
    }
    public class UnitConverter 
    {
     static double INCHES = 0.0254001;
     static double FEET = 0.3048;
     static double MILES = 1609.35;
     static double MILLIMETERS = 0.001;
     static double CENTIMETERS = 0.01;
     static double METERS = 1;
     static double KILOMETERS = 1000;
     private double val ,meters ,converted;
     String afromUnit;
     
     public UnitConverter(String fromUnit)
     {
      afromUnit = fromUnit;
     }
     
     public double toMeters(double val) 
     {
      if(afromUnit.equals("in"))
      {
       meters = (val*INCHES);
      }
      else if(afromUnit.equals("ft"))
      {
       meters = (val*FEET);
      }
      else if(afromUnit.equals("mi"))
      {
       meters = (val*MILES);
      }
      else if(afromUnit.equals("mm"))
      {
       meters = (val*MILLIMETERS);
      }
      else if(afromUnit.equals("cm"))
      {
       meters = (val*CENTIMETERS);
      }
      else if(afromUnit.equals("m"))
      {
       meters = (val*METERS);
      }
      else
      {
       meters = (val*KILOMETERS);
      }
      return meters;
     }
     
     public double fromMeters(double meters) 
     {
      if(afromUnit.equals("in"))
      {
       converted = Math.round(meters*39.369923740457715);
      }
      else if(afromUnit.equals("ft")) 
      {
       converted = Math.round(meters*3.280839895013123);
      }
      else if(afromUnit.equals("mi"))
      {
       converted = Math.round(meters*0.0006213688756330196);
      }
      else if(afromUnit.equals("mm")) 
      {
       converted = Math.round(meters*1000);
      }
      else if(afromUnit.equals("cm")) 
      {
       converted = Math.round(meters*100);
      }
      else if(afromUnit.equals("m")) 
      {
       converted = Math.round(meters*1);;
      }
      else 
      {
       converted = Math.round(meters*0.001);
      }
      return converted;
     }	
    }
    EzirhD.jpg
    http://3.imgland.net/EzirhD.png <--- Link to picture in high resolution!


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: I dont know why its giving me this error with eclipse!

    There are two public classes in the same file - mark one with a different access modifier or better yet place them in their own files with the class name as the file name.

    For future reference, I'd recommend posting the error message directly to the forums rather than attaching photos. And further, if you are new to java and using an IDE, you might benefit from spending some time using the command line for development. YMMV

Similar Threads

  1. I have an error i dont knwo how to fix.
    By 93tomh in forum What's Wrong With My Code?
    Replies: 5
    Last Post: July 21st, 2012, 05:53 PM
  2. Replies: 7
    Last Post: October 13th, 2011, 03:03 AM
  3. Replies: 4
    Last Post: July 25th, 2011, 06:12 PM
  4. JavaCompilerobject giving an error WITHOUT ide
    By divs1210 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 2nd, 2011, 08:49 PM
  5. i'm getting this error, dont know why? please help
    By amr in forum What's Wrong With My Code?
    Replies: 4
    Last Post: December 17th, 2010, 06:14 AM