I'm making a program that find sums multiple values that are in a single string. For example you put H2O in and it will return the molar mass value for that chemical (2*H + O). So I copied the periodic table and listed the values e.g "private double H = 1.008;". So the problem is I need to get that value based on the name of the variable. Here is an example.
private double H = 1.008;
System.out.println(multMass(2, H));
// should print 2.016
public static double multMass(int multiplier, String chem){
return double(chem) * multiplier;
} /\
||
where the double would go(in this case 'double H')