forked from nighthawkcoders/student
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
af4f8c7
commit 011ee6a
Showing
2 changed files
with
105 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"---\n", | ||
"title: FRQ 2\n", | ||
"description: Second FRQ for collegeboard FRQ final\n", | ||
"toc: true\n", | ||
"layout: post\n", | ||
"courses: { ToC: {week: 23} }\n", | ||
"---" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 11, | ||
"metadata": { | ||
"vscode": { | ||
"languageId": "java" | ||
} | ||
}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"+A+++\n", | ||
"H*++*\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"public class Main{\n", | ||
" public static void main (String args[]){\n", | ||
" HiddenWord puzzle = new HiddenWord(\"HARPS\");\n", | ||
" System.out.println(puzzle.getHint(\"AAAAA\"));\n", | ||
" System.out.println(puzzle.getHint(\"HEART\"));\n", | ||
" }\n", | ||
"}\n", | ||
"\n", | ||
"public class HiddenWord{\n", | ||
" private String word;\n", | ||
" public HiddenWord(String word){\n", | ||
" this.word = word;\n", | ||
" }\n", | ||
" public String getHint(String guess){\n", | ||
" String hint = \"\";\n", | ||
" for (int i = 0; i < guess.length(); i++){\n", | ||
" if (this.word.contains(String.valueOf(guess.charAt(i)))){\n", | ||
" if (this.word.charAt(i) == guess.charAt(i)){\n", | ||
" hint = hint + guess.charAt(i);\n", | ||
" }\n", | ||
" else {\n", | ||
" hint = hint + \"+\";\n", | ||
" }\n", | ||
" }\n", | ||
" else {\n", | ||
" hint = hint + \"*\";\n", | ||
" }\n", | ||
" }\n", | ||
" return hint;\n", | ||
" }\n", | ||
"}\n", | ||
"Main.main(null);" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Learnings:\n", | ||
"\n", | ||
"1. I can check if a letter is contained in a string by using the .contains() method on the string\n", | ||
"2. length of a string is a method, length(). Length of an array is a property of the class. \n", | ||
"3. I can't iterate through a string using brackents, I need to do charAt(). \n", | ||
"4. String.contains can only include a string as the parameter, not a char. You need to convert a char if you're going to use a char. " | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Java", | ||
"language": "java", | ||
"name": "java" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": "java", | ||
"file_extension": ".jshell", | ||
"mimetype": "text/x-java-source", | ||
"name": "Java", | ||
"pygments_lexer": "java", | ||
"version": "20.0.2+9" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |