Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
3bb1836
{"types":"A","runs":4}
Jun 3, 2017
359527c
{"types":"C","runs":5}
Jun 3, 2017
b2909a4
{"types":"C","runs":0}
Jun 3, 2017
a8022ea
{"types":"C","runs":1}
Jun 3, 2017
b85a4d3
{"types":"C","runs":2}
Jun 3, 2017
7ad7944
{"types":"C","runs":31}
Jun 4, 2017
41def3a
{"types":"C","runs":0}
Jun 5, 2017
36b2500
{"types":"C","runs":1}
Jun 5, 2017
016c179
{"types":"C","runs":6}
Jun 5, 2017
bc6b77c
{"types":"C","runs":1}
Jun 5, 2017
fdbafe1
{"types":"C","runs":4}
Jun 5, 2017
b80bb6e
{"types":"C","runs":6}
Jun 5, 2017
7249aa9
{"types":"C","runs":7}
Jun 5, 2017
0f14e37
{"types":"C","runs":8}
Jun 5, 2017
e4031d6
{"types":"C","runs":9}
Jun 6, 2017
366d5ee
{"types":"C","runs":10}
Jun 6, 2017
2f271ee
{"types":"C","runs":12}
Jun 6, 2017
f3ff050
{"types":"C","runs":13}
Jun 6, 2017
c11a998
{"types":"C","runs":14}
Jun 6, 2017
5ed397c
{"types":"C","runs":15}
Jun 6, 2017
b29934f
{"types":"C","runs":16}
Jun 6, 2017
108b15c
{"types":"C","runs":17}
Jun 6, 2017
750cb93
{"types":"C","runs":18}
Jun 6, 2017
d2e1a7b
{"types":"C","runs":1}
Jun 6, 2017
3e83e7c
{"types":"C","runs":2}
Jun 6, 2017
a050b0a
{"types":"C","runs":3}
Jun 6, 2017
fe86149
{"types":"C","runs":4}
Jun 6, 2017
4e9cb1c
{"types":"C","runs":5}
Jun 6, 2017
66e35b0
{"types":"C","runs":6}
Jun 6, 2017
405d864
{"types":"C","runs":7}
Jun 6, 2017
f726de8
{"types":"C","runs":8}
Jun 6, 2017
d106b4e
{"types":"C","runs":9}
Jun 6, 2017
c79ce72
{"types":"C","runs":10}
Jun 6, 2017
177cfa3
{"types":"C","runs":11}
Jun 6, 2017
80441ad
{"types":"C","runs":12}
Jun 6, 2017
d07e65e
{"types":"C","runs":13}
Jun 6, 2017
c5340c3
{"types":"C","runs":14}
Jun 6, 2017
4de094b
{"types":"C","runs":15}
Jun 6, 2017
84459e6
{"types":"C","runs":16}
Jun 6, 2017
489c21c
{"types":"C","runs":17}
Jun 6, 2017
52bb186
{"types":"C","runs":18}
Jun 6, 2017
0a162e9
{"types":"C","runs":19}
Jun 6, 2017
3de4731
{"types":"C","runs":22}
Jun 6, 2017
9940c9e
{"types":"C","runs":22}
Jun 6, 2017
84a5f04
submitting my assignment 2
bjwealthy Jun 6, 2017
fb3643d
{"types":"C","runs":0}
Jun 6, 2017
b41d3ca
{"types":"C","runs":2}
Jun 6, 2017
690af48
{"types":"C","runs":3}
Jun 6, 2017
977f481
{"types":"C","runs":24}
Jun 13, 2017
08bcce3
{"types":"C","runs":1}
Jun 13, 2017
5cd2e4a
{"types":"C","runs":1}
Jun 29, 2017
8d29fb5
changes to range
bjwealthy Jun 29, 2017
764ea32
{"types":"R","runs":1}
Jun 29, 2017
75097b4
{"types":"A","runs":1}
Jun 29, 2017
f080472
{"types":"R","runs":1}
Jun 29, 2017
5eb94b2
{"types":"A","runs":1}
Jun 29, 2017
5a0c19b
{"types":"C","runs":46}
Jun 29, 2017
c4335f1
{"types":"C","runs":1}
Jun 29, 2017
7739428
{"types":"C","runs":4}
Jun 29, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs
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
46 changes: 30 additions & 16 deletions FindRange.java
100755 → 100644
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);
}
}
}
47 changes: 31 additions & 16 deletions Hailstone.java
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.*;

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.


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");
}

}

}
}


83 changes: 65 additions & 18 deletions ProgramHierarchy.java
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.*;

Choose a reason for hiding this comment

The 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:

  1. Someone reading your code will be confused how you came up with them
  2. If requirements change your program will be really hard to update. For example imagine for this exercise the requirements changed and we decide that the value for HEIGHT (50) and WIDTH (150) should be changed to HEIGHT = 60 and WIDTH = 180

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() {

Choose a reason for hiding this comment

The 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

public void run() {
    drawProgramBox();
    drawConsoleLine();
    drawConsoleBox();
    drawGraphicsLine();
    drawGraphicsBox();
    drawDialogLine();
    drawDialogBox();
}

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);




}
}

7 changes: 7 additions & 0 deletions ProgramHierarchy1496708469754.html
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>
70 changes: 38 additions & 32 deletions Pyramid.java
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);
}
}
}
}
43 changes: 28 additions & 15 deletions PythagoreanTheorem.java
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);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"The answer " instead of "The ansa"

/* You fill this in */
}

}

50 changes: 33 additions & 17 deletions Target.java
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.*;

Choose a reason for hiding this comment

The 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() {

Choose a reason for hiding this comment

The 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:

private static final int PIXELS_PER_INCH = 72;
private static final double RADIUS_OUTER_CIRCLE = 1.0;
private static final double RADIUS_WHITE_CIRCLE = 0.65;
private static final double RADIUS_INNER_CIRCLE = 0.3;

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);


}
}
7 changes: 7 additions & 0 deletions java.policy.applet
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;
};