Skip to content
Browse files

Assignment 2 Added

Assignment 2 Added
  • Loading branch information...
1 parent 23de915 commit 31ec49fce3bd82b2ba5e56b5d06b4900c6120c17 @simyseng committed Jul 21, 2013
View
BIN Assignment 2/.DS_Store
Binary file not shown.
View
7 Assignment 2/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path=""/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="lib" path="acm.jar"/>
+ <classpathentry kind="output" path=""/>
+</classpath>
View
17 Assignment 2/.project
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>Assignment2</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>
View
67 Assignment 2/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,67 @@
+#Fri Oct 01 11:23:39 PDT 2010
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
+org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
+org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning
+org.eclipse.jdt.core.compiler.problem.deadCode=warning
+org.eclipse.jdt.core.compiler.problem.deprecation=warning
+org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
+org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
+org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
+org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore
+org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore
+org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled
+org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore
+org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
+org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=error
+org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
+org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
+org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=ignore
+org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore
+org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore
+org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
+org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore
+org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=ignore
+org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore
+org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled
+org.eclipse.jdt.core.compiler.problem.missingSerialVersion=ignore
+org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore
+org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
+org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
+org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
+org.eclipse.jdt.core.compiler.problem.nullReference=warning
+org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
+org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
+org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore
+org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore
+org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning
+org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore
+org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore
+org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
+org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
+org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled
+org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
+org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
+org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
+org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
+org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
+org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
+org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore
+org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=ignore
+org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
+org.eclipse.jdt.core.compiler.problem.unusedImport=warning
+org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
+org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
+org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=ignore
+org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore
+org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled
+org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
+org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
+org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
+org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
+org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
View
BIN Assignment 2/FindRange.class
Binary file not shown.
View
48 Assignment 2/FindRange.java
@@ -0,0 +1,48 @@
+/*
+ * File: FindRange.java
+ * Name:
+ * Section Leader:
+ * --------------------
+ * This file is the starter file for the FindRange problem.
+ */
+
+import acm.program.*;
+
+public class FindRange extends ConsoleProgram {
+ public void run() {
+ println("This program finds the largest and smallest numbers.");
+ /*
+ * Initialize the first userInput and set maximum and minimum to this value
+ */
+ int userInput = readInt("?");
+ int maximum = userInput;
+ int minimum = userInput;
+
+ /*
+ * loop to receive userInput and set maximum and minimum when necessary
+ * Exit loop when userInput equals SENTINEL
+ */
+ while( userInput != SENTINEL) {
+ userInput = readInt("?");
+ if (userInput == SENTINEL) break;
+ if (userInput > maximum) {
+ maximum = userInput;
+ } else if (userInput < minimum) {
+ minimum = userInput;
+ }
+ }
+
+ /*
+ * Print the appropriate outputs.
+ */
+ if ( maximum == 0 && minimum == 0) {
+ println("No numbers were entered.");
+ } else {
+ println("smallest: " + minimum);
+ println("largest: " + maximum);
+ }
+ }
+
+ private static final int SENTINEL = 0;
+}
+
View
BIN Assignment 2/Hailstone.class
Binary file not shown.
View
30 Assignment 2/Hailstone.java
@@ -0,0 +1,30 @@
+/*
+ * File: Hailstone.java
+ * Name:
+ * Section Leader:
+ * --------------------
+ * This file is the starter file for the Hailstone problem.
+ */
+
+import acm.program.*;
+
+public class Hailstone extends ConsoleProgram {
+ public void run() {
+ int n = readInt("Enter a number: ");
+ int step = 0;
+ while(n != 1) {
+ if( n % 2 == 0) {
+ print( n + " is even so I take half: ");
+ n /= 2;
+ println(n);
+ } else {
+ print( n + " is odd so I make 3n + 1: ");
+ n = 3 * n + 1;
+ println(n);
+ }
+ step ++;
+ }
+ println("The process took " + step + " to reach 1.");
+ }
+}
+
View
BIN Assignment 2/ProgramHierarchy.class
Binary file not shown.
View
91 Assignment 2/ProgramHierarchy.java
@@ -0,0 +1,91 @@
+/*
+ * File: ProgramHierarchy.java
+ * Name:
+ * Section Leader:
+ * ---------------------------
+ * This file is the starter file for the ProgramHierarchy problem.
+ */
+
+import acm.graphics.*;
+import acm.program.*;
+//import java.awt.*;
+
+public class ProgramHierarchy extends GraphicsProgram {
+ public void run() {
+
+ drawProgramBox();
+ drawGraphicsProgramBox();
+ drawConsoleProgramBox();
+ drawDialogProgramBox();
+ drawLines();
+
+ }
+
+ private void drawProgramBox() {
+ GLabel label = new GLabel("Program"); // To get the label properties
+ double labelWidth = label.getWidth();
+ double labelAscent = label.getAscent();
+ double labelBoxOriginX = (getWidth() - BOXWIDTH) / 2;
+ double labelBoxOriginY = (getHeight() / 2) - (BOXHEIGHT + OFFSET_Y);
+ GRect labelBox = new GRect(labelBoxOriginX, labelBoxOriginY, BOXWIDTH, BOXHEIGHT);
+ GLabel labelText = new GLabel("Program", (labelBoxOriginX + (BOXWIDTH - labelWidth) / 2), (labelBoxOriginY + (BOXHEIGHT + labelAscent) / 2));
+
+ add(labelBox);
+ add(labelText);
+ }
+
+ private void drawGraphicsProgramBox() {
+ GLabel label = new GLabel("GraphicsProgram"); // To get the label properties
+ double labelWidth = label.getWidth();
+ double labelAscent = label.getAscent();
+ double labelBoxOriginX = (getWidth() - BOXWIDTH) / 2;
+ double labelBoxOriginY = (getHeight() / 2) + OFFSET_Y;
+ GRect labelBox = new GRect(labelBoxOriginX, labelBoxOriginY, BOXWIDTH, BOXHEIGHT);
+ GLabel labelText = new GLabel("GraphicsProgram", (labelBoxOriginX + (BOXWIDTH - labelWidth) / 2), (labelBoxOriginY + (BOXHEIGHT + labelAscent) / 2));
+
+ add(labelBox);
+ add(labelText);
+ }
+
+ private void drawConsoleProgramBox() {
+ GLabel label = new GLabel("ConsoleProgram"); // To get the label properties
+ double labelWidth = label.getWidth();
+ double labelAscent = label.getAscent();
+ double labelBoxOriginX = ((getWidth() - BOXWIDTH) / 2) - (BOXWIDTH + OFFSET_X);
+ double labelBoxOriginY = (getHeight() / 2) + OFFSET_Y;
+ GRect labelBox = new GRect(labelBoxOriginX, labelBoxOriginY, BOXWIDTH, BOXHEIGHT);
+ GLabel labelText = new GLabel("ConsoleProgram", (labelBoxOriginX + (BOXWIDTH - labelWidth) / 2), (labelBoxOriginY + (BOXHEIGHT + labelAscent) / 2));
+
+ add(labelBox);
+ add(labelText);
+ }
+
+ private void drawDialogProgramBox() {
+ GLabel label = new GLabel("DialogProgram"); // To get the label properties
+ double labelWidth = label.getWidth();
+ double labelAscent = label.getAscent();
+ double labelBoxOriginX = ((getWidth() - BOXWIDTH) / 2) + (BOXWIDTH + OFFSET_X);
+ double labelBoxOriginY = (getHeight() / 2) + OFFSET_Y;
+ GRect labelBox = new GRect(labelBoxOriginX, labelBoxOriginY, BOXWIDTH, BOXHEIGHT);
+ GLabel labelText = new GLabel("DialogProgram", (labelBoxOriginX + (BOXWIDTH - labelWidth) / 2), (labelBoxOriginY + (BOXHEIGHT + labelAscent) / 2));
+
+ add(labelBox);
+ add(labelText);
+ }
+
+ private void drawLines() {
+ GLine centreLine = new GLine(getWidth() / 2, (getHeight() / 2) - OFFSET_Y, getWidth() / 2, (getHeight() / 2) + OFFSET_Y);
+ GLine leftLine = new GLine(getWidth() / 2, (getHeight() / 2) - OFFSET_Y, getWidth() / 2 - (BOXWIDTH + OFFSET_X), (getHeight() / 2) + OFFSET_Y);
+ GLine rightLine = new GLine(getWidth() / 2, (getHeight() / 2) - OFFSET_Y, getWidth() / 2 + (BOXWIDTH + OFFSET_X), (getHeight() / 2) + OFFSET_Y);
+ add(centreLine);
+ add(leftLine);
+ add(rightLine);
+ }
+
+
+ private static final int BOXWIDTH = 150;
+ private static final int BOXHEIGHT = 40;
+ private static final int OFFSET_X = 60;
+ private static final int OFFSET_Y = 25;
+}
+
View
BIN Assignment 2/Pyramid.class
Binary file not shown.
View
45 Assignment 2/Pyramid.java
@@ -0,0 +1,45 @@
+/*
+ * File: Pyramid.java
+ * Name:
+ * Section Leader:
+ * ------------------
+ * This file is the starter file for the Pyramid problem.
+ * It includes definitions of the constants that match the
+ * sample run in the assignment, but you should make sure
+ * that changing these values causes the generated display
+ * to change accordingly.
+ */
+
+import acm.graphics.*;
+import acm.program.*;
+import java.awt.*;
+
+public class Pyramid extends GraphicsProgram {
+
+ public void run() {
+ int rowCount = BRICKS_IN_BASE;
+ double x_coordinate;
+ double y_coordinate;
+
+ while( rowCount > 0 ) {
+ for ( int i = 0 ; i < rowCount ; i++) {
+ x_coordinate = (getWidth() / 2) - ((rowCount / 2.0) * BRICK_WIDTH) + (i * BRICK_WIDTH);
+ y_coordinate = (getHeight() - ((BRICKS_IN_BASE - rowCount + 1) * BRICK_HEIGHT));
+ GRect brick = new GRect(x_coordinate, y_coordinate, BRICK_WIDTH, BRICK_HEIGHT);
+ add(brick);
+ }
+ rowCount--;
+ }
+ }
+
+ /** Width of each brick in pixels */
+ private static final int BRICK_WIDTH = 30;
+
+ /** Width of each brick in pixels */
+ private static final int BRICK_HEIGHT = 12;
+
+ /** Number of bricks in the base of the pyramid */
+ private static final int BRICKS_IN_BASE = 14;
+
+}
+
View
BIN Assignment 2/PythagoreanTheorem.class
Binary file not shown.
View
20 Assignment 2/PythagoreanTheorem.java
@@ -0,0 +1,20 @@
+/*
+ * File: PythagoreanTheorem.java
+ * Name:
+ * Section Leader:
+ * -----------------------------
+ * This file is the starter file for the PythagoreanTheorem problem.
+ */
+
+import acm.program.*;
+
+public class PythagoreanTheorem extends ConsoleProgram {
+ public void run() {
+ println("Enter values to compute the Pythagorean theorem.");
+ double a = readDouble("a: ");
+ double b = readDouble("b: ");
+ double hSquare = a*a + b*b;
+ double c = Math.sqrt(hSquare);
+ println("c = " + c);
+ }
+}
View
BIN Assignment 2/Target.class
Binary file not shown.
View
35 Assignment 2/Target.java
@@ -0,0 +1,35 @@
+/*
+ * File: Target.java
+ * Name:
+ * Section Leader:
+ * -----------------
+ * This file is the starter file for the Target problem.
+ */
+
+import acm.graphics.*;
+import acm.program.*;
+import java.awt.*;
+
+public class Target extends GraphicsProgram {
+ public void run() {
+ int circle_diameter; // diameter of largest circle
+ int circle_origin_x;
+ int circle_origin_y;
+ /*
+ * Draw 3 circles from largest to smallest
+ */
+ for(int i = 3 ; i > 0 ; i--){
+ circle_diameter = 24 * i;
+ circle_origin_x = (getWidth() - circle_diameter) / 2;
+ circle_origin_y = (getHeight() - circle_diameter) / 2;
+ GOval circle = new GOval( circle_origin_x , circle_origin_y , circle_diameter, circle_diameter);
+ circle.setFilled(true);
+ if(i % 2 != 0){
+ circle.setColor(Color.RED);
+ } else {
+ circle.setColor(Color.WHITE);
+ }
+ add(circle);
+ }
+ }
+}
View
BIN Assignment 2/acm.jar
Binary file not shown.
View
7 Assignment 2/java.policy.applet
@@ -0,0 +1,7 @@
+/* AUTOMATICALLY GENERATED ON Tue Apr 16 17:20:59 EDT 2002*/
+/* DO NOT EDIT */
+
+grant {
+ permission java.security.AllPermission;
+};
+

0 comments on commit 31ec49f

Please sign in to comment.
Something went wrong with that request. Please try again.