-
Notifications
You must be signed in to change notification settings - Fork 14
bjwealthy submitting his assignment 2 #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
3bb1836
359527c
b2909a4
a8022ea
b85a4d3
7ad7944
41def3a
36b2500
016c179
bc6b77c
fdbafe1
b80bb6e
7249aa9
0f14e37
e4031d6
366d5ee
2f271ee
f3ff050
c11a998
5ed397c
b29934f
108b15c
750cb93
d2e1a7b
3e83e7c
a050b0a
fe86149
4e9cb1c
66e35b0
405d864
f726de8
d106b4e
c79ce72
177cfa3
80441ad
d07e65e
c5340c3
4de094b
84459e6
489c21c
52bb186
0a162e9
3de4731
9940c9e
84a5f04
fb3643d
b41d3ca
690af48
977f481
08bcce3
5cd2e4a
8d29fb5
764ea32
75097b4
f080472
5eb94b2
5a0c19b
c4335f1
7739428
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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"); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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.*; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Generally you should avoid the use of constant numbers in your program. You have values like (130, 175, 210...etc) throughout your code and this is not a good idea because:
If this happens your program will fail to draw the right diagram. To make it work you will have to go back and start changing all the numbers throughout your program. It should be possible to come up with a solution that works without you doing further modification. The ability of a program to be able to adapt to changes like that is called scalability. So in this case your solution is not scalable enough. |
||
| 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() { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should breakdown your program into smaller understandable methods. So the run method should have looked like this |
||
| 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); | ||
|
|
||
|
|
||
|
|
||
|
|
||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| <html> | ||
| <meta http-equiv="Content-Type" content="text/html; charset=Cp1252"/> | ||
| <body> | ||
| <applet code=ProgramHierarchy.class width="200" height="200" > | ||
| </applet> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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); | ||
| } | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "The answer " instead of "The ansa" |
||
| /* You fill this in */ | ||
| } | ||
|
|
||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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.*; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The solution does not draw the target correctly as described in the assignment. |
||
| import acm.program.*; | ||
| import java.awt.*; | ||
|
|
||
| public class Target extends GraphicsProgram { | ||
| public void run() { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The radius and pixel values should have been constants similar to what the starter code for the pyramid question had brick width, brick height and number of bricks on the base as constants. So you should have had something like this: Also again this solution is not scalable (If the assignment requirements changed to have different radiuses your program will not work) and I don't think it uses the right measurements provided by the question (specifically the radiuses: 1.0, 0.65 and 0.3) |
||
| 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); | ||
|
|
||
|
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| /* AUTOMATICALLY GENERATED ON Tue Apr 16 17:20:59 EDT 2002*/ | ||
| /* DO NOT EDIT */ | ||
|
|
||
| grant { | ||
| permission java.security.AllPermission; | ||
| }; | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your program does not print how many steps it takes to reach to value 1.