Question: Please use the Java Classes Below to complete this assignment: package org.assignment 2 ; public class FormulaCalc { public static void main ( String [
Please use the Java Classes Below to complete this assignment:
package org.assignment;
public class FormulaCalc
public static void mainString args
Algorithm
@param a Molecular formula
@return Total number of protons
public static int AlgorithmString a
Once you are dealing character by character, you can set a multiple if statement to check if that character is a capital letter, a small case letter, a number, or a parenthesis.
For each of these options, you need to perform a decision.
If is a capital letter
if the stack is not empty
pop :
add it to cumulative sum
request the string value and add it to stack.
else if is a lowercase letter
pop stack to clear it
grab the prior letter and request the string value and add it to stack
else if it is a number
pop :
multiply times the number
add it to a cumulative sum
else if parenthesis
return ;
private static int getElementProtonsString c
switch c
case H: return ;
case He: return ;
case Li: return ;
case Be: return ;
case B: return ;
case C: return ;
case N: return ;
case O: return ;
case F: return ;
case Ne: return ;
case Na: return ;
case Mg: return ;
case Al: return ;
case Si: return ;
case P: return ;
case S: return ;
case Cl: return ;
case K: return ;
case Ar: return ;
case Ca: return ;
case Sc: return ;
case Ti: return ;
case V: return ;
case Cr: return ;
case Mn: return ;
case Fe: return ;
case Ni: return ;
case Co: return ;
case Cu: return ;
case Zn: return ;
case Ga: return ;
case Ge: return ;
case As: return ;
case Se: return ;
case Br: return ;
case Kr: return ;
case Rb: return ;
case Sr: return ;
case Y: return ;
case Zr: return ;
case Nb: return ;
case Mo: return ;
case Tc: return ;
case Ru: return ;
case Rh: return ;
case Pd: return ;
case Ag: return ;
case
import org.junit.jupiter.api.Test;
import org.assignmentFormulaCalc;
import org.junit.jupiter.api.Assertions;
public class FormulaCalcTest
@Test
public void testwithH
Assertions.assertEquals FormulaCalc.AlgorithmH;
@Test
public void testwithKBr
Assertions.assertEquals FormulaCalc.AlgorithmKBr;
The parentheses are replaced with underscores
@Test
public void testwithNaCl
Assertions.assertEquals FormulaCalc.AlgorithmNaCl;
@Test
public void testwithHO
Assertions.assertEquals FormulaCalc.AlgorithmHO;
@Test
public void testwithCHO
Assertions.assertEquals FormulaCalc.AlgorithmCHO;
@Test
public void testwithNiNO
Assertions.assertEquals FormulaCalc.AlgorithmNiNO;
@Test
public void testwithCoFeCN
Assertions.assertEquals FormulaCalc.AlgorithmCoFeCN;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
