Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
dad17da
{"types":"A","runs":64}
Jun 4, 2017
46fafc4
{"types":"C","runs":65}
Jun 4, 2017
1a28096
{"types":"C","runs":67}
Jun 4, 2017
35a9653
{"types":"C","runs":70}
Jun 4, 2017
ea3eba6
{"types":"C","runs":71}
Jun 4, 2017
66aa2f8
{"types":"C","runs":72}
Jun 4, 2017
a4acfaa
{"types":"C","runs":74}
Jun 4, 2017
28dc698
{"types":"C","runs":75}
Jun 4, 2017
1399455
{"types":"C","runs":76}
Jun 4, 2017
48e22c8
{"types":"C","runs":1}
Jun 5, 2017
37ab060
{"types":"C","runs":2}
Jun 5, 2017
d4af33d
{"types":"C","runs":3}
Jun 5, 2017
9f6b722
{"types":"C","runs":4}
Jun 5, 2017
7ba4240
{"types":"C","runs":3}
Jun 5, 2017
1fd374d
{"types":"C","runs":6}
Jun 5, 2017
158ca2b
{"types":"C","runs":7}
Jun 5, 2017
6a643c6
{"types":"C","runs":8}
Jun 5, 2017
0326903
{"types":"C","runs":9}
Jun 5, 2017
fa40728
{"types":"C","runs":10}
Jun 5, 2017
4ce811a
{"types":"C","runs":2}
Jun 5, 2017
956dd05
{"types":"C","runs":3}
Jun 5, 2017
4b9377d
{"types":"C","runs":4}
Jun 5, 2017
197cb52
{"types":"C","runs":5}
Jun 5, 2017
8dd9d03
{"types":"C","runs":6}
Jun 5, 2017
28578ea
{"types":"C","runs":7}
Jun 5, 2017
e7f996a
{"types":"C","runs":8}
Jun 5, 2017
c703d88
{"types":"C","runs":12}
Jun 5, 2017
a21d61c
{"types":"C","runs":13}
Jun 5, 2017
d26930c
{"types":"C","runs":14}
Jun 5, 2017
bec7dca
{"types":"C","runs":15}
Jun 5, 2017
76efb9c
{"types":"C","runs":19}
Jun 6, 2017
8aa2436
{"types":"C","runs":20}
Jun 6, 2017
8d3ddaf
{"types":"C","runs":25}
Jun 6, 2017
220928d
{"types":"C","runs":26}
Jun 6, 2017
d9e3dfe
{"types":"C","runs":27}
Jun 6, 2017
bed295e
{"types":"C","runs":28}
Jun 6, 2017
1f12354
{"types":"C","runs":29}
Jun 6, 2017
40afa7b
{"types":"C","runs":30}
Jun 6, 2017
22df0ec
{"types":"C","runs":30}
Jun 6, 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
64 changes: 48 additions & 16 deletions FindRange.java
Original file line number Diff line number Diff line change
@@ -1,16 +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() {
/* You fill this in */
}
}

/*
* File: FindRange.java

Choose a reason for hiding this comment

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

Your program doesn't work correctly because you have an incorrect value of the SENTINEL. You set it to 20 instead of 0. Also it misses the following two edge cases:

If the user enters only one value before the sentinel, the program should report
that value as both the largest and smallest

and

If the user enters the sentinel on the very first input line, then no values have been
entered, and your program should display a message to that effect.

* Name:
* Section Leader:
* --------------------
* This file is the starter file for the FindRange problem.
*/

import acm.program.*;

public class FindRange extends ConsoleProgram {
public void run() {
/*
* This program finds the range of
* any set of numbers until the Sentinel
* value is reached
*/
println("This program finds the minimum and");
println("maximum values in a given set of numbers");






int min = 0;
int max = 0;
println("Enter a value");
while (true){

int val = readInt();
if (val == SENTINEL){
break;

}
else if(val < min){
min = val;
}
else if(val > max){
max = val;
}
}
println("The minimum value is " +min);
println("The maximum value is " +max);
}
private static final int SENTINEL = 20;

Choose a reason for hiding this comment

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

This should be 0.

}

59 changes: 43 additions & 16 deletions Hailstone.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,43 @@
/*
* 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.

Choose a reason for hiding this comment

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

Great solution.

*/

import acm.program.*;

public class Hailstone extends ConsoleProgram {
public void run() {
/* The program computes the Hailstone's sequence of any number
* entered by the user
*/

println("...");
println("Enter any number to get the Hailstone sequence: ");
int x = readInt();
int y = 0;

while (x != 1) {

if (x % 2 == 0) {

println( " " +x+ " is even, so i take half: " + x/2 );
x /= 2;
y++;

}
else{
println( " " +x+ " is odd, so i compute 3x + 1: " + (3 * x + 1) );
x = 3 * x + 1;
y++;

}

}
println("...");
println ("It took " + y + " steps to arrive at 1");
}
}

36 changes: 18 additions & 18 deletions ProgramHierarchy.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/*
* 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.*;

Choose a reason for hiding this comment

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

I suppose you didn't have enough time to code this part. :(


public class ProgramHierarchy extends GraphicsProgram {
public void run() {
/* You fill this in. */
}
}
62 changes: 30 additions & 32 deletions Pyramid.java
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
/*
* 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. */
}
}


Choose a reason for hiding this comment

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

Excellent solution.

import acm.graphics.*;
import acm.program.*;
import java.awt.*;

public class Pyramid extends GraphicsProgram {
private static final int BRICKS_IN_BASE = 32;
private static final int BRICK_WIDTH = 20;
private static final int BRICK_HEIGHT = 14;
public void run() {
/* You fill this in. */
double x = (getWidth() - BRICKS_IN_BASE * BRICK_WIDTH) / 2;
double y = getHeight() - BRICK_HEIGHT;
for (int row = 0; row < BRICKS_IN_BASE; row++) {
createRow(x, y, (BRICKS_IN_BASE - row));
y -= BRICK_HEIGHT;
x += BRICK_WIDTH / 2;
}
}
private void createRow(double x, double y, int bricks) {
for (int i = 0; i < bricks; i++) {
createBrick((x + i * BRICK_WIDTH), y);
}
}

private void createBrick(double x, double y) {
GRect rect = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT);
add(rect);
}
}
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 */
}
}
/*

Choose a reason for hiding this comment

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

Excellent solution.

* 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 */
println("*********************************************************");
println("Enter the values of A and B to compute Pythagoras theorem");
int a = readInt ("A = ");
println("");
int b = readInt ("B = ");

int c = ((a*a) + (b*b));

double x = Math.sqrt (c);
println("");
println("The answer is " +x);
println("*********************************************************");

}
}
59 changes: 42 additions & 17 deletions Target.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,42 @@
/*
* 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. */
}
}
/*

Choose a reason for hiding this comment

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

Great solution. Just a few technical issues.

* 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() {
/*
* This program draws an archery target
*/

Choose a reason for hiding this comment

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

These values should have been declared as constants outside of the run method. So something like:

private static final int INCH_TO_PIX = 72;
private static final double MAXI_RADIUS = 1 * INCH_TO_PIX;
private static final double MEDI_RADIUS = 0.65 * INCH_TO_PIX;
private static final double MINI_RADIUS = 0.3 * INCH_TO_PIX;

double inch2Pix = 72;

double maxiRadius = 1 * inch2Pix;
double mediRadius = 0.65 * inch2Pix;
double miniRadius = 0.30 * inch2Pix;

double x = getWidth()/2;
double y = getHeight()/2;

GOval maxiTarget = new GOval(x - maxiRadius, y - maxiRadius, 2 * maxiRadius, 2 * maxiRadius);
maxiTarget.setFilled(true);
maxiTarget.setColor(Color.RED);
add(maxiTarget);

GOval mediTarget = new GOval(x - mediRadius, y - mediRadius, 2 * mediRadius, 2 * mediRadius);
mediTarget.setFilled(true);
mediTarget.setColor(Color.WHITE);
add(mediTarget);

GOval miniTarget = new GOval(x - miniRadius, y - miniRadius, 2 * miniRadius, 2 * miniRadius);
miniTarget.setFilled(true);
miniTarget.setColor(Color.RED);
add(miniTarget);
}

Choose a reason for hiding this comment

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

The operation to draw the circles should have been done in a method since they all share code. So something like this:

private void drawCircle(double centerX, double centerY, double rad, Color c) {
    GOval circle = new GOval(centerX - rad, centerY - rad, 2*rad, 2*rad);
    circle.setColor(c); 
    circle.setFillColor(c);
    circle.setFilled (true);
    add (circle);
}

}