Permalink
Browse files

Problem Set 4

Added
  • Loading branch information...
1 parent 18ef10b commit e3c7f5c28624f8cccf59f3ffab1b5b1e4d678214 @simyseng committed Jul 21, 2013
View
BIN .DS_Store
Binary file not shown.
View
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry excluding="src/" kind="src" path=""/>
+ <classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="lib" path="/Problem Set 3/acm.jar"/>
+ <classpathentry kind="lib" path="/TextBook Examples/acm.jar"/>
+ <classpathentry kind="lib" path="/Users/yssim/Documents/workspace/Problem Set 4/acm.jar"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
View
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>Problem Set 4</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
@@ -0,0 +1,12 @@
+#Fri Jul 19 22:12:12 WIT 2013
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
View
Binary file not shown.
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry excluding="src/" kind="src" path=""/>
+ <classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="lib" path="/Problem Set 3/acm.jar"/>
+ <classpathentry kind="lib" path="/TextBook Examples/acm.jar"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
View
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>Problem Set 4</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
@@ -0,0 +1,12 @@
+#Fri Jul 19 22:12:12 WIT 2013
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
Binary file not shown.
Binary file not shown.
Binary file not shown.
View
Binary file not shown.
@@ -0,0 +1,7 @@
+/* AUTOMATICALLY GENERATED ON Tue Apr 16 17:20:59 EDT 2002*/
+/* DO NOT EDIT */
+
+grant {
+ permission java.security.AllPermission;
+};
+
@@ -0,0 +1,30 @@
+import acm.program.*;
+
+public class Comma extends ConsoleProgram {
+ public void run() {
+ while(true) {
+ String digits = readLine("Enter a number: ");
+ if(digits.length() == 0) break;
+ println(addComma(digits));
+ }
+ }
+
+ private String addComma(String digitsString) {
+ // Find the number of commas in the number
+ int commaCount = (digitsString.length() - 1) / 3;
+ if(commaCount == 0) return digitsString;
+
+ int firstCommaIndex = (digitsString.length() % 3 != 0 ? digitsString.length() % 3 : 3); // Find the index of the first comma
+
+ String aString = "";
+ aString = digitsString.substring(0,firstCommaIndex) + ","; // Get the substring from first digit to the digit before first comma
+
+ /* Concat aString with a comma to the returning string */
+ for(int i = 0 ; i < commaCount - 1 ; i++){
+ aString += digitsString.substring(firstCommaIndex + i * 3, firstCommaIndex + i * 3 + 3);
+ aString += ",";
+ }
+ aString += digitsString.substring(digitsString.length() - 3, digitsString.length()); // Add the last comma
+ return aString;
+ }
+}
@@ -0,0 +1,17 @@
+import acm.program.*;
+
+public class RemoveAllOccurences extends ConsoleProgram{
+ public void run() {
+ String aString = readLine("Enter a sentence: ");
+ char ch = '-';
+ println(removeAllOccurences(aString, ch));
+ }
+
+ private String removeAllOccurences(String aString, char ch) {
+ String returningString = "";
+ for(int i = 0 ; i < aString.length() - 1; i++) {
+ if(aString.charAt(i) != ch) returningString += aString.charAt(i);
+ }
+ return returningString;
+ }
+}
@@ -0,0 +1,10 @@
+import acm.program.*;
+
+public class Test extends ConsoleProgram{
+ public void run() {
+ String string = "1000";
+
+ println(string.substring(string.length()-3,string.length()-1));
+
+ }
+}

0 comments on commit e3c7f5c

Please sign in to comment.