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: WHAT IS WRONG??!?!? unknown error

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

    Default WHAT IS WRONG??!?!? unknown error

    so.... here is a molar mass calculator... it only needs to find the molar mass with C,H,N,O. please help
    import java.util.Scanner;
    /**
    * Cookin' some chicken.
    *
    * @
    * @1.1
    */

    public class FormulaMass
    {
    final static double Carbon = 12.0107;
    final static double Oxygen = 15.9994;
    final static double Nitrogen = 14.0067;
    final static double Hydrogen = 1.00794;
    String formula;
    String [] formarray;
    double Product;
    int x;
    int y;
    int numletters;
    int q;
    int e;
    int f;
    double g;


    public FormulaMass()
    {
    getInput();
    arrayConstructor();
    calculations();
    output();

    }
    public void getInput()
    {
    Scanner in = new Scanner (System.in);
    System.out.println("Enter the formula of your carbon, oxygen,nitrogen or hydrogen compound: ");
    formula = in.next();
    }
    private String arrayConstructor()
    {
    for (x=0; x< formula.length(); x++)
    {
    numletters++;
    }
    String [] subscript = new String[numletters];
    formarray = subscript;
    return formarray[numletters];
    }
    private double calculations()
    {
    for (x =0; x<=formula.length(); x++)
    {
    if (formarray[x].equals ("C"))
    {
    q = Integer.parseInt(formarray[x+1]);
    Product = Product + (q * Carbon);
    }
    if (formarray[x].equals ("N"))
    {
    q = Integer.parseInt(formarray[x+1]);
    Product = Product + (q * Nitrogen);
    }
    if (formarray[x].equals ("H"))
    {
    q = Integer.parseInt(formarray[x+1]);
    Product = Product + (q * Hydrogen);
    }
    if (formarray[x].equals ("O"))
    {
    q = Integer.parseInt(formarray[x+1]);
    Product = Product + (q * Oxygen);
    }
    else
    {
    e = Integer.parseInt(formarray[x]);
    f = Integer.parseInt(formarray[x-1]);
    if (formarray[x+2].equals ("C"))
    {
    g = Carbon;
    }
    if (formarray[x+2].equals ("N"))
    {
    g = Nitrogen;
    }
    if (formarray[x+2].equals ("H"))
    {
    g = Hydrogen;
    }
    if (formarray[x+2].equals ("O"))
    {
    g = Oxygen;
    }
    else
    {
    g = 0;
    }
    f = (f * 10) - f;
    Product = Product + (e * g) + (g * f);
    }
    }
    return Product;
    }
    public void output ()
    {
    System.out.println(Product);
    }
    }


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

    Default Re: WHAT IS WRONG??!?!? unknown error

    ?!?!?! anything?

  3. #3
    Forum VIP
    Join Date
    Jun 2011
    Posts
    317
    My Mood
    Bored
    Thanks
    47
    Thanked 89 Times in 74 Posts
    Blog Entries
    4

    Default Re: WHAT IS WRONG??!?!? unknown error

    Please use the HIGHLIGHT tags to make it easier for us to read your code. Also, please be specific about what you are having problems with.

    From what I can see; you are asking for the input but not using it. Try returning a value in the getInput() method. Also, where is the entry point to the program? I cannot see a main function.

Similar Threads

  1. My code has error when its run....I dont understand what's wrong of it.
    By jacky@~ in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 11th, 2011, 07:48 AM
  2. [Compile Error] Whats wrong with that ?
    By Anomis in forum What's Wrong With My Code?
    Replies: 1
    Last Post: June 5th, 2011, 11:01 AM
  3. What's wrong. Compile Ok but error when execute.
    By hantuapi in forum What's Wrong With My Code?
    Replies: 7
    Last Post: April 1st, 2011, 05:33 AM
  4. [SOLVED] Picture won't go with the .jar (Wrong code or compile error?)
    By Fermen in forum Object Oriented Programming
    Replies: 3
    Last Post: March 15th, 2011, 05:22 PM
  5. [SOLVED] Unknown Character
    By aussiemcgr in forum Java Theory & Questions
    Replies: 19
    Last Post: September 1st, 2010, 05:22 PM