Question
Please answer on jsfiddle.net Answer must work in jsfiddle Please show both the HTML and Java sections Assignment 15 Networks last edited by Dr. Ron Eaglin 1 week, 2 days ago Page Assignment 15 Networks Objective Use overall knowledge of data structures to solve problems Introduction In programming you are often confronted with a choice of choosing the correct object, structure, or algorithm to solve a problem. Making the wrong choice often leads to inefficiencies that must be corrected later or a complete inability to solve the problem. This is important enough that there are even guides to technical interviews that help you get ready for these types of questions (see http://careerdrill.com blog!coding- interview/choosing-the-right-data-structure-to-solve-problems). Also common in programming is the use of Caffeine https:llen.wikipedia.org/wikilCaffeine) Assignment So you will get to have a little fun with this assignment. You will w model a caffeine molecule as a graph and present that computer model. Edges that are single bonds should be presented with a weight of 1, with a double bond they should have a weight of 2. Build your model as a Graph. The graph should be able to print all of its Nodes with each adjacent node. You can have a print button or simply call it when the Graph is built. Output H (C) there will be 9 of these C (N,H) there will be 3 of these N (C, C, C) there are 3 of these N (C. C) only one of these etc. etc. for each element and combination of connected element
Explanation / Answer
public class MolecularWeight { public static void main(String[] args) { // symbol table whose key = element symbol and value = molecular weight ST st = new ST(); // read in elements symbols and their atomic weights In in = new In("elements.csv"); while (in.hasNextLine()) { String line = in.readLine(); String[] fields = line.split(","); String symbol = fields[2]; double weight = Double.parseDouble(fields[3]); st.put(symbol, weight); } // read in chemical formulas from stdin, and print out molecular weight while (StdIn.hasNextLine()) { double total = 0.0; String line = StdIn.readLine(); String[] fields = line.split("\."); // period is a special regexp char for (int i = 0; i