Skip to content

Commit 62363f1

Browse files
Merge branch 'Ahmad-Java-Puzzles-working'
2 parents 3eb6f3e + 77b38c3 commit 62363f1

72 files changed

Lines changed: 1351 additions & 1 deletion

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Ahmad/2_puzzles/assignment_07/src/assignment_07/App.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public static String fizzyWizzy(int n) {
2929
if(fizz) return "Fizz!";
3030
if(buzz) return "Buzz!";
3131

32-
32+
return n + "!";
3333
}
3434

3535

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
4+
<attributes>
5+
<attribute name="module" value="true"/>
6+
</attributes>
7+
</classpathentry>
8+
<classpathentry kind="src" path="src"/>
9+
<classpathentry kind="output" path="bin"/>
10+
</classpath>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/bin/
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>assignment_11</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
eclipse.preferences.version=1
2+
encoding/<project>=UTF-8
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
4+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5+
org.eclipse.jdt.core.compiler.compliance=17
6+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
8+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10+
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
11+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
12+
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
13+
org.eclipse.jdt.core.compiler.release=enabled
14+
org.eclipse.jdt.core.compiler.source=17
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package assignment_11;
2+
3+
import ignore.TestingUtils;
4+
5+
public class App {
6+
7+
8+
/**
9+
10+
Given a string, return a string where for every char in the original, append another.
11+
<br>
12+
<br>
13+
14+
* <b>EXPECTATIONS:</b><br>
15+
repeatChar("The") <b>---></b>"TThhee"<br>
16+
repeatChar("AAbb") <b>---></b> "AAAAbbbb" <br>
17+
repeatChar("Hi-There") <b>---></b> "HHii--TThheerree" <br>
18+
*/
19+
20+
public static String repeatChar(String str) {
21+
String result = "";
22+
23+
for(int i =0; i <str.length(); i++) {
24+
char aChar = str.charAt(i);
25+
result = result + aChar + aChar;
26+
}
27+
return result;
28+
29+
}
30+
31+
32+
33+
34+
35+
36+
37+
38+
39+
40+
41+
//----------------------STARTING POINT OF PROGRAM. IGNORE BELOW --------------------//
42+
public static void main(String args[]){
43+
TestingUtils.runTests();
44+
45+
}
46+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package ignore;
2+
3+
import assignment_11.App;
4+
5+
public class TestingUtils {
6+
public static void runTests(){
7+
8+
String[] params1 = { "The", "AAbb", "Hi-There", "Word!", "!!", "", "a", ".", "aa" };
9+
10+
String[] expected = { "TThhee", "AAAAbbbb", "HHii--TThheerree", "WWoorrdd!!", "!!!!", "", "aa", "..", "aaaa" };
11+
12+
for(int i=0; i < params1.length; i++){
13+
String result = App.repeatChar(params1[i]);
14+
if(result.equals(expected[i])) {
15+
System.out.println(printPassResult(params1[i], expected[i], result));
16+
} else{
17+
System.out.println(printFailResult(params1[i], expected[i], result));
18+
}
19+
}
20+
}
21+
22+
private static String printPassResult(Object params1, Object expected, Object result){
23+
return "PASS: repeatChar("+ params1.toString()+ ") -> " + result.toString();
24+
}
25+
26+
27+
private static String printFailResult(Object params1, Object expected, Object result){
28+
String ret = "**********************" + "\n";
29+
ret += "FAIL: repeatChar("+ params1.toString()+") -> " + result.toString()
30+
+ " Expected: "+ expected.toString();
31+
ret += "\n" + "**********************";
32+
return ret;
33+
}
34+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
4+
<attributes>
5+
<attribute name="module" value="true"/>
6+
</attributes>
7+
</classpathentry>
8+
<classpathentry kind="src" path="src"/>
9+
<classpathentry kind="output" path="bin"/>
10+
</classpath>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/bin/

0 commit comments

Comments
 (0)