From 5cdcedbe5836d60690e075926a9c735eb90ec6e9 Mon Sep 17 00:00:00 2001 From: SteffenLm <33038091+SteffenLm@users.noreply.github.com> Date: Wed, 26 Oct 2022 11:11:33 +0200 Subject: [PATCH 1/2] implement solution --- Dice.java | 25 +++++++++++++++++++++++++ Exercise.java | 8 +++++++- 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 Dice.java diff --git a/Dice.java b/Dice.java new file mode 100644 index 0000000..1c4a66f --- /dev/null +++ b/Dice.java @@ -0,0 +1,25 @@ +import java.util.Random; + +public class Dice { + + private int id; + private int value; + + public Dice(int id) { + this.id = id; + rollTheDice(); + } + + public int getId() { + return id; + } + + public int getValue() { + return value; + } + + public void rollTheDice() { + Random random = new Random(); + value = random.nextInt(6) + 1; + } +} diff --git a/Exercise.java b/Exercise.java index 3c092f9..f700885 100644 --- a/Exercise.java +++ b/Exercise.java @@ -1,6 +1,12 @@ public class Exercise { public static void main(String[] args) { - // implement exercise here + Dice dice = new Dice(1); + + System.out.println("ID - Wuerfelwert"); + for (int i = 1; i <= 5; i++) { + dice.rollTheDice(); + System.out.println(dice.getId() + " - " + dice.getValue()); + } } } From 8e905bc0576186ce77a4d36c70d6e382d3a06847 Mon Sep 17 00:00:00 2001 From: github-actions <> Date: Wed, 26 Oct 2022 09:11:50 +0000 Subject: [PATCH 2/2] Google Java Format --- Dice.java | 32 ++++++++++++++++---------------- Exercise.java | 12 ++++++------ 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/Dice.java b/Dice.java index 1c4a66f..5266834 100644 --- a/Dice.java +++ b/Dice.java @@ -2,24 +2,24 @@ public class Dice { - private int id; - private int value; + private int id; + private int value; - public Dice(int id) { - this.id = id; - rollTheDice(); - } + public Dice(int id) { + this.id = id; + rollTheDice(); + } - public int getId() { - return id; - } + public int getId() { + return id; + } - public int getValue() { - return value; - } + public int getValue() { + return value; + } - public void rollTheDice() { - Random random = new Random(); - value = random.nextInt(6) + 1; - } + public void rollTheDice() { + Random random = new Random(); + value = random.nextInt(6) + 1; + } } diff --git a/Exercise.java b/Exercise.java index f700885..40bbccd 100644 --- a/Exercise.java +++ b/Exercise.java @@ -1,12 +1,12 @@ public class Exercise { public static void main(String[] args) { - Dice dice = new Dice(1); + Dice dice = new Dice(1); - System.out.println("ID - Wuerfelwert"); - for (int i = 1; i <= 5; i++) { - dice.rollTheDice(); - System.out.println(dice.getId() + " - " + dice.getValue()); - } + System.out.println("ID - Wuerfelwert"); + for (int i = 1; i <= 5; i++) { + dice.rollTheDice(); + System.out.println(dice.getId() + " - " + dice.getValue()); + } } }