From 5291e84619cb4558ad5b775d8801a698c66cc245 Mon Sep 17 00:00:00 2001 From: BCR Date: Sun, 15 Oct 2023 16:30:26 -0700 Subject: [PATCH 1/5] Create Die.java --- Die.java | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 Die.java diff --git a/Die.java b/Die.java new file mode 100644 index 0000000..7fcbefc --- /dev/null +++ b/Die.java @@ -0,0 +1,84 @@ +import java.util.ArrayList; +import java.util.List; + + +public class Die { + int numSides; + boolean lastroll = false; + int x; + List l1 = new ArrayList(); + + + public Die() { + numSides=6; + } + public Die(int i) { + numSides = i; + } + + + int roll() + { + int roll; + int max = numSides; + int min =1; + int range = max-min+1; + lastroll = true; + + roll = (int)(Math.random() * range) + min; + l1.add(roll); + + return roll; + } + + + int readLastroll() { + if (lastroll == true) { + //System.out.println("Last Roll was: " + l1.get(0)); + + + return l1.get(l1.size() - 1); + } + else { + System.out.println("Roll the Die First"); + + return -1; + } + + + + } + + + + + + + + + + public static void main(String[] args) + { + Die x = new Die(6); + Die y = new Die(6); + Die z = new Die(6); + System.out.println("Number of Sides: " + x.numSides); + System.out.println("Roll:" + x.roll()); + System.out.println("Roll:" + x.roll()); + System.out.println("Roll:" + x.roll()); + System.out.println("Roll:" + x.roll()); + System.out.println("Last Roll: " + x.readLastroll()); + int sum; + System.out.println("Rollx:" + x.roll()); + System.out.println("Rolly:" + y.roll()); + System.out.println("Rollz:" + z.roll()); + sum = x.roll() + y.roll() + z.roll(); + System.out.println("Sum of these three die is: " + sum); + + + + + + }} + + From 7e38bb01d94fb885c70cf489d9f0ab270090b74f Mon Sep 17 00:00:00 2001 From: BCR Date: Sun, 15 Oct 2023 16:31:46 -0700 Subject: [PATCH 2/5] Create Problem1.java --- Problem1.java | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 Problem1.java diff --git a/Problem1.java b/Problem1.java new file mode 100644 index 0000000..e69de29 From 67343336cea5fb4738c47f545215c1d22894bc6f Mon Sep 17 00:00:00 2001 From: BCR Date: Sun, 15 Oct 2023 16:37:56 -0700 Subject: [PATCH 3/5] Added Problem1.java --- Die.java | 2 +- Problem1.java | 0 exercise1.java | 27 +++++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) delete mode 100644 Problem1.java create mode 100644 exercise1.java diff --git a/Die.java b/Die.java index 7fcbefc..98bcb06 100644 --- a/Die.java +++ b/Die.java @@ -73,7 +73,7 @@ public static void main(String[] args) System.out.println("Rolly:" + y.roll()); System.out.println("Rollz:" + z.roll()); sum = x.roll() + y.roll() + z.roll(); - System.out.println("Sum of these three die is: " + sum); + System.out.println("Sum of random three die is: " + sum); diff --git a/Problem1.java b/Problem1.java deleted file mode 100644 index e69de29..0000000 diff --git a/exercise1.java b/exercise1.java new file mode 100644 index 0000000..dabe1b4 --- /dev/null +++ b/exercise1.java @@ -0,0 +1,27 @@ +public class exercise1 { + + public static void main(String[] args) + { + int max = 6; + int min = 1; + int range = max - min + 1; + + + for (int i = 0; i<=20; i++) + { + int rand = (int)(Math.random() * range) + min; + System.out.println("Roll " + i + " = " + rand); + + + } + + + + + } + +} + + + + From be101e0707d028f0628d657a9ad0f767b0651513 Mon Sep 17 00:00:00 2001 From: Tristan Lu <60327051+coolmehman@users.noreply.github.com> Date: Sun, 22 Oct 2023 13:45:41 -0700 Subject: [PATCH 4/5] Update Die.java --- Die.java | 114 +++++++++++++++++++++---------------------------------- 1 file changed, 43 insertions(+), 71 deletions(-) diff --git a/Die.java b/Die.java index 98bcb06..3cbb42a 100644 --- a/Die.java +++ b/Die.java @@ -1,84 +1,56 @@ import java.util.ArrayList; -import java.util.List; - -public class Die { +public class Die +{ int numSides; - boolean lastroll = false; - int x; - List l1 = new ArrayList(); + int lastRoll = -1; + int rollNum = 0; + + ArrayList number = new ArrayList(); public Die() { - numSides=6; - } - public Die(int i) { - numSides = i; - } - - - int roll() - { - int roll; - int max = numSides; - int min =1; - int range = max-min+1; - lastroll = true; - - roll = (int)(Math.random() * range) + min; - l1.add(roll); - - return roll; + numSides = 6; } + public Die(int n) { + numSides = n; + } - int readLastroll() { - if (lastroll == true) { - //System.out.println("Last Roll was: " + l1.get(0)); - - - return l1.get(l1.size() - 1); - } - else { - System.out.println("Roll the Die First"); - - return -1; - } - - - - } - - - - - - - - - - public static void main(String[] args) - { - Die x = new Die(6); - Die y = new Die(6); - Die z = new Die(6); - System.out.println("Number of Sides: " + x.numSides); - System.out.println("Roll:" + x.roll()); - System.out.println("Roll:" + x.roll()); - System.out.println("Roll:" + x.roll()); - System.out.println("Roll:" + x.roll()); - System.out.println("Last Roll: " + x.readLastroll()); - int sum; - System.out.println("Rollx:" + x.roll()); - System.out.println("Rolly:" + y.roll()); - System.out.println("Rollz:" + z.roll()); - sum = x.roll() + y.roll() + z.roll(); - System.out.println("Sum of random three die is: " + sum); - - + int numSides() { + return numSides; + } + int roll() { + int max = numSides; + int min = 1; + int range = max - min + 1; - - }} + int roll = (int)(Math.random() * range) + min; + lastRoll = roll; + rollNum += 1; + System.out.println("Roll Number: " + rollNum + " Rolled " + roll); + return roll; + } + int readLastRoll() { + if(lastRoll != -1) { + System.out.println("Last roll was " + lastRoll); + } else { + System.out.println("Roll a die first"); + } + System.out.println("Rolled a total of: " + rollNum + " times"); + return lastRoll; + } + + public static void main(String[] args) { + Die die = new Die(); + for (int i=0; i<5; i++) { + die.roll(); + } + die.readLastRoll(); + int sum = die.roll() + die.roll() + die.roll(); + System.out.println("Sum of three random die is: " + sum); + } +} \ No newline at end of file From 592aea0be5c25187a6f76fcadd99b1f638c4589c Mon Sep 17 00:00:00 2001 From: Tristan Lu <60327051+coolmehman@users.noreply.github.com> Date: Sun, 22 Oct 2023 15:19:03 -0700 Subject: [PATCH 5/5] Update Die.java --- Die.java | 109 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 68 insertions(+), 41 deletions(-) diff --git a/Die.java b/Die.java index 3cbb42a..8916748 100644 --- a/Die.java +++ b/Die.java @@ -1,56 +1,83 @@ import java.util.ArrayList; +import java.util.List; -public class Die -{ - int numSides; - int lastRoll = -1; - int rollNum = 0; +public class Die { + int numSides; + boolean lastroll = false; + int x; + List l1 = new ArrayList(); - ArrayList number = new ArrayList(); public Die() { - numSides = 6; + numSides=6; + } + public Die(int i) { + numSides = i; + } + + + int roll() + { + int roll; + int max = numSides; + int min =1; + int range = max-min+1; + lastroll = true; + + roll = (int)(Math.random() * range) + min; + l1.add(roll); + + return roll; } - public Die(int n) { - numSides = n; - } - int numSides() { - return numSides; - } + int readLastroll() { + if (lastroll == true) { + return l1.get(l1.size() - 1); + } + else { + System.out.println("Roll the Die First"); + + return -1; + } - int roll() { - int max = numSides; - int min = 1; - int range = max - min + 1; - int roll = (int)(Math.random() * range) + min; - lastRoll = roll; - rollNum += 1; - System.out.println("Roll Number: " + rollNum + " Rolled " + roll); - return roll; - } + + } - int readLastRoll() { - if(lastRoll != -1) { - System.out.println("Last roll was " + lastRoll); - } else { - System.out.println("Roll a die first"); - } - System.out.println("Rolled a total of: " + rollNum + " times"); - return lastRoll; - } - - public static void main(String[] args) { - Die die = new Die(); - for (int i=0; i<5; i++) { - die.roll(); - } - die.readLastRoll(); - int sum = die.roll() + die.roll() + die.roll(); + + + + + + + + public static void main(String[] args) + { + Die x = new Die(6); + Die y = new Die(6); + Die z = new Die(6); + System.out.println("Number of Sides: " + x.numSides); + System.out.println("Roll:" + x.roll()); + System.out.println("Roll:" + x.roll()); + System.out.println("Roll:" + x.roll()); + System.out.println("Roll:" + x.roll()); + System.out.println("Last Roll: " + x.readLastroll()); + int sum; + System.out.println("Rollx:" + x.roll()); + System.out.println("Rolly:" + y.roll()); + System.out.println("Rollz:" + z.roll()); + sum = x.roll() + y.roll() + z.roll(); System.out.println("Sum of three random die is: " + sum); + + + + + } -} \ No newline at end of file + + + +}