Commit 5ed72847 authored by Caelan Reese Wong's avatar Caelan Reese Wong
Browse files

Created skeleton Molecule Class that reads a text file

parent 2ba90282
Loading
Loading
Loading
Loading

example.txt

0 → 100644
+1 −0
Original line number Diff line number Diff line
Hello World!
 No newline at end of file
+10 −0
Original line number Diff line number Diff line
package edu.bu.ec504.project;

public class Main {
    public static void main(String[] args) {
        final String filename="example.txt";
        Molecule tester = new Molecule(filename);
    }


}
+40 −0
Original line number Diff line number Diff line
package edu.bu.ec504.project;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;

public class Molecule {

    // TODO:save the molecule information

    // TODO:read the text file (adjacency list), line by line
    //Current implementation is in the constructor

    public Molecule(String MoleculeFile){
        // Read and process input
        try (BufferedReader reader = new BufferedReader(new FileReader(MoleculeFile))) {
            String line;
            while ((line = reader.readLine()) != null) {
                System.out.println(line); // TODO: we can change this to parse the file rather than print it
            }
        } catch (IOException e) {
            System.err.println("Error reading the file: " + e.getMessage());
        }
    }


    // TODO: add molecule to the database


    //FIELDS

    /**
     * saves element as the key and the quantity as the value
     */

    HashMap <Character ,Integer>map = new HashMap<>();

}