Download 07 - Control Statements/006 User Activity Selector.html from Tan115/java-development-for-beginners-learnit: direct link, hf CLI and curl.
- Browser
- Download file 9.39 kB
-
https://huggingface.co/Tan115/java-development-for-beginners-learnit/resolve/main/07%20-%20Control%20Statements/006%20User%20Activity%20Selector.html
- Command line
-
hf download 'hf://Tan115/java-development-for-beginners-learnit/07 - Control Statements/006 User Activity Selector.html'
-
curl -L -o '006 User Activity Selector.html' https://huggingface.co/Tan115/java-development-for-beginners-learnit/resolve/main/07%20-%20Control%20Statements/006%20User%20Activity%20Selector.html
9.39 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8" /> | |
| <meta http-equiv="X-UA-Compatible" content="IE=edge" /> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
| <title>Coding Assignment</title> | |
| <style> | |
| body { | |
| font-family: sf pro text, -apple-system, BlinkMacSystemFont, Roboto, segoe ui, Helvetica, Arial, | |
| sans-serif, apple color emoji, segoe ui emoji, segoe ui symbol; | |
| font-weight: 400; | |
| line-height: 22.4px; | |
| font-size: 16px; | |
| } | |
| p, | |
| ul, | |
| ol { | |
| font-size: 16px; | |
| font-weight: 400; | |
| } | |
| h1, | |
| h2, | |
| h3, | |
| h4, | |
| h5, | |
| h6 { | |
| font-weight: bold; | |
| } | |
| ul { | |
| list-style: none; | |
| margin: 0; | |
| padding: 0; | |
| max-width: none; | |
| } | |
| .code-snippet { | |
| background-color: #fff; | |
| border: 1px solid #d1d7dc; | |
| color: #b4690e; | |
| font-size: 90%; | |
| padding: 0.2rem 0.4rem; | |
| } | |
| .code-block { | |
| background-color: #fff; | |
| color: #b4690e; | |
| font-size: 90%; | |
| } | |
| .black-block { | |
| color: #000000; | |
| } | |
| .italic-text { | |
| font-style: italic; | |
| } | |
| </style> | |
| </head> | |
| <body onload="main()"> | |
| <h1 id="coding-title"></h1> | |
| <div> | |
| <h2>Instructions</h2> | |
| <div id="coding-instructions"></div> | |
| </div> | |
| <div> | |
| <h2>Test(s)</h2> | |
| <div id="coding-tests"></div> | |
| </div> | |
| <div> | |
| <h2>Solution(s)</h2> | |
| <div id="coding-solutions"></div> | |
| </div> | |
| <script> | |
| const quizData = {"title": "006 User Activity Selector", "hasInstructions": true, "hasTests": true, "hasSolutions": true, "instructions": "<ol><li><p>Implement console program which will meet the following requirements:</p><ol><li><p>Program is started and user is asked to enter one of possible events:</p><ol><li><p>login</p></li><li><p>sign_up</p></li><li><p>terminate_program</p></li><li><p>main_menu</p></li><li><p>about_app</p></li></ol></li><li><p>Based on user input program prints to console different text. Mapping is below:<br></p><img src=\"https://img-c.udemycdn.com/redactor/raw/2020-04-14_17-17-07-cd73b16a9c0c505bcb5e301221bf0b31.jpg\"></li></ol></li></ol>", "tests": [{"file_name": "Evaluate.java", "content": "import org.junit.Test;\nimport org.junit.Assert;\nimport com.udemy.ucp.*;\nimport static org.junit.Assert.assertEquals;\n\nimport java.io.ByteArrayInputStream;\nimport java.io.ByteArrayOutputStream;\nimport java.io.InputStream;\nimport java.io.PrintStream;\n\nimport org.junit.After;\nimport org.junit.Before;\nimport org.junit.Test;\n\npublic class Evaluate {\n \tprivate static final String OUTPUT_RESULT_SEPARATOR = \"Please, enter action name:\";\n\tprivate final ByteArrayOutputStream out = new ByteArrayOutputStream();\n\tprivate final PrintStream originalOut = System.out;\n\n\t@Before\n\tpublic void setStreams() {\n\t\tSystem.setOut(new PrintStream(out));\n\t}\n\n\t@After\n\tpublic void restoreInitialStreams() {\n\t\tSystem.setOut(originalOut);\n\t}\n\n\t@Test\n\tpublic void shouldProcessLoginEvent() {\n\t\tString input = \"login\";\n\t\tInputStream in = new ByteArrayInputStream(input.getBytes());\n\t\tSystem.setIn(in);\n\n\t\tUserActivitySelector.main(new String[] {});\n\t\t\n\t\tString consoleOutput = out.toString().split(OUTPUT_RESULT_SEPARATOR)[1].strip();\n\t\tassertEquals(\"Please, enter your username\", consoleOutput);\n\t}\n\n\t@Test\n\tpublic void shouldProcessSignUpEvent() {\n\t\tString input = \"sign_up\";\n\t\tInputStream in = new ByteArrayInputStream(input.getBytes());\n\t\tSystem.setIn(in);\n\n\t\tUserActivitySelector.main(new String[] {});\n\t\t\n\t\tString consoleOutput = out.toString().split(OUTPUT_RESULT_SEPARATOR)[1].strip();\n\t\tassertEquals(\"Welcome!\", consoleOutput);\n\t}\n\n\t@Test\n\tpublic void shouldProcessTerminationEvent() {\n\t\tString input = \"terminate_program\";\n\t\tInputStream in = new ByteArrayInputStream(input.getBytes());\n\t\tSystem.setIn(in);\n\n\t\tUserActivitySelector.main(new String[] {});\n\t\t\n\t\tString consoleOutput = out.toString().split(OUTPUT_RESULT_SEPARATOR)[1].strip();\n\t\tassertEquals(\"Thank you! Good bye!\", \n\t\t\t\tconsoleOutput);\n\t}\n\n\t@Test\n\tpublic void shouldProcessMainMenuEvent() {\n\t\tString input = \"main_menu\";\n\t\tInputStream in = new ByteArrayInputStream(input.getBytes());\n\t\tSystem.setIn(in);\n\n\t\tUserActivitySelector.main(new String[] {});\n\t\t\n\t\tString consoleOutput = out.toString().split(OUTPUT_RESULT_SEPARATOR)[1].strip();\n\t\tassertEquals(\"Main menu\", \n\t\t\t\tconsoleOutput);\n\t}\n\n\t@Test\n\tpublic void shouldProcessAboutAppEvent() {\n\t\tString input = \"about_app\";\n\t\tInputStream in = new ByteArrayInputStream(input.getBytes());\n\t\tSystem.setIn(in);\n\n\t\tUserActivitySelector.main(new String[] {});\n\t\tString consoleOutput = out.toString().split(OUTPUT_RESULT_SEPARATOR)[1].strip();\n\t\tassertEquals(\"This app is created by me with support of \u00aeIT-Bulls.com\", \n\t\t\t\tconsoleOutput);\n\t}\n\n\t@Test\n\tpublic void shouldProcessDefaultEvent() {\n\t\tString input = \"any other input about_app\";\n\t\tInputStream in = new ByteArrayInputStream(input.getBytes());\n\t\tSystem.setIn(in);\n\n\t\tUserActivitySelector.main(new String[] {});\n\t\tString consoleOutput = out.toString().split(OUTPUT_RESULT_SEPARATOR)[1].strip();\n\t\tassertEquals(\"Please, enter one of these values: login, sign_up, terminate_program, main_menu, about_app\", \n\t\t\t\tconsoleOutput);\n\n\t}\n\n}\n"}], "solutions": [{"file_name": "UserActivitySelector.java", "content": "import java.util.Scanner;\r\n\r\npublic class UserActivitySelector {\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\tSystem.out.print(\"Please, enter action name: \");\r\n\t\tScanner sc = new Scanner(System.in);\r\n\t\tString userInput = sc.nextLine();\r\n\r\n\t\tswitch (userInput) {\r\n\t\tcase \"login\":\r\n\t\t\tSystem.out.println(\"Please, enter your username\");\r\n\t\t\tbreak;\r\n\t\tcase \"sign_up\":\r\n\t\t\tSystem.out.println(\"Welcome!\");\r\n\t\t\tbreak;\r\n\t\tcase \"terminate_program\":\r\n\t\t\tSystem.out.println(\"Thank you! Good bye!\");\r\n\t\t\tbreak;\r\n\t\tcase \"main_menu\":\r\n\t\t\tSystem.out.println(\"Main menu\");\r\n\t\t\tbreak;\r\n\t\tcase \"about_app\":\r\n\t\t\tSystem.out.println(\"This app is created by me with \"\r\n\t\t\t\t\t+ \"support of \\u00AEIT-Bulls.com\");\r\n\t\t\tbreak;\r\n\t\tdefault:\r\n\t\t\tSystem.out.println(\"Please, enter one of these values: login, \"\r\n\t\t\t\t\t+ \"sign_up, terminate_program, main_menu, about_app\");\r\n\t\t\tbreak;\r\n\t\t}\r\n\r\n\t}\r\n}\r\n"}]}; | |
| function renderCodeList(rootElement, codeList, className, titlePrefix) { | |
| for (var i = 0; i < codeList.length; i++) { | |
| var elem = codeList[i]; | |
| var jsElem = document.createElement("div"); | |
| jsElem.className = className; | |
| var jsElemTitle = document.createElement("h3"); | |
| jsElemTitle.innerHTML = titlePrefix + " " + (i + 1); | |
| var jsElemBody = document.createElement("code"); | |
| jsElemBody.className = "code-block black-block"; | |
| jsElemBody.innerHTML = "<pre>" + elem.content + "</pre>"; | |
| jsElem.appendChild(jsElemTitle); | |
| jsElem.appendChild(jsElemBody); | |
| rootElement.appendChild(jsElem); | |
| } | |
| } | |
| function main() { | |
| // display the assignment | |
| var codingTitle = document.getElementById("coding-title"); | |
| codingTitle.innerHTML = quizData.title; | |
| var codingInstructions = document.getElementById("coding-instructions"); | |
| if (quizData.hasInstructions) { | |
| codingInstructions.innerHTML = quizData.instructions; | |
| } else { | |
| codingInstructions.innerHTML = '<span class="italic-text">' + quizData.instructions + "</span>"; | |
| } | |
| // display the test(s) | |
| var codingTests = document.getElementById("coding-tests"); | |
| if (!quizData.hasTests) { | |
| codingTests.innerHTML = '<span class="italic-text">' + quizData.tests + "</span>"; | |
| } else { | |
| renderCodeList(codingTests, quizData.tests, "coding-test", "Test"); | |
| } | |
| // display the solution(s) | |
| var codingSolutions = document.getElementById("coding-solutions"); | |
| if (!quizData.hasSolutions) { | |
| codingSolutions.innerHTML = '<span class="italic-text">' + quizData.solutions + "</span>"; | |
| } else { | |
| renderCodeList(codingSolutions, quizData.solutions, "coding-solution", "Solution"); | |
| } | |
| } | |
| </script> | |
| </body> | |
| </html> | |