/* * Intro to Programming CSE 1310 * University of Texas at Arlington */ package code27feb2018; import java.util.Scanner; import java.util.logging.Level; import java.util.logging.Logger; /** * * @author jcmtiernan */ public class Code27Feb2018 { /** * @param args the command line arguments */ /** * This program is going to find out what type of media you prefer * for your entertainment. It is going to ask a series of questions and * get answers to try to determine your preferences. * @param args the command line arguments */ public static void main(String[] args) { // methods // try-catch exception handling // control statements // file input Scanner input = new Scanner(System.in); Logger.getGlobal().setLevel(Level.INFO);// Use Level.OFF to turn off int choice; String mobOrStat; boolean moveForward = false; char iOrO; do { System.out.println("Hi! What kind of entertainment media do you prefer? "); System.out.println("M - mobile or S - stationary "); mobOrStat = input.next(); // reads a "word" input.nextLine(); // reads end of line marker out of input buffer // Validate the user's input to insure that only one of the // following values are entered: // M, m, mobile or // S, s, stationary if (mobOrStat.equalsIgnoreCase("m") || mobOrStat.equalsIgnoreCase("mobile") || mobOrStat.equalsIgnoreCase("s") || mobOrStat.equalsIgnoreCase("stationary") ) { moveForward = true; } else { System.out.println("Your input was not recognized."); System.out.println("Please enter a valid input."); } } while (!moveForward); // !moveForward is the same as moveForward == false // alternate selection mobOrStat = mobOrStat.toUpperCase(); switch (mobOrStat) { case "S": case "STATIONARY": mobOrStat = "STATIONARY"; break; case "M": case "MOBILE": mobOrStat = "MOBILE"; break; } System.out.println("You entered "+mobOrStat+" as your first entertainment preference\n"); String inOrOut = ""; if (mobOrStat.equalsIgnoreCase("STATIONARY")) { // query user for home (TV, desktop computer) or not (movie theater, live theatre, RPG) System.out.println("Is the entertainment media in your home or outside your home?"); System.out.println("Respond with I (inside) or O (outside): "); inOrOut = input.nextLine(); Logger.getGlobal().info("User entered *"+inOrOut+"*"); iOrO = inOrOut.charAt(0); Logger.getGlobal().info("First letter of user input is *"+iOrO+"*"); if ((iOrO == 'I') || (iOrO == 'i')) { inOrOut = "INSIDE"; } else if ((iOrO == 'O') || (iOrO == 'o')) { inOrOut = "OUTSIDE"; } else // user entered invalid input { // could have set up a do-while loop like above but didn't System.out.println("You entered an invalid input."); System.out.println("The system assumes you are a mushroom and your media in INSIDE."); inOrOut = "INSIDE"; } String finalMedia; // Given INSIDE or OUTSIDE // find user's preferred type of media // INSIDE choices are: Desktop computer, TV, Gaming system, VR // OUTSIDE choices are: Movie theater, Theatre, RPG, ComicCon // Making a method to // show choices if (inOrOut.equals("INSIDE")) { finalMedia = chooseMedia("Desktop computer", "TV", "Gaming system", "VR"); } else { finalMedia = chooseMedia("Movie theater", "Theatre", "ComicCon", "RPG"); } System.out.println("Final choice is "+finalMedia); /* System.out.println("Please select your favorite media from this list:"); System.out.println("1. "+firstChoice); // firstChoice is string System.out.println("2. "+secondChoice); System.out.println("3. "+thirdChoice); System.out.println("4. "+fourthChoice); System.out.println("Enter the number of your choice: "); intChoice = input.nextInt(); String finalChoice; switch (intChoice) { case 1: finalChoice = firstChoice; break; case 2: finalChoice = secondChoice; break; case 3: finalChoice = thirdChoice; break; case 4: finalChoice = fourthChoice; break; } */ // let user select // return selected choice } else // must be MOBILE { // query user for phone, laptop, VR system, ...) } /* if (testVar < 100) { int testVar2 = 9; System.out.println("If testVar2 = "+testVar2); } System.out.println("After if testVar2 = "+testVar2); while(testVar < 20) { int testVar2 = 4; System.out.println("While testVar2 = "+testVar2+ " and testVar = "+testVar); testVar++; } */ } public static String chooseMedia(String firstChoice, String secondChoice, String thirdChoice, String fourthChoice) { Scanner input = new Scanner(System.in); System.out.println("Please select your favorite media from this list:"); System.out.println("1. "+firstChoice); // firstChoice is string System.out.println("2. "+secondChoice); System.out.println("3. "+thirdChoice); System.out.println("4. "+fourthChoice); System.out.println("Enter the number of your choice: "); int intChoice = input.nextInt(); String finalChoice; switch (intChoice) { case 1: finalChoice = firstChoice; break; case 2: finalChoice = secondChoice; break; case 3: finalChoice = thirdChoice; break; case 4: finalChoice = fourthChoice; break; default: finalChoice = "kazoo"; break; } return finalChoice; } }