24fed34
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | <!DOCTYPE html>
<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": "013 String Processor", "hasInstructions": true, "hasTests": true, "hasSolutions": true, "instructions": "<ol><li><p>Implement console program which will meet the following requirements:</p><ol><li><p>Program contains methods that can process input string according to requirements below</p></li><li><p>You have input string like this:<br><br><strong><em>Login;Name;Email</em></strong></p></li></ol></li></ol><p><strong><em> peterson;Chris Peterson;peterson@outlook.com</em></strong></p><p><strong><em> james;Derek James;james@gmail.com</em></strong></p><p><strong><em> jackson;Walter Jackson;jackson@gmail.com</em></strong></p><p><strong><em> gregory;Mike Gregory;gregory@yahoo.com<br><br></em></strong></p><ol><li><ol><li><p>You program has next method:<br><br><strong><em>public static String convert1(String input) {<br> <write your code here><br>}</em></strong><br><br>Which formats input data like this:<br>peterson ==> peterson@outlook.com</p></li></ol><p> james ==> james@gmail.com</p><p> jackson ==> jackson@gmail.com</p><p> gregory ==> gregory@yahoo.com</p></li></ol><p><br><br></p><ol><li><ol><li><p>You program has next method:<br><br><strong><em>public static String convert2(String input) {<br> <write your code here><br>}</em></strong><br><br>Which formats input data like this:</p><p>Chris Peterson (email: peterson@outlook.com)</p></li></ol><p> Derek James (email: james@gmail.com)</p><p> Walter Jackson (email: jackson@gmail.com)</p><p> Mike Gregory (email: gregory@yahoo.com)</p></li></ol><p><br></p>", "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 org.junit.Test;\n\npublic class Evaluate {\n private static final String INPUT_DATA = \"Login;Name;Email\" + System.lineSeparator()\n\t\t\t+ \"peton;Chris Peterso;person@outlook.com\" + System.lineSeparator()\n\t\t\t+ \"jas;Derek Jame;jes@gmail.com\" + System.lineSeparator()\n\t\t\t+ \"jack;Walter Jackso;jkson@gmail.com\" + System.lineSeparator()\n\t\t\t+ \"greg;Mike Gregor;ggory@yahoo.com\";\n\n\t@Test\n\tpublic void shouldFormatConvert1() {\n\t\tassertEquals(\n\t\t\t\t\"peton ==> person@outlook.com\" + System.lineSeparator()\n\t\t\t\t\t\t+ \"jas ==> jes@gmail.com\" + System.lineSeparator()\n\t\t\t\t\t\t+ \"jack ==> jkson@gmail.com\" + System.lineSeparator()\n\t\t\t\t\t\t+ \"greg ==> ggory@yahoo.com\",\n\t\t\t\tStringProcessor.convert1(INPUT_DATA).strip());\n\t}\n\n\t@Test\n\tpublic void shouldFormatConvert2() {\n\t\tassertEquals(\n\t\t\t\t\"Chris Peterso (email: person@outlook.com)\" + System.lineSeparator()\n\t\t\t\t\t\t+ \"Derek Jame (email: jes@gmail.com)\" + System.lineSeparator()\n\t\t\t\t\t\t+ \"Walter Jackso (email: jkson@gmail.com)\"\n\t\t\t\t\t\t+ System.lineSeparator() + \"Mike Gregor (email: ggory@yahoo.com)\",\n\t\t\t\tStringProcessor.convert2(INPUT_DATA).strip());\n\t}\n\n\n}\n"}], "solutions": [{"file_name": "StringProcessor.java", "content": "\r\npublic class StringProcessor {\r\n\t\r\n\t\r\n\tpublic static final String INPUT_DATA = \"Login;Name;Email\" + System.lineSeparator() +\r\n\t\t\t\"peterson;Chris Peterson;peterson@outlook.com\" + System.lineSeparator() +\r\n\t\t\t\"james;Derek James;james@gmail.com\" + System.lineSeparator() +\r\n\t\t\t\"jackson;Walter Jackson;jackson@gmail.com\" + System.lineSeparator() +\r\n\t\t\t\"gregory;Mike Gregory;gregory@yahoo.com\";\r\n\t\r\n\tpublic static void main(String[] args) {\r\n\t\tSystem.out.println(\"===== Convert 1 demo =====\");\r\n\t\tSystem.out.println(convert1(INPUT_DATA));\r\n\t\t\r\n\t\tSystem.out.println(\"===== Convert 2 demo =====\");\r\n\t\tSystem.out.println(convert2(INPUT_DATA));\r\n\t\t\r\n\t}\r\n\t\r\n\tpublic static String convert1(String input) {\r\n\t\tString result = \"\";\r\n\t\tString[] lines = input.split(System.lineSeparator());\r\n\t\tfor (int i = 1; i < lines.length; i++) {\r\n\t\t\tString[] wordsInLine = lines[i].split(\";\");\r\n\t\t\tresult += wordsInLine[0] + \" ==> \" + wordsInLine[2] + System.lineSeparator();\r\n\t\t}\r\n\t\treturn result;\r\n\t\r\n\t}\r\n\t\r\n\t\r\n\tpublic static String convert2(String input) {\r\n\t\tString result = new String();\r\n\t\tString[] lines = input.split(System.lineSeparator());\r\n\t\tfor (int i = 1; i < lines.length; i++) {\r\n\t\t\tString[] wordsInLine = lines[i].split(\";\");\r\n\t\t\tresult += wordsInLine[1] + \" (email: \" + wordsInLine[2] + \")\" + System.lineSeparator();\r\n\t\t}\r\n\t\treturn result;\r\n\t\r\n\t}\r\n\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>
|