Created
June 30, 2015 17:41
-
-
Save calindotgabriel/ea10e0587409cd56a2ce to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package tree; | |
import domain.ChildrenOccupiedException; | |
import domain.Controller; | |
import domain.model.Dog; | |
import java.util.Scanner; | |
/** | |
* Created by motan on 29.06.2015. | |
*/ | |
public class Console { | |
private Controller controller; | |
private Scanner scanner; | |
public Console() { | |
controller = new Controller(); | |
} | |
public void runUI() { | |
scanner = new Scanner(System.in); | |
System.out.println("Enter ancestor name:"); | |
String ancestorName = scanner.nextLine(); | |
System.out.println("Enter ancestor breed:"); | |
String ancestorBred = scanner.nextLine(); | |
controller.saveAncestor(ancestorName, ancestorBred); | |
while (true) { | |
try { | |
System.out.println("Enter command:\n" + | |
"0) Add sub specie.\n" + | |
"1) List all species.\n" + | |
"2) Check if specie exists.\n" + | |
"Type 'exit' if done"); | |
String cmd = scanner.nextLine(); | |
if (cmd.equals("exit")) break; | |
if (cmd.equals("0")) addSubSpecie(); | |
if (cmd.equals("1")) listSpecies(); | |
if (cmd.equals("2")) checkSpecie(); | |
} catch (ChildrenOccupiedException e) { | |
System.out.println("Already added 2 children."); | |
} | |
} | |
} | |
private void checkSpecie() { | |
System.out.println("Enter specie name:"); | |
String name = scanner.nextLine(); | |
if (controller.exists(name)) { | |
System.out.println("Found " + name + " in tree."); | |
} else { | |
System.out.println("Could not find " + name + " in tree."); | |
} | |
} | |
private void addSubSpecie() { | |
System.out.println("Enter parent specie name:"); | |
String parentName = scanner.nextLine(); | |
if (controller.exists(parentName)) { | |
System.out.println("Enter dog name:"); | |
String childName = scanner.nextLine(); | |
System.out.println("Enter dog breed:"); | |
String childBreed = scanner.nextLine(); | |
controller.saveChild(parentName, childName, childBreed); | |
} else { | |
System.out.println("Found no parent with name : " + parentName); | |
} | |
} | |
private void listSpecies() { | |
controller.listSpecies(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment