Created
September 4, 2016 08:17
-
-
Save polinabee/a2851b19fa2efdb36810b3c47d84c247 to your computer and use it in GitHub Desktop.
CS111B Assignment 3: Number Guesser
This file contains 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
<?xml version="1.0" encoding="UTF-8"?> | |
<project version="4"> | |
<component name="CompilerConfiguration"> | |
<resourceExtensions /> | |
<wildcardResourcePatterns> | |
<entry name="!?*.java" /> | |
<entry name="!?*.form" /> | |
<entry name="!?*.class" /> | |
<entry name="!?*.groovy" /> | |
<entry name="!?*.scala" /> | |
<entry name="!?*.flex" /> | |
<entry name="!?*.kt" /> | |
<entry name="!?*.clj" /> | |
<entry name="!?*.aj" /> | |
</wildcardResourcePatterns> | |
<annotationProcessing> | |
<profile default="true" name="Default" enabled="false"> | |
<processorPath useClasspath="true" /> | |
</profile> | |
</annotationProcessing> | |
</component> | |
</project> |
This file contains 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
<component name="CopyrightManager"> | |
<settings default="" /> | |
</component> |
This file contains 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
<?xml version="1.0" encoding="UTF-8"?> | |
<project version="4"> | |
<component name="EntryPointsManager"> | |
<entry_points version="2.0" /> | |
</component> | |
<component name="MavenImportPreferences"> | |
<option name="generalSettings"> | |
<MavenGeneralSettings> | |
<option name="mavenHome" value="Bundled (Maven 3)" /> | |
</MavenGeneralSettings> | |
</option> | |
</component> | |
<component name="ProjectLevelVcsManager" settingsEditedManually="false"> | |
<OptionsSetting value="true" id="Add" /> | |
<OptionsSetting value="true" id="Remove" /> | |
<OptionsSetting value="true" id="Checkout" /> | |
<OptionsSetting value="true" id="Update" /> | |
<OptionsSetting value="true" id="Status" /> | |
<OptionsSetting value="true" id="Edit" /> | |
<ConfirmationsSetting value="0" id="Add" /> | |
<ConfirmationsSetting value="0" id="Remove" /> | |
</component> | |
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="IntelliJ IDEA IU-162.1447.26" project-jdk-type="IDEA JDK"> | |
<output url="file://$PROJECT_DIR$/out" /> | |
</component> | |
<component name="masterDetails"> | |
<states> | |
<state key="GlobalLibrariesConfigurable.UI"> | |
<settings> | |
<splitter-proportions> | |
<option name="proportions"> | |
<list> | |
<option value="0.2" /> | |
</list> | |
</option> | |
</splitter-proportions> | |
</settings> | |
</state> | |
<state key="JdkListConfigurable.UI"> | |
<settings> | |
<last-edited>IntelliJ IDEA IU-162.1447.26 (1)</last-edited> | |
<splitter-proportions> | |
<option name="proportions"> | |
<list> | |
<option value="0.2" /> | |
</list> | |
</option> | |
</splitter-proportions> | |
</settings> | |
</state> | |
<state key="ProjectLibrariesConfigurable.UI"> | |
<settings> | |
<splitter-proportions> | |
<option name="proportions"> | |
<list> | |
<option value="0.2" /> | |
</list> | |
</option> | |
</splitter-proportions> | |
</settings> | |
</state> | |
</states> | |
</component> | |
</project> |
This file contains 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
<?xml version="1.0" encoding="UTF-8"?> | |
<project version="4"> | |
<component name="ProjectModuleManager"> | |
<modules> | |
<module fileurl="file://$PROJECT_DIR$/NumberGuesser.iml" filepath="$PROJECT_DIR$/NumberGuesser.iml" /> | |
</modules> | |
</component> | |
</project> |
This file contains 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
<?xml version="1.0" encoding="UTF-8"?> | |
<module type="JAVA_MODULE" version="4"> | |
<component name="NewModuleRootManager" inherit-compiler-output="true"> | |
<exclude-output /> | |
<content url="file://$MODULE_DIR$"> | |
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> | |
</content> | |
<orderEntry type="inheritedJdk" /> | |
<orderEntry type="sourceFolder" forTests="false" /> | |
</component> | |
</module> |
This file contains 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
/** | |
* Created by pberenstein on 9/3/2016. | |
* CCSF Fall 2016 | |
*/ | |
import java.util.Scanner; | |
public class NumberGuesser { | |
public static void main(String[] args) { | |
do{ | |
playOneGame(); | |
} while (shouldPlayAgain()); | |
} | |
static void playOneGame(){ | |
int myGuess; | |
int upLimit = 100; | |
int lowLimit = 1; | |
char response; | |
do{ | |
myGuess = getMidpoint(lowLimit, upLimit); | |
response = getUserResponseToGuess(myGuess); | |
if (response == 'h'){ | |
upLimit = myGuess; | |
} | |
else{ | |
lowLimit = myGuess; | |
} | |
}while(response != 'c'); | |
} | |
public static char getUserResponseToGuess(int guess){ | |
Scanner user_input = new Scanner(System.in); | |
System.out.print("is it "+guess+"? (h/l/c): "); | |
return user_input.next().charAt(0); | |
} | |
public static int getMidpoint(int low, int high){ | |
return((int)Math.floor((low+high)/2)); | |
} | |
static boolean shouldPlayAgain(){ | |
Scanner user_input = new Scanner(System.in); | |
boolean flag = false; | |
System.out.print("Great! Do you want to play again? (y/n): "); | |
if (user_input.next().charAt(0) == 'y'){ | |
flag = true; | |
} | |
return flag; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment