diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..ef8a789 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,12 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate +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 diff --git a/FindRange.java b/FindRange.java old mode 100755 new mode 100644 index b662530..7f87a3b --- a/FindRange.java +++ b/FindRange.java @@ -1,16 +1,30 @@ -/* - * 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() { - /* You fill this in */ - } -} - +import acm.program.*; +class FindRange extends ConsoleProgram{ + public static int SENTINEL = 0; + public void run(){ + System.out.println("The program finds the largest and smallest values"); + + int firstNumber = readInt("Enter first number"); + int smallestNmber = firstNumber; + int largestNumber = firstNumber; + + if (firstNumber == SENTINEL) + System.out.print("You did not enter a valid value"); + else + System.out.println("you can now enter others"); + + int otherNumber = readInt("Enter other integers"); + while(true){ + + if(otherNumber <= SENTINEL){ + System.out.println(firstNumber+ "is the largest as well as th smallst"); + } + else{ + largestNumber = otherNumber; + if(otherNumber > largestNumber) + largestNumber = otherNumber; + } + System.out.print("Largest number: "+largestNumber); + } + } +} diff --git a/Hailstone.java b/Hailstone.java index 2c7a16e..67694d8 100755 --- a/Hailstone.java +++ b/Hailstone.java @@ -1,16 +1,31 @@ -/* - * 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() { - /* You fill this in */ - } -} - +/* + * 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() { + println("Enter n: "); + int n = readInt("n: "); + + while(n>1){ + if((n % 2) == 0){ + n = (n/2); + println(+n+ " is even so i make half: n/2"); + } + else if((n % 2) == 1){ + n=((3*n)+1); + println( +n+" is even so i make 3n+1"); + } + + } + + } +} + + diff --git a/ProgramHierarchy.java b/ProgramHierarchy.java index b666b6d..00e0053 100755 --- a/ProgramHierarchy.java +++ b/ProgramHierarchy.java @@ -1,18 +1,65 @@ -/* - * 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() { - /* You fill this in. */ - } -} - +/* + * 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 { + + + private static final int HEIGHT = 50; + private static final int WIDTH = 150; + + public void run() { + int x; + int y; + + x = (getWidth() - WIDTH) / 2; + y = (getHeight() - HEIGHT) /2; + + GRect Rect = new GRect(x, y, WIDTH, HEIGHT); + add(Rect); + + GLabel label1 = new GLabel("Program", (x + 50), (y + 30)); + add(label1); + + + GLine Line1 = new GLine((x + 75), (y+50), (x+75), (y+100)); + add(Line1); + + GRect Rect2 = new GRect(x, (y+100), WIDTH, HEIGHT); + add(Rect2); + + GLabel label2 = new GLabel("ConsoleProgram", (x + 30), (y + 130)); + add(label2); + + GLine Line2 = new GLine((x - 100), (y + 100), (x + 75), (y + 50)); + add(Line2); + + GRect Rect3 = new GRect((x - 175), (y + 100), WIDTH, HEIGHT); + add(Rect3); + + GLabel label3 = new GLabel("GraphicProgram", (x - 145), (y + 130)); + add(label3); + + GLine Line3 = new GLine((x + 75), (y+50), (x+250), (y+100)); + add(Line3); + + GRect Rect4 = new GRect((x+175), (y+100), WIDTH, HEIGHT); + add(Rect4); + + GLabel label4 = new GLabel("DialogProgram", (x + 210), (y + 130)); + add(label4); + + + + + } +} + diff --git a/ProgramHierarchy1496708469754.html b/ProgramHierarchy1496708469754.html new file mode 100644 index 0000000..3511966 --- /dev/null +++ b/ProgramHierarchy1496708469754.html @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Pyramid.java b/Pyramid.java index cf32252..5726d75 100755 --- a/Pyramid.java +++ b/Pyramid.java @@ -1,32 +1,38 @@ -/* - * 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 { - -/** 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; - - public void run() { - /* You fill this in. */ - } -} - +/* + * 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 { + private static final int brickWidth = 30; + private static final int brickHeight = 12; + private static final int brickInBase = 14; + + public void run() { + putAllBricks(); + } + private void putAllBricks(){ + for( int row = 0; row < brickInBase; row++ ){ + + int bricksInRow = brickInBase - row; + + for( int brickNumber = 0; brickNumber < bricksInRow; brickNumber++ ){ + int x = ( getWidth()/2 ) - (brickWidth * bricksInRow) / 2 + brickNumber * brickWidth; + int y = getHeight() - brickHeight * (row+1); + + GRect brick = new GRect( x , y , brickWidth , brickHeight ); + add(brick); + } + } + } +} diff --git a/PythagoreanTheorem.java b/PythagoreanTheorem.java index 5b4f30d..db2d2ee 100755 --- a/PythagoreanTheorem.java +++ b/PythagoreanTheorem.java @@ -1,15 +1,28 @@ -/* - * 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() { - /* You fill this in */ - } -} +/* + * 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(){ + + int a = readInt("Enter a"); + + int b = readInt("Enter b"); + + double c = Math.sqrt((a*a) + (b*b)); + + println("The ansa is " +c); + /* You fill this in */ + } + +} + diff --git a/Target.java b/Target.java index 44c1f34..82fa43b 100755 --- a/Target.java +++ b/Target.java @@ -1,17 +1,33 @@ -/* - * 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() { - /* You fill this in. */ - } -} +/* + * 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() { + GOval oval1 = new GOval(300, 137, 72, 72); + oval1.setFilled(true); + oval1.setFillColor(Color.RED); + add(oval1); + + + GOval oval2 = new GOval(310, 148, 49, 49); + oval2.setFilled(true); + oval2.setFillColor(Color.WHITE); + add(oval2); + + GOval oval3 = new GOval(318, 155, 34, 34); + oval3.setFilled(true); + oval3.setFillColor(Color.RED); + add(oval3); + + + } +} diff --git a/java.policy.applet b/java.policy.applet new file mode 100644 index 0000000..ba9f51d --- /dev/null +++ b/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; +}; +