/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package referencelibrary;

/**
 *
 * @author juhapekm
 */
public class UI {
    private IO io;
    
    public void run() {
        io = new ConsoleIO();
        io.print("Reference library");
        printAvailableCommands();
        String command = "q";
        command = io.readLine("\nChoose command: \n");
        while(!command.equals("q")) {
            //call chosen functionality
            switch (command){
                case "a":   addNewReference();
                            break;
                case "g":   generateBixTexFile();
                            break;
            }
            //new command
            printAvailableCommands();
            command = io.readLine("\nChoose command: \n");
        }
        io.print("Ohjelma loppuu..");
    }
    
    public void printAvailableCommands() {
        io.print("(q)uit," + "\n" + "(a)dd new reference," + "\n" + "(g)enerate bibtex" + "\n");
    }
    
    public void addNewReference() {
        io.print("Add new reference");
        //switch: reference type
            //call appropriate adding method
        io.print("--adding not implement");
        
        io.print("Reference added!");
    }
    
    public void generateBixTexFile() {
        io.print("Generating bibTex -file");
        //call bibtex-file generator
        io.print("--generating not implemented");
        
        io.print("Generating done!");
    }
}

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package referencelibrary;

import java.util.HashMap;

/**
 *
 * @author juhapekm
 */
public class UI {
    private IO io;
    
    public void run() {
        io = new ConsoleIO();
        io.print("Reference library");
        printAvailableCommands();
        String command = "q";
        command = io.readLine("\nChoose command: \n");
        while(!command.equals("q")) {
            //call chosen functionality
            switch (command){
                case "a":   addNewReference();
                            break;
                case "g":   generateBixTexFile();
                            break;
            }
            //new command
            printAvailableCommands();
            command = io.readLine("\nChoose command: \n");
        }
        io.print("Ohjelma loppuu..");
    }
    
    public void printAvailableCommands() {
        io.print("(q)uit," + "\n" + "(a)dd new reference," + "\n" + "(g)enerate bibtex" + "\n");
    }
    
    public void addNewReference() {
        io.print("Add new reference");
        
        //promt reference type
        String command = io.readLine("\nChoose reference type: \n");
        io.print("(B)ook, \n(O)ther\n");
        
        //switch (reference type)
        switch(command){
            case "B":   //Call addBook
                        io.print("--adding not implement");
                        //io.print("Reference added!");
                        break;
            case "O":   io.print("--adding not implement");
                        //io.print("Reference added!");
                        break;
        } 
    }
    
    public void addNewBook() {
        String referenceType = "Book";
        String referenceName = io.readLine("Reference id");
        String author = io.readLine("Author: ");
        String title = io.readLine("Title: ");
        String year = io.readLine("Year: ");
        String publisher = io.readLine("Publisher: ");
        HashMap<String, String> newRefHash = new HashMap<String, String>();
        newRefHash.put("author", author);
        newRefHash.put("title", title);
        newRefHash.put("year", year);
        newRefHash.put("publisher", publisher);
        //Reference newRef = new Reference();
    }
    
    public void generateBixTexFile() {
        io.print("Generating bibTex -file");
        //call bibtex-file generator
        io.print("--generating not implemented");
        
        io.print("Generating done!");
    }
}

add 'add book'-functionality to UI