Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using jsfiddle.net. Please include html and javascript In programming you are of

ID: 3577079 • Letter: U

Question

Using jsfiddle.net.

Please include html and javascript

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://en.wikipedia.org/wiki/Caffeine )

Assignment

So you will get to have a little fun with this assignment. You will 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

While executing the code keep the fiule in appropraiet path or right click on the file and choose path name change it in the line 6 of the program one.

public class CafMolecular {

    public static void main(String[] args) {

        ST<String, Double> st = new ST<String, Double>();

        In in = new In("c:\desktop\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);
        }

     
        while (StdIn.hasNextLine()) {
            double total = 0.0;
            String line = StdIn.readLine();
            String[] fields = line.split("\.");
            for (int i = 0; i < fields.length; i++) {

             
                int j;
                for (j = 0; j < fields[i].length(); j++) {
                    if (Character.isDigit(fields[i].charAt(j))) break;
                }
                String symbol = fields[i].substring(0, j);
                double weight = st.get(symbol);

               String atoms = fields[i].substring(j, fields[i].length());
                if (atoms.length() == 0) total += weight;
                else                     total += Integer.parseInt(atoms) * weight;
            }


            System.out.printf("Molecular weight of %s = %f ", line, total);
        }


    }
}


import java.util.Scanner;
import java.util.Locale;
import java.io.BufferedInputStream;

public final class StdIn {

    private static String charsetName = "UTF-8";

    private static Locale usLocale = new Locale("en", "US");
    private static Scanner scanner = new Scanner(new BufferedInputStream(System.in), charsetName);

    static { scanner.useLocale(usLocale); }


    private StdIn() { }

    public static boolean isEmpty() {
   return !scanner.hasNext();
    }

      public static String readString() {
        return scanner.next();
    }

       public static int readInt() {
        return scanner.nextInt();
    }

        public static double readDouble() {
        return scanner.nextDouble();
    }

    public static float readFloat() {
   return scanner.nextFloat();
    }

    public static short readShort() {
   return scanner.nextShort();
    }
    public static long readLong() {
        return scanner.nextLong();
    }

    public static byte readByte() {
        return scanner.nextByte();
    }

      public static boolean readBoolean() {
        String s = readString();
        if (s.equalsIgnoreCase("true")) return true;
        if (s.equalsIgnoreCase("false")) return false;
        if (s.equals("1"))               return true;
        if (s.equals("0"))               return false;
        throw new java.util.InputMismatchException();
    }

     public static boolean hasNextLine() {
        return scanner.hasNextLine();
    }
    public static String readLine() {
        return scanner.nextLine();
    }
    public static char readChar() {
        String s = scanner.findWithinHorizon("(?s).", 1);
        return s.charAt(0);
    }

      public static String readAll() {
        if (!scanner.hasNextLine()) return null;

           return scanner.useDelimiter("\A").next();
    }

    public static void main(String[] args) {

        System.out.println("Type a string: ");
        String s = StdIn.readString();
        System.out.println("Your string was: " + s);
        System.out.println();

        System.out.println("Type an int: ");
        int a = StdIn.readInt();
        System.out.println("Your int was: " + a);
        System.out.println();

        System.out.println("Type a boolean: ");
        boolean b = StdIn.readBoolean();
        System.out.println("Your boolean was: " + b);
        System.out.println();

        System.out.println("Type a double: ");
        double c = StdIn.readDouble();
        System.out.println("Your double was: " + c);
        System.out.println();

    }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote