Commit 4ea3deec authored by Adam Blank's avatar Adam Blank
Browse files

Initial commit

parents
No related merge requests found
Showing with 407 additions and 0 deletions
+407 -0
File added
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CheckStyle-IDEA">
<option name="configuration">
<map>
<entry key="checkstyle-version" value="8.13" />
<entry key="copy-libs" value="false" />
<entry key="location-0" value="BUNDLED:(bundled):Sun Checks" />
<entry key="location-1" value="BUNDLED:(bundled):Google Checks" />
<entry key="scan-before-checkin" value="false" />
<entry key="scanscope" value="JavaOnly" />
<entry key="suppress-errors" value="false" />
</map>
</option>
</component>
</project>
\ No newline at end of file
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
</state>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with NO BOM" />
</project>
\ No newline at end of file
<component name="libraryTable">
<library name="com.github.javaparser:javaparser-core:3.5.2" type="repository">
<properties maven-id="com.github.javaparser:javaparser-core:3.5.2" />
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/com/github/javaparser/javaparser-core/3.5.2/javaparser-core-3.5.2.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="org.hamcrest:hamcrest-all:1.3" type="repository">
<properties maven-id="org.hamcrest:hamcrest-all:1.3" />
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-all/1.3/hamcrest-all-1.3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="org.junit.jupiter:junit-jupiter-params:5.4.0" type="repository">
<properties maven-id="org.junit.jupiter:junit-jupiter-params:5.4.0-SNAPSHOT" />
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-params/5.4.0-SNAPSHOT/junit-jupiter-params-5.4.0-SNAPSHOT.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/apiguardian/apiguardian-api/1.0.0/apiguardian-api-1.0.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-api/5.4.0-SNAPSHOT/junit-jupiter-api-5.4.0-SNAPSHOT.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/opentest4j/opentest4j/1.1.1/opentest4j-1.1.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-commons/1.4.0-SNAPSHOT/junit-platform-commons-1.4.0-SNAPSHOT.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="PreferredVcsStorage">
<preferredVcsName>ApexVCS</preferredVcsName>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/lab04-questions.iml" filepath="$PROJECT_DIR$/lab04-questions.iml" />
</modules>
</component>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/../../.." vcs="Git" />
</component>
</project>
\ No newline at end of file
This diff is collapsed.
<?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" />
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="org.junit.jupiter:junit-jupiter-params:5.4.0" level="project" />
<orderEntry type="library" name="org.hamcrest:hamcrest-all:1.3" level="project" />
<orderEntry type="library" name="com.github.javaparser:javaparser-core:3.5.2" level="project" />
</component>
</module>
package edu.caltech.cs2.lab04;
import java.io.PrintStream;
import java.util.List;
import java.util.Scanner;
public class FullStringTree {
protected static class StringNode {
public final String data;
public StringNode left;
public StringNode right;
public StringNode(String data) {
this(data, null, null);
}
public StringNode(String data, StringNode left, StringNode right) {
this.data = data;
this.left = left;
this.right = right;
// Ensures that the StringNode is either a leaf or has two child nodes.
if ((this.left == null || this.right == null) && !this.isLeaf()) {
throw new IllegalArgumentException("StringNodes must represent nodes in a full binary tree");
}
}
// Returns true if the StringNode has no child nodes.
public boolean isLeaf() {
return left == null && right == null;
}
}
protected FullStringTree() {}
public FullStringTree(Scanner in) {
}
private StringNode deserialize(Scanner in) {
return null;
}
public List<String> explore() {
return null;
}
public void serialize(PrintStream output) {
}
}
\ No newline at end of file
package edu.caltech.cs2.lab04;
import java.io.*;
import java.util.*;
public class QuestionMain {
public static void main(String[] args) throws IOException {
Scanner console = new Scanner(System.in);
System.out.println("Welcome to CS 2 Game of N-Questions!");
System.out.println();
System.out.print("Which questions file would you like to use? ");
String filename = console.nextLine().trim();
/* Create the Questions File if it doesn't exist */
File questionsFile = new File(filename);
if (!questionsFile.exists()) {
questionsFile.createNewFile();
}
Scanner questions = new Scanner(questionsFile);
QuestionTree game;
/* Check if the file has anything in it. If it does, use it. Otherwise, initialize
* a new game. */
if (!questions.hasNext()) {
System.out.println("There are no objects to guess in that questions file.");
System.out.print("Can you provide me with an initial object? ");
game = new QuestionTree(new Scanner("L: " + console.nextLine()));
}
else {
game = new QuestionTree(questions);
}
System.out.print("Let's play! ");
do {
System.out.println("Please choose your object, and I'll start guessing.");
System.out.println("Press Enter when you're ready to begin!");
console.nextLine();
game.play();
System.out.println();
game.serialize(new PrintStream(questionsFile));
System.out.print("Do you want to play again (y/n)? ");
} while (console.nextLine().trim().toLowerCase().startsWith("y"));
}
}
package edu.caltech.cs2.lab04;
// The QuestionsGame class can be used to play a "twenty questions" game with
// the user in which the computer attempts to guess an object the user is
// thinking of by asking yes/no questions. If it fails to guess correctly, it
// asks the user for information about the object and adds it to the tree. It
// includes methods for writing the current tree to a file and loadQuestions in a
// tree from a file.
import java.util.*;
public class QuestionTree extends FullStringTree {
private Scanner console;
public QuestionTree(Scanner in) {
super(in);
this.console = new Scanner(System.in);
}
// The game guesses what the object is and updates the tree if necessary.
private StringNode makeFinalGuess(StringNode leaf) {
System.out.println("I guess that your object is " + leaf.data + "!");
if (isYes("Am I right?")) {
System.out.println("Awesome! I win!");
}
else {
// Now, the game will get smarter! To learn from the loss, the game collects information about the
// object from the user and adds the object and its corresponding distinguishing question to the tree.
System.out.println("Boo! I Lose. Please help me get better!");
System.out.print("What is your object? ");
String name = console.nextLine();
System.out.print("Please give me a yes/no question that");
System.out.println(" distinguishes between " + name + " and " + leaf.data + ".");
System.out.print("Q: ");
String question = console.nextLine();
if (isYes("Is the answer \"yes\" for " + name + "?")) {
leaf = new StringNode(question, new StringNode(name), leaf);
}
else {
leaf = new StringNode(question, leaf, new StringNode(name));
}
}
return leaf;
}
// Returns true if the inputted response starts with the letter "y" (upper case or lower case)
private boolean isYes(String prompt) {
System.out.print(prompt + " (y/n)? ");
return console.nextLine().trim().toLowerCase().startsWith("y");
}
public void play() {
// Fill me in!
}
}
\ No newline at end of file
File added
I: apple
I: orange
L: pineapple
L: kiwi
I: lime
I: lemon
L: watermelon
L: strawberry
L: mango
\ No newline at end of file
I: Dr. Pepper
I: Sprite
I: Mountain Dew
L: Coke
L: Root Beer
L: Ginger Ale
I: Fanta
L: Sunkist
L: Pepsi
\ No newline at end of file
Is it an animal? (y/n)? Does it have wheels? (y/n)? I guess that your object is bicycle!
Am I right? (y/n)? Awesome! I win!
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment