From dad17daa87a18723a167636d65cd0e628dd09323 Mon Sep 17 00:00:00 2001 From: S Date: Sun, 4 Jun 2017 15:17:20 +0100 Subject: [PATCH 01/39] {"types":"A","runs":64} --- FindRange.java | 32 ++++++++++----------- Hailstone.java | 32 ++++++++++----------- ProgramHierarchy.java | 36 +++++++++++------------ Pyramid.java | 64 ++++++++++++++++++++--------------------- PythagoreanTheorem.java | 30 +++++++++---------- Target.java | 34 +++++++++++----------- 6 files changed, 114 insertions(+), 114 deletions(-) diff --git a/FindRange.java b/FindRange.java index b662530..416b172 100755 --- a/FindRange.java +++ b/FindRange.java @@ -1,16 +1,16 @@ -/* - * 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 + * 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 */ + } +} + diff --git a/Hailstone.java b/Hailstone.java index 2c7a16e..17a27fe 100755 --- a/Hailstone.java +++ b/Hailstone.java @@ -1,16 +1,16 @@ -/* - * 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() { + /* You fill this in */ + } +} + diff --git a/ProgramHierarchy.java b/ProgramHierarchy.java index b666b6d..4d425c7 100755 --- a/ProgramHierarchy.java +++ b/ProgramHierarchy.java @@ -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.*; + +public class ProgramHierarchy extends GraphicsProgram { + public void run() { + /* You fill this in. */ + } +} + diff --git a/Pyramid.java b/Pyramid.java index cf32252..82c2c2a 100755 --- a/Pyramid.java +++ b/Pyramid.java @@ -1,32 +1,32 @@ -/* - * 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 { + +/** 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. */ + } +} + diff --git a/PythagoreanTheorem.java b/PythagoreanTheorem.java index 5b4f30d..f774a30 100755 --- a/PythagoreanTheorem.java +++ b/PythagoreanTheorem.java @@ -1,15 +1,15 @@ -/* - * 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() { + /* You fill this in */ + } +} diff --git a/Target.java b/Target.java index 44c1f34..5f0e0a1 100755 --- a/Target.java +++ b/Target.java @@ -1,17 +1,17 @@ -/* - * 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() { + /* You fill this in. */ + } +} From 46fafc40c1b66a357c3a62c254b3240dfe6f5b53 Mon Sep 17 00:00:00 2001 From: S Date: Sun, 4 Jun 2017 15:56:19 +0100 Subject: [PATCH 02/39] {"types":"C","runs":65} --- Pyramid.java | 1 + 1 file changed, 1 insertion(+) diff --git a/Pyramid.java b/Pyramid.java index 82c2c2a..9c2c6af 100755 --- a/Pyramid.java +++ b/Pyramid.java @@ -27,6 +27,7 @@ public class Pyramid extends GraphicsProgram { public void run() { /* You fill this in. */ + add(new GRect(375, 450, 25, 20)); } } From 1a2809620960620972c5410ecdd6c1795a4a3d2b Mon Sep 17 00:00:00 2001 From: S Date: Sun, 4 Jun 2017 16:18:37 +0100 Subject: [PATCH 03/39] {"types":"C","runs":67} --- Pyramid.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/Pyramid.java b/Pyramid.java index 9c2c6af..7739fe5 100755 --- a/Pyramid.java +++ b/Pyramid.java @@ -27,7 +27,20 @@ public class Pyramid extends GraphicsProgram { public void run() { /* You fill this in. */ - add(new GRect(375, 450, 25, 20)); + /* You fill this in. */ + int startY = getHeight()-BRICK_HEIGHT; + int startX; + for (int i = BRICKS_IN_BASE; i >0; i--) + { + startX = getWidth() / 2; + startX -= i * (BRICK_WIDTH/2); + for (int j = i; j > 0; j--) + { + GRect rect = new GRect(startX,startY,BRICK_WIDTH,BRICK_HEIGHT); + add(rect); + startX += BRICK_WIDTH; + } + startY -= BRICK_HEIGHT; + } } } - From 35a9653221b6acb608b25ed213f7f28957e9deda Mon Sep 17 00:00:00 2001 From: S Date: Sun, 4 Jun 2017 16:37:29 +0100 Subject: [PATCH 04/39] {"types":"C","runs":70} --- Pyramid.java | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/Pyramid.java b/Pyramid.java index 7739fe5..258d5b3 100755 --- a/Pyramid.java +++ b/Pyramid.java @@ -23,24 +23,17 @@ public class Pyramid extends GraphicsProgram { private static final int BRICK_HEIGHT = 12; /** Number of bricks in the base of the pyramid */ - private static final int BRICKS_IN_BASE = 14; + private static final int BRICKS_IN_BASE = 12; public void run() { /* You fill this in. */ - /* You fill this in. */ - int startY = getHeight()-BRICK_HEIGHT; - int startX; - for (int i = BRICKS_IN_BASE; i >0; i--) - { - startX = getWidth() / 2; - startX -= i * (BRICK_WIDTH/2); - for (int j = i; j > 0; j--) - { - GRect rect = new GRect(startX,startY,BRICK_WIDTH,BRICK_HEIGHT); - add(rect); - startX += BRICK_WIDTH; - } - startY -= BRICK_HEIGHT; + int centreX = getWidth()/2; + int bottomY = getHeight(); + for(int i=BRICKS_IN_BASE; i >0; i--){ + for(int j = BRICKS_IN_BASE; j >0; j--){ + GRect gBrick = new GRect(centreX - j*BRICK_WIDTH/2, bottomY - BRICK_HEIGHT*(i-(i-8)), BRICK_WIDTH, BRICK_HEIGHT); + add(gBrick); + } } } } From ea3eba6a8ef17fbbeb7809bfa3ca90b0117ba764 Mon Sep 17 00:00:00 2001 From: S Date: Sun, 4 Jun 2017 16:51:13 +0100 Subject: [PATCH 05/39] {"types":"C","runs":71} --- Pyramid.java | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/Pyramid.java b/Pyramid.java index 258d5b3..a4c57ad 100755 --- a/Pyramid.java +++ b/Pyramid.java @@ -27,13 +27,24 @@ public class Pyramid extends GraphicsProgram { public void run() { /* You fill this in. */ - int centreX = getWidth()/2; - int bottomY = getHeight(); - for(int i=BRICKS_IN_BASE; i >0; i--){ - for(int j = BRICKS_IN_BASE; j >0; j--){ - GRect gBrick = new GRect(centreX - j*BRICK_WIDTH/2, bottomY - BRICK_HEIGHT*(i-(i-8)), BRICK_WIDTH, BRICK_HEIGHT); - add(gBrick); - } + int totalPyramidWidth = BRICK_WIDTH * BRICKS_IN_BASE; + int totalPyramidHeight = BRICK_HEIGHT * BRICKS_IN_BASE; + int startingHeight = getHeight() - 0; + int startingWidth = (getWidth() - totalPyramidWidth) / 2; + int size = BRICKS_IN_BASE + 1; + int x = startingWidth; + for (int j = 0; j < BRICKS_IN_BASE; j++) + { + size--; + int pyramidWidth = size * BRICK_WIDTH; + x = (getWidth() - pyramidWidth) / 2; + startingHeight -= BRICK_HEIGHT; + for (int i = 0; i < size; i++) + { + GRect brick = new GRect(x, startingHeight, BRICK_WIDTH, BRICK_HEIGHT); + add(brick); + x += BRICK_WIDTH; + } } - } -} + } +} \ No newline at end of file From 66aa2f8b11277beb81d57b824f3775bd8dcf9a09 Mon Sep 17 00:00:00 2001 From: S Date: Sun, 4 Jun 2017 16:53:03 +0100 Subject: [PATCH 06/39] {"types":"C","runs":72} --- Pyramid.java | 136 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 116 insertions(+), 20 deletions(-) diff --git a/Pyramid.java b/Pyramid.java index a4c57ad..49903b0 100755 --- a/Pyramid.java +++ b/Pyramid.java @@ -27,24 +27,120 @@ public class Pyramid extends GraphicsProgram { public void run() { /* You fill this in. */ - int totalPyramidWidth = BRICK_WIDTH * BRICKS_IN_BASE; - int totalPyramidHeight = BRICK_HEIGHT * BRICKS_IN_BASE; - int startingHeight = getHeight() - 0; - int startingWidth = (getWidth() - totalPyramidWidth) / 2; - int size = BRICKS_IN_BASE + 1; - int x = startingWidth; - for (int j = 0; j < BRICKS_IN_BASE; j++) - { - size--; - int pyramidWidth = size * BRICK_WIDTH; - x = (getWidth() - pyramidWidth) / 2; - startingHeight -= BRICK_HEIGHT; - for (int i = 0; i < size; i++) - { - GRect brick = new GRect(x, startingHeight, BRICK_WIDTH, BRICK_HEIGHT); - add(brick); - x += BRICK_WIDTH; - } - } - } + int initBrick = 30; + int initPlacement = (getWidth() - BRICK_WIDTH) / 2; + + for (int i = 0; i < initBrick; i += 30) + { + int initX = i; + int x = initX + initPlacement; + GRect brick = new GRect(x, 0, BRICK_WIDTH, BRICK_HEIGHT); + add(brick); + } + for (int i = 0; i < 60; i += 30) + { + int initX = i; + int x = (initX + initPlacement) - 15; + int y = 12; + GRect brick = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT); + add(brick); + } + for (int i = 0; i < 90; i += 30) + { + int initX = i; + int x = (initX + initPlacement) - 30; + int y = 24; + GRect brick = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT); + add(brick); + } + for (int i = 0; i < 120; i += 30) + { + int initX = i; + int x = (initX + initPlacement) - 45; + int y = 36; + GRect brick = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT); + add(brick); + } + for (int i = 0; i < 150; i += 30) + { + int initX = i; + int x = (initX + initPlacement) - 60; + int y = 48; + GRect brick = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT); + add(brick); + } + for (int i = 0; i < 180; i += 30) + { + int initX = i; + int x = (initX + initPlacement) - 75; + int y = 60; + GRect brick = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT); + add(brick); + } + for (int i = 0; i < 210; i += 30) + { + int initX = i; + int x = (initX + initPlacement) - 90; + int y = 72; + GRect brick = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT); + add(brick); + } + for (int i = 0; i < 240; i += 30) + { + int initX = i; + int x = (initX + initPlacement) - 105; + int y = 84; + GRect brick = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT); + add(brick); + } + for (int i = 0; i < 270; i += 30) + { + int initX = i; + int x = (initX + initPlacement) - 120; + int y = 96; + GRect brick = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT); + add(brick); + } + for (int i = 0; i < 300; i += 30) + { + int initX = i; + int x = (initX + initPlacement) - 135; + int y = 108; + GRect brick = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT); + add(brick); + } + for (int i = 0; i < 330; i += 30) + { + int initX = i; + int x = (initX + initPlacement) - 150; + int y = 120; + GRect brick = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT); + add(brick); + } + for (int i = 0; i < 360; i += 30) + { + int initX = i; + int x = (initX + initPlacement) - 165; + int y = 132; + GRect brick = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT); + add(brick); + } + for (int i = 0; i < 390; i += 30) + { + int initX = i; + int x = (initX + initPlacement) - 180; + int y = 144; + GRect brick = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT); + add(brick); + } + for (int i = 0; i < 420; i += 30) + { + int initX = i; + int x = (initX + initPlacement) - 195; + int y = 156; + GRect brick = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT); + add(brick); + } + + } } \ No newline at end of file From a4acfaaa912e869359ed7897e77cd7157dbf61b4 Mon Sep 17 00:00:00 2001 From: S Date: Sun, 4 Jun 2017 16:56:06 +0100 Subject: [PATCH 07/39] {"types":"C","runs":74} --- Pyramid.java | 181 +++++++++++++++------------------------------------ 1 file changed, 53 insertions(+), 128 deletions(-) diff --git a/Pyramid.java b/Pyramid.java index 49903b0..2db5a50 100755 --- a/Pyramid.java +++ b/Pyramid.java @@ -11,136 +11,61 @@ */ 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 = 12; - - public void run() { - /* You fill this in. */ - int initBrick = 30; - int initPlacement = (getWidth() - BRICK_WIDTH) / 2; - - for (int i = 0; i < initBrick; i += 30) - { - int initX = i; - int x = initX + initPlacement; - GRect brick = new GRect(x, 0, BRICK_WIDTH, BRICK_HEIGHT); - add(brick); - } - for (int i = 0; i < 60; i += 30) - { - int initX = i; - int x = (initX + initPlacement) - 15; - int y = 12; - GRect brick = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT); - add(brick); - } - for (int i = 0; i < 90; i += 30) - { - int initX = i; - int x = (initX + initPlacement) - 30; - int y = 24; - GRect brick = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT); - add(brick); - } - for (int i = 0; i < 120; i += 30) - { - int initX = i; - int x = (initX + initPlacement) - 45; - int y = 36; - GRect brick = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT); - add(brick); - } - for (int i = 0; i < 150; i += 30) - { - int initX = i; - int x = (initX + initPlacement) - 60; - int y = 48; - GRect brick = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT); - add(brick); - } - for (int i = 0; i < 180; i += 30) - { - int initX = i; - int x = (initX + initPlacement) - 75; - int y = 60; - GRect brick = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT); - add(brick); - } - for (int i = 0; i < 210; i += 30) - { - int initX = i; - int x = (initX + initPlacement) - 90; - int y = 72; - GRect brick = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT); - add(brick); - } - for (int i = 0; i < 240; i += 30) - { - int initX = i; - int x = (initX + initPlacement) - 105; - int y = 84; - GRect brick = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT); - add(brick); - } - for (int i = 0; i < 270; i += 30) - { - int initX = i; - int x = (initX + initPlacement) - 120; - int y = 96; - GRect brick = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT); - add(brick); - } - for (int i = 0; i < 300; i += 30) - { - int initX = i; - int x = (initX + initPlacement) - 135; - int y = 108; - GRect brick = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT); - add(brick); - } - for (int i = 0; i < 330; i += 30) - { - int initX = i; - int x = (initX + initPlacement) - 150; - int y = 120; - GRect brick = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT); - add(brick); - } - for (int i = 0; i < 360; i += 30) - { - int initX = i; - int x = (initX + initPlacement) - 165; - int y = 132; - GRect brick = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT); - add(brick); - } - for (int i = 0; i < 390; i += 30) - { - int initX = i; - int x = (initX + initPlacement) - 180; - int y = 144; - GRect brick = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT); - add(brick); - } - for (int i = 0; i < 420; i += 30) - { - int initX = i; - int x = (initX + initPlacement) - 195; - int y = 156; - GRect brick = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT); - add(brick); - } - - } +/* Defining the constants values */ + + private static final int BRICK_WIDTH = 30; + + private static final int BRICK_HEIGHT = 12; + + private static final int BRICKS_IN_BASE = 14; + + + +/* Defining the position of the PYRAMID */ + + public void run() { + + double x = getWidth() / 2-BRICK_WIDTH; + + double y = getHeight() - BRICKS_IN_BASE * BRICK_HEIGHT; + + + +/* For loop draws the current row then evaluates the x and y of the row beneath.*/ + + for (int i = 0; i < BRICKS_IN_BASE; i++) { + + drawRow(x, y, i); + + y += BRICK_HEIGHT; + + x -= BRICK_WIDTH / 2; + + } + + } + + + +/* Draw bricks in current row */ + + private void drawRow(double x, double y, int count) { + + for (int i = 0; i <= count; i++) { + + add(new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT)); + + x += BRICK_WIDTH; + + } + + + + } + } \ No newline at end of file From 28dc698944cb1cb27a43061737c5f54340942faa Mon Sep 17 00:00:00 2001 From: S Date: Sun, 4 Jun 2017 16:59:41 +0100 Subject: [PATCH 08/39] {"types":"C","runs":75} --- Pyramid.java | 102 +++++++++++++++++++-------------------------------- 1 file changed, 37 insertions(+), 65 deletions(-) diff --git a/Pyramid.java b/Pyramid.java index 2db5a50..d3df5cf 100755 --- a/Pyramid.java +++ b/Pyramid.java @@ -1,71 +1,43 @@ -/* - * 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 { - -/* Defining the constants values */ - - private static final int BRICK_WIDTH = 30; - - private static final int BRICK_HEIGHT = 12; - - private static final int BRICKS_IN_BASE = 14; - - - -/* Defining the position of the PYRAMID */ - - public void run() { - - double x = getWidth() / 2-BRICK_WIDTH; - - double y = getHeight() - BRICKS_IN_BASE * BRICK_HEIGHT; - - - -/* For loop draws the current row then evaluates the x and y of the row beneath.*/ - - for (int i = 0; i < BRICKS_IN_BASE; i++) { - - drawRow(x, y, i); - - y += BRICK_HEIGHT; - - x -= BRICK_WIDTH / 2; - - } - - } - - - -/* Draw bricks in current row */ - - private void drawRow(double x, double y, int count) { - - for (int i = 0; i <= count; i++) { - - add(new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT)); - - x += BRICK_WIDTH; - - } - - - } - +/** Width of each brick in pixels */ + private static final int BRICK_WIDTH = 40; + +/** Height 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; + +/** New window size */ + private static final int WINDOW_WIDTH = 800; + private static final int WINDOW_HEIGHT = 400; + + public void run() { + + int brick_level = 0; + int brick_order = 0; + int x, y; + + setSize(WINDOW_WIDTH, WINDOW_HEIGHT); // adapting the window + + // looping through each brick level + for (brick_level = 0; brick_level <= BRICKS_IN_BASE - 1; brick_level++) { + + // looping through each brick for a particular level + for (brick_order = 0; brick_order <= BRICKS_IN_BASE - brick_level - 1; brick_order++) { + + x = (WINDOW_WIDTH - BRICK_WIDTH * (BRICKS_IN_BASE - brick_level)) / 2 + BRICK_WIDTH * brick_order; + y = WINDOW_HEIGHT - BRICK_HEIGHT * (brick_level + 1); + GRect rectangle = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT); + add(rectangle); + + } + } + } } \ No newline at end of file From 13994553ce4d758d2284c8aa0400c3d0396c3596 Mon Sep 17 00:00:00 2001 From: S Date: Sun, 4 Jun 2017 17:19:54 +0100 Subject: [PATCH 09/39] {"types":"C","runs":76} --- Pyramid.java | 70 ++++++++++++++++++++++------------------------------ 1 file changed, 29 insertions(+), 41 deletions(-) diff --git a/Pyramid.java b/Pyramid.java index d3df5cf..d03c9b0 100755 --- a/Pyramid.java +++ b/Pyramid.java @@ -1,43 +1,31 @@ -import acm.graphics.*; -import acm.program.*; -import java.awt.*; + 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 = 40; - -/** Height 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; - -/** New window size */ - private static final int WINDOW_WIDTH = 800; - private static final int WINDOW_HEIGHT = 400; - - public void run() { - - int brick_level = 0; - int brick_order = 0; - int x, y; - - setSize(WINDOW_WIDTH, WINDOW_HEIGHT); // adapting the window - - // looping through each brick level - for (brick_level = 0; brick_level <= BRICKS_IN_BASE - 1; brick_level++) { - - // looping through each brick for a particular level - for (brick_order = 0; brick_order <= BRICKS_IN_BASE - brick_level - 1; brick_order++) { - - x = (WINDOW_WIDTH - BRICK_WIDTH * (BRICKS_IN_BASE - brick_level)) / 2 + BRICK_WIDTH * brick_order; - y = WINDOW_HEIGHT - BRICK_HEIGHT * (brick_level + 1); - GRect rectangle = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT); - add(rectangle); - - } - } - } -} \ No newline at end of file + public class Pyramid extends GraphicsProgram { + private static final int BRICKS_IN_BASE = 14; + private static final int BRICK_WIDTH = 30; + private static final int BRICK_HEIGHT = 12; + 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++) { + drawRow(x, y, BRICKS_IN_BASE - row); + y -= BRICK_HEIGHT; + x += BRICK_WIDTH / 2; + } + } + private void drawRow(double x, double y, int bricks) { + for (int i = 0; i < bricks; i++) { + drawBrick(x + i * BRICK_WIDTH, y); + } + } + + private void drawBrick(double x, double y) { + GRect rect = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT); + rect.setColor(Color.BLACK); + add(rect); + } + } \ No newline at end of file From 48e22c8c8da58b90bd6c39a65b29b816c4adb7dd Mon Sep 17 00:00:00 2001 From: S Date: Mon, 5 Jun 2017 08:55:17 +0100 Subject: [PATCH 10/39] {"types":"C","runs":1} From 37ab06001ac9e1ba2e582af4c1503b782e77a60b Mon Sep 17 00:00:00 2001 From: S Date: Mon, 5 Jun 2017 09:15:04 +0100 Subject: [PATCH 11/39] {"types":"C","runs":2} --- Pyramid.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Pyramid.java b/Pyramid.java index d03c9b0..a2dc357 100755 --- a/Pyramid.java +++ b/Pyramid.java @@ -8,18 +8,18 @@ public class Pyramid extends GraphicsProgram { private static final int BRICK_WIDTH = 30; private static final int BRICK_HEIGHT = 12; public void run() { - /* You fill this in. */ + /* 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++) { - drawRow(x, y, BRICKS_IN_BASE - row); + drawRow(x, y, (BRICKS_IN_BASE - row)); y -= BRICK_HEIGHT; x += BRICK_WIDTH / 2; } } private void drawRow(double x, double y, int bricks) { for (int i = 0; i < bricks; i++) { - drawBrick(x + i * BRICK_WIDTH, y); + drawBrick((x + i * BRICK_WIDTH), y); } } From d4af33d33c0adc30842898be4ff548c711230a3f Mon Sep 17 00:00:00 2001 From: S Date: Mon, 5 Jun 2017 09:18:00 +0100 Subject: [PATCH 12/39] {"types":"C","runs":3} --- Pyramid.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Pyramid.java b/Pyramid.java index a2dc357..1f9ebcd 100755 --- a/Pyramid.java +++ b/Pyramid.java @@ -11,7 +11,7 @@ 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++) { + for (int row = 0; row < BRICKS_IN_BASE; row++) { drawRow(x, y, (BRICKS_IN_BASE - row)); y -= BRICK_HEIGHT; x += BRICK_WIDTH / 2; From 9f6b72232b927edbf2a144495867aaf6dcc82107 Mon Sep 17 00:00:00 2001 From: S Date: Mon, 5 Jun 2017 09:49:43 +0100 Subject: [PATCH 13/39] {"types":"C","runs":4} From 7ba4240be66a4f9a0c42afe333b88f968d1ced26 Mon Sep 17 00:00:00 2001 From: S Date: Mon, 5 Jun 2017 11:58:39 +0100 Subject: [PATCH 14/39] {"types":"C","runs":3} From 1fd374de6f9b1bab0aba9d809ca8d0c147627ecb Mon Sep 17 00:00:00 2001 From: S Date: Mon, 5 Jun 2017 12:06:33 +0100 Subject: [PATCH 15/39] {"types":"C","runs":6} --- Pyramid.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Pyramid.java b/Pyramid.java index 1f9ebcd..bf7e0e0 100755 --- a/Pyramid.java +++ b/Pyramid.java @@ -4,9 +4,9 @@ import java.awt.*; public class Pyramid extends GraphicsProgram { - private static final int BRICKS_IN_BASE = 14; - private static final int BRICK_WIDTH = 30; - private static final int BRICK_HEIGHT = 12; + private static final int BRICKS_IN_BASE = 18; + private static final int BRICK_WIDTH = 32; + private static final int BRICK_HEIGHT = 15; public void run() { /* You fill this in. */ double x = (getWidth() - BRICKS_IN_BASE * BRICK_WIDTH) / 2; From 158ca2be5fcb228bfaf165c02953d65b9d2751ca Mon Sep 17 00:00:00 2001 From: S Date: Mon, 5 Jun 2017 12:07:43 +0100 Subject: [PATCH 16/39] {"types":"C","runs":7} --- Pyramid.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Pyramid.java b/Pyramid.java index bf7e0e0..8e148f0 100755 --- a/Pyramid.java +++ b/Pyramid.java @@ -4,9 +4,9 @@ import java.awt.*; public class Pyramid extends GraphicsProgram { - private static final int BRICKS_IN_BASE = 18; - private static final int BRICK_WIDTH = 32; - private static final int BRICK_HEIGHT = 15; + private static final int BRICKS_IN_BASE = 35; + private static final int BRICK_WIDTH = 15; + private static final int BRICK_HEIGHT = 14; public void run() { /* You fill this in. */ double x = (getWidth() - BRICKS_IN_BASE * BRICK_WIDTH) / 2; From 6a643c6e569ae2e0e497da39b958af2d50f51dbb Mon Sep 17 00:00:00 2001 From: S Date: Mon, 5 Jun 2017 12:08:04 +0100 Subject: [PATCH 17/39] {"types":"C","runs":8} --- Pyramid.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Pyramid.java b/Pyramid.java index 8e148f0..d46bf69 100755 --- a/Pyramid.java +++ b/Pyramid.java @@ -4,7 +4,7 @@ import java.awt.*; public class Pyramid extends GraphicsProgram { - private static final int BRICKS_IN_BASE = 35; + private static final int BRICKS_IN_BASE = 32; private static final int BRICK_WIDTH = 15; private static final int BRICK_HEIGHT = 14; public void run() { From 0326903b928488ff5bdd90ac75e9498ecec51821 Mon Sep 17 00:00:00 2001 From: S Date: Mon, 5 Jun 2017 12:26:58 +0100 Subject: [PATCH 18/39] {"types":"C","runs":9} --- Pyramid.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Pyramid.java b/Pyramid.java index d46bf69..1e0c505 100755 --- a/Pyramid.java +++ b/Pyramid.java @@ -12,20 +12,19 @@ public void run() { double x = (getWidth() - BRICKS_IN_BASE * BRICK_WIDTH) / 2; double y = getHeight() - BRICK_HEIGHT; for (int row = 0; row < BRICKS_IN_BASE; row++) { - drawRow(x, y, (BRICKS_IN_BASE - row)); + createRow(x, y, (BRICKS_IN_BASE - row)); y -= BRICK_HEIGHT; x += BRICK_WIDTH / 2; } } - private void drawRow(double x, double y, int bricks) { + private void createRow(double x, double y, int bricks) { for (int i = 0; i < bricks; i++) { - drawBrick((x + i * BRICK_WIDTH), y); + createBrick((x + i * BRICK_WIDTH), y); } } - private void drawBrick(double x, double y) { + private void createBrick(double x, double y) { GRect rect = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT); - rect.setColor(Color.BLACK); add(rect); } } \ No newline at end of file From fa407281eabbdabc08cf2689411f3ee97d570231 Mon Sep 17 00:00:00 2001 From: S Date: Mon, 5 Jun 2017 12:28:23 +0100 Subject: [PATCH 19/39] {"types":"C","runs":10} --- Pyramid.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Pyramid.java b/Pyramid.java index 1e0c505..aa3ff12 100755 --- a/Pyramid.java +++ b/Pyramid.java @@ -5,7 +5,7 @@ public class Pyramid extends GraphicsProgram { private static final int BRICKS_IN_BASE = 32; - private static final int BRICK_WIDTH = 15; + private static final int BRICK_WIDTH = 20; private static final int BRICK_HEIGHT = 14; public void run() { /* You fill this in. */ From 4ce811a0ef74ac236263c5bee8b1e6f49230f406 Mon Sep 17 00:00:00 2001 From: S Date: Mon, 5 Jun 2017 15:25:18 +0100 Subject: [PATCH 20/39] {"types":"C","runs":2} --- Hailstone.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Hailstone.java b/Hailstone.java index 17a27fe..87a2133 100755 --- a/Hailstone.java +++ b/Hailstone.java @@ -11,6 +11,24 @@ public class Hailstone extends ConsoleProgram { public void run() { /* You fill this in */ + int x = readInt("?"); + int y = 0; + + while (x != 1) { + + if (x % 2 == 0) { + + println( x+ " is even, so i take half: " + x/2 ); + y++; + + } + else{ + println( x+ " is odd, so i compute 3x + 1: " + 3 * x + 1 ); + y++; + } + + println ("It took " + y + " to arrive at 1"); + } } } From 956dd0540e0b45ae3d77a3de79386e461d80238f Mon Sep 17 00:00:00 2001 From: S Date: Mon, 5 Jun 2017 15:26:43 +0100 Subject: [PATCH 21/39] {"types":"C","runs":3} --- Hailstone.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Hailstone.java b/Hailstone.java index 87a2133..d3a7abf 100755 --- a/Hailstone.java +++ b/Hailstone.java @@ -23,7 +23,7 @@ public void run() { } else{ - println( x+ " is odd, so i compute 3x + 1: " + 3 * x + 1 ); + println( x+ " is odd, so i compute 3x + 1: " + (3 * x + 1) ); y++; } From 4b9377d42227d65dd9af78deb6e6e09ae885866f Mon Sep 17 00:00:00 2001 From: S Date: Mon, 5 Jun 2017 15:32:32 +0100 Subject: [PATCH 22/39] {"types":"C","runs":4} --- Hailstone.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Hailstone.java b/Hailstone.java index d3a7abf..79e2156 100755 --- a/Hailstone.java +++ b/Hailstone.java @@ -19,11 +19,13 @@ public void run() { 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++; } From 197cb521c6d80a6042fb2b11a60f00e2fb65e7ac Mon Sep 17 00:00:00 2001 From: S Date: Mon, 5 Jun 2017 15:33:36 +0100 Subject: [PATCH 23/39] {"types":"C","runs":5} --- Hailstone.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Hailstone.java b/Hailstone.java index 79e2156..45e61c4 100755 --- a/Hailstone.java +++ b/Hailstone.java @@ -29,8 +29,8 @@ public void run() { y++; } - println ("It took " + y + " to arrive at 1"); } + println ("It took " + y + " to arrive at 1"); } } From 8dd9d03acf12443bd171ba1973ab9fc44fc8fb67 Mon Sep 17 00:00:00 2001 From: S Date: Mon, 5 Jun 2017 15:34:34 +0100 Subject: [PATCH 24/39] {"types":"C","runs":6} --- Hailstone.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Hailstone.java b/Hailstone.java index 45e61c4..df269ae 100755 --- a/Hailstone.java +++ b/Hailstone.java @@ -30,7 +30,7 @@ public void run() { } } - println ("It took " + y + " to arrive at 1"); + println ("It took " + y + " steps to arrive at 1"); } } From 28578ea44ac822e82cb472bc9bf86e4fd5262bc4 Mon Sep 17 00:00:00 2001 From: S Date: Mon, 5 Jun 2017 15:45:32 +0100 Subject: [PATCH 25/39] {"types":"C","runs":7} --- Hailstone.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Hailstone.java b/Hailstone.java index df269ae..9e6a613 100755 --- a/Hailstone.java +++ b/Hailstone.java @@ -10,26 +10,34 @@ public class Hailstone extends ConsoleProgram { public void run() { - /* You fill this in */ - int x = readInt("?"); + /* 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 ); + 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) ); + println( " " +x+ " is odd, so i compute 3x + 1: " + (3 * x + 1) ); x = 3 * x + 1; y++; + + println("..."); } } + println("..."); println ("It took " + y + " steps to arrive at 1"); } } From e7f996af148834fa69200ae3eefffbef1fe63416 Mon Sep 17 00:00:00 2001 From: S Date: Mon, 5 Jun 2017 15:46:29 +0100 Subject: [PATCH 26/39] {"types":"C","runs":8} --- Hailstone.java | 1 - 1 file changed, 1 deletion(-) diff --git a/Hailstone.java b/Hailstone.java index 9e6a613..180c9f8 100755 --- a/Hailstone.java +++ b/Hailstone.java @@ -33,7 +33,6 @@ public void run() { x = 3 * x + 1; y++; - println("..."); } } From c703d88e51b24fcfde4c2beffcd2c02c606a7658 Mon Sep 17 00:00:00 2001 From: S Date: Mon, 5 Jun 2017 15:54:13 +0100 Subject: [PATCH 27/39] {"types":"C","runs":12} --- PythagoreanTheorem.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/PythagoreanTheorem.java b/PythagoreanTheorem.java index f774a30..e6fab4a 100755 --- a/PythagoreanTheorem.java +++ b/PythagoreanTheorem.java @@ -11,5 +11,10 @@ public class PythagoreanTheorem extends ConsoleProgram { public void run() { /* You fill this in */ + + int a = readInt (); + int b = readInt (); + + double c = Math.sqrt((a*a) + (b*b)); } } From a21d61c28e86a34466822f3136e3c481389352ed Mon Sep 17 00:00:00 2001 From: S Date: Mon, 5 Jun 2017 15:55:16 +0100 Subject: [PATCH 28/39] {"types":"C","runs":13} --- PythagoreanTheorem.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/PythagoreanTheorem.java b/PythagoreanTheorem.java index e6fab4a..6fe3a0c 100755 --- a/PythagoreanTheorem.java +++ b/PythagoreanTheorem.java @@ -16,5 +16,8 @@ public void run() { int b = readInt (); double c = Math.sqrt((a*a) + (b*b)); + + println(c); + } } From d26930cf9d06cc893c443ee41c1736a7d05ab570 Mon Sep 17 00:00:00 2001 From: S Date: Mon, 5 Jun 2017 16:08:22 +0100 Subject: [PATCH 29/39] {"types":"C","runs":14} --- PythagoreanTheorem.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/PythagoreanTheorem.java b/PythagoreanTheorem.java index 6fe3a0c..a2fd114 100755 --- a/PythagoreanTheorem.java +++ b/PythagoreanTheorem.java @@ -11,13 +11,18 @@ public class PythagoreanTheorem extends ConsoleProgram { public void run() { /* You fill this in */ - - int a = readInt (); - int b = readInt (); + println("*********************************************************"); + println("Enter the values of A and B to compute Pythagoras theorem"); + int a = readInt ("A = "); + println("/n"); + int b = readInt ("B = "); - double c = Math.sqrt((a*a) + (b*b)); + int c = ((a*a) + (b*b)); - println(c); + double x = Math.sqrt (c); + println("/n"); + println(x); + println("*********************************************************"); } } From bec7dca29cecce261e2818fb74a320f620f4540f Mon Sep 17 00:00:00 2001 From: S Date: Mon, 5 Jun 2017 16:10:08 +0100 Subject: [PATCH 30/39] {"types":"C","runs":15} --- PythagoreanTheorem.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/PythagoreanTheorem.java b/PythagoreanTheorem.java index a2fd114..b126558 100755 --- a/PythagoreanTheorem.java +++ b/PythagoreanTheorem.java @@ -14,14 +14,14 @@ public void run() { println("*********************************************************"); println("Enter the values of A and B to compute Pythagoras theorem"); int a = readInt ("A = "); - println("/n"); + println(""); int b = readInt ("B = "); int c = ((a*a) + (b*b)); double x = Math.sqrt (c); - println("/n"); - println(x); + println(""); + println("The answer is " +x); println("*********************************************************"); } From 76efb9c7e2ae99074767c4d0ac95db866aee2d43 Mon Sep 17 00:00:00 2001 From: S Date: Tue, 6 Jun 2017 14:45:52 +0100 Subject: [PATCH 31/39] {"types":"C","runs":19} --- Target.java | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/Target.java b/Target.java index 5f0e0a1..1356919 100755 --- a/Target.java +++ b/Target.java @@ -12,6 +12,31 @@ public class Target extends GraphicsProgram { public void run() { - /* You fill this in. */ + /* + * This program draws an archery target + */ + double inch2Pix = 72; + + double maxiDiameter = 2 * 1 * inch2Pix; + double mediDiameter = 2 * 0.65 * inch2Pix; + double miniDiameter = 2 * 0.30 * inch2Pix; + + double x = getWidth()/2; + double y = getHeight()/2; + + GOval maxiTarget = new GOval(x - maxiDiameter, y - maxiDiameter, maxiDiameter, maxiDiameter); + maxiTarget.setFilled(true); + maxiTarget.setColor(Color.RED); + add(maxiTarget); + + GOval mediTarget = new GOval(x - mediDiameter, y - mediDiameter, mediDiameter, mediDiameter); + mediTarget.setFilled(true); + mediTarget.setColor(Color.WHITE); + add(mediTarget); + + GOval miniTarget = new GOval(x - miniDiameter, y - miniDiameter, miniDiameter, miniDiameter); + miniTarget.setFilled(true); + miniTarget.setColor(Color.RED); + add(miniTarget); } } From 8aa24368b9922cfbfe95978e16f306962ecc6862 Mon Sep 17 00:00:00 2001 From: S Date: Tue, 6 Jun 2017 14:49:29 +0100 Subject: [PATCH 32/39] {"types":"C","runs":20} --- Target.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Target.java b/Target.java index 1356919..4fbde87 100755 --- a/Target.java +++ b/Target.java @@ -17,24 +17,24 @@ public void run() { */ double inch2Pix = 72; - double maxiDiameter = 2 * 1 * inch2Pix; - double mediDiameter = 2 * 0.65 * inch2Pix; - double miniDiameter = 2 * 0.30 * inch2Pix; + 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 - maxiDiameter, y - maxiDiameter, maxiDiameter, maxiDiameter); + 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 - mediDiameter, y - mediDiameter, mediDiameter, mediDiameter); + 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 - miniDiameter, y - miniDiameter, miniDiameter, miniDiameter); + GOval miniTarget = new GOval(x - miniRadius, y - miniRadius, 2 * miniRadius, 2 * miniRadius); miniTarget.setFilled(true); miniTarget.setColor(Color.RED); add(miniTarget); From 8d3ddaf22415acf60f8cf14fbd24e8f657938ba3 Mon Sep 17 00:00:00 2001 From: S Date: Tue, 6 Jun 2017 15:20:59 +0100 Subject: [PATCH 33/39] {"types":"C","runs":25} --- FindRange.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/FindRange.java b/FindRange.java index 416b172..def457d 100755 --- a/FindRange.java +++ b/FindRange.java @@ -10,7 +10,24 @@ public class FindRange extends ConsoleProgram { public void run() { - /* You fill this in */ + /* + * This program finds the range of + * any set of numbers until the Sentinel + * value is reached + */ + println("This program finds displays the minimum and"); + println("maximum values in a given set of numbers"); + + + println("Enter a value"); + int val = readInt(); + if (val == SENTINEL){ + println("Number not valid"); + } + + int min = 0; + int max = 0; } + private static final int SENTINEL = 20; } From 220928d4a0c8dda9697c5034fe82e57df64d23eb Mon Sep 17 00:00:00 2001 From: S Date: Tue, 6 Jun 2017 15:21:58 +0100 Subject: [PATCH 34/39] {"types":"C","runs":26} --- FindRange.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FindRange.java b/FindRange.java index def457d..470b1bd 100755 --- a/FindRange.java +++ b/FindRange.java @@ -15,7 +15,7 @@ public void run() { * any set of numbers until the Sentinel * value is reached */ - println("This program finds displays the minimum and"); + println("This program finds the minimum and"); println("maximum values in a given set of numbers"); From d9e3dfe4690e15f878498a4c03706562e300d13a Mon Sep 17 00:00:00 2001 From: S Date: Tue, 6 Jun 2017 15:38:16 +0100 Subject: [PATCH 35/39] {"types":"C","runs":27} --- FindRange.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/FindRange.java b/FindRange.java index 470b1bd..6fba455 100755 --- a/FindRange.java +++ b/FindRange.java @@ -27,6 +27,20 @@ public void run() { int min = 0; int max = 0; + + while (true){ + 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; } From bed295edbd7073076de62c3debefdaeb5f1d70d1 Mon Sep 17 00:00:00 2001 From: S Date: Tue, 6 Jun 2017 15:39:30 +0100 Subject: [PATCH 36/39] {"types":"C","runs":28} --- FindRange.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/FindRange.java b/FindRange.java index 6fba455..cebf8c8 100755 --- a/FindRange.java +++ b/FindRange.java @@ -21,9 +21,8 @@ public void run() { println("Enter a value"); int val = readInt(); - if (val == SENTINEL){ - println("Number not valid"); - } + + int min = 0; int max = 0; From 1f1235401b692a19ca7fb80836002f7183fed35b Mon Sep 17 00:00:00 2001 From: S Date: Tue, 6 Jun 2017 15:40:14 +0100 Subject: [PATCH 37/39] {"types":"C","runs":29} --- FindRange.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/FindRange.java b/FindRange.java index cebf8c8..caa36d1 100755 --- a/FindRange.java +++ b/FindRange.java @@ -19,8 +19,7 @@ public void run() { println("maximum values in a given set of numbers"); - println("Enter a value"); - int val = readInt(); + @@ -28,6 +27,8 @@ public void run() { int max = 0; while (true){ + println("Enter a value"); + int val = readInt(); if (val == SENTINEL){ break; } From 40afa7b09a2080e20bb5c55fe50d0a2a4815a1b9 Mon Sep 17 00:00:00 2001 From: S Date: Tue, 6 Jun 2017 15:40:59 +0100 Subject: [PATCH 38/39] {"types":"C","runs":30} --- FindRange.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/FindRange.java b/FindRange.java index caa36d1..2b71400 100755 --- a/FindRange.java +++ b/FindRange.java @@ -25,9 +25,9 @@ public void run() { int min = 0; int max = 0; - + println("Enter a value"); while (true){ - println("Enter a value"); + int val = readInt(); if (val == SENTINEL){ break; From 22df0ec9884289ae443c3449eb26a487e3ef2fc9 Mon Sep 17 00:00:00 2001 From: S Date: Tue, 6 Jun 2017 15:55:55 +0100 Subject: [PATCH 39/39] {"types":"C","runs":30} --- FindRange.java | 1 + 1 file changed, 1 insertion(+) diff --git a/FindRange.java b/FindRange.java index 2b71400..60e6aac 100755 --- a/FindRange.java +++ b/FindRange.java @@ -31,6 +31,7 @@ public void run() { int val = readInt(); if (val == SENTINEL){ break; + } else if(val < min){ min = val;