package class10_1_ClothingList; // MSOE. Dr. Yoder. 01 November 2015. import com.sun.xml.internal.bind.v2.schemagen.xmlschema.NestedParticle; import java.util.Random; import java.util.Scanner; public class ClothesChooser { private ClothingList shirts; private ClothingList pants; private Clothing currentShirt; private Clothing currentPants; private Scanner in; private Random generator; public static void main(String[] args) { ClothesChooser chooser = new ClothesChooser(); chooser.run(); } public void run() { createWardrobe(); in = new Scanner(System.in); generator = new Random(); int choice = 1; System.out.println("Welcomd to the clothing chooser!"); while(choice != 0) { choice = getUserChoice(); if(choice == 1) { pickRandomSelection(); } else if(choice ==2) { enterASelectionManually(); } else if(choice == 3) { checkCurrentSelection(); } else if(choice == 4) { addArticle("pant"); } else if (choice == 0) { /* will exit. Do nothing */ } else { System.out.println("Warning: Unexpected option: "+choice); } } } /** * Prompt the user for info needed to * create a new article of clothing. * @param type */ private void addArticle(String type) { Color color = new Color(); int styleLevel; System.out.println("Please enter the information for "); System.out.println("Your new "+type); System.out.println("Enter the name of the color" + " and the type number" + "(separated by whitespace):"); String colorName = in.next(); styleLevel = in.nextInt(); Clothing article = new Clothing(type,color,styleLevel); System.out.println("nEW CLOHTES: "+ article); ClothingList list; if(type.equals("shirt")) { list = shirts; } else { list = pants; } // TODO: How to put this in the array list? // (EXERCISE) } private int getUserChoice() { int choice; System.out.println(); System.out.println("Options:"); System.out.println("1: Pick a random Selection"); System.out.println("2: Enter a selection manually"); System.out.println("3: Check if current selection matches"); System.out.println("0: Exit"); System.out.println("(There are "+ Clothing.getNumArticles()+" total articles of clothing)"); System.out.println(); System.out.print("Please enter an option: "); choice = in.nextInt(); return choice; } private void checkCurrentSelection() { if(currentShirt.isMatchTo(currentPants)) { System.out.println("The current selection matches."); } else { System.out.println("The current selection doesn't match"); } } private void createWardrobe() { pants = new ClothingList("pant"); pants.add(new Clothing("pant", new Color(), Style.PLAIN)); pants.add(new Clothing("pant", new Color(), Style.FANCY)); pants.add(new Clothing("pant", new Color(), Style.WORK)); shirts = new ClothingList("shirt"); shirts.add(new Clothing("shirt", new Color(), Style.PLAIN)); shirts.add(new Clothing("shirt", new Color(), Style.FANCY)); shirts.add(new Clothing("shirt", new Color(), Style.WORK)); currentShirt = shirts.pick(1); currentPants = pants.pick(1); } private void enterASelectionManually() { shirts.listClothing(); System.out.println("Enter the number of the shirt that you want."); int selectedShirt = in.nextInt(); currentShirt = shirts.pick(selectedShirt); pants.listClothing(); System.out.println("Enter the number of the pants that you want."); int selectedPants = in.nextInt(); currentPants = pants.pick(selectedPants); displayCurrentSelection(); } private void displayCurrentSelection() { System.out.println("Current shirt: "+currentShirt); System.out.println("Current pants: "+currentPants); } private void pickRandomSelection() { currentShirt = shirts.pick(generator.nextInt(shirts.numClothes())+1); currentPants = pants.pick(generator.nextInt(pants.numClothes())+1); displayCurrentSelection(); } }