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);
}
}
Re: WHAT IS WRONG??!?!? unknown error
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.