From 0a3dfd2ca5cca68f8ff06f1535c39ed9c2a7b015 Mon Sep 17 00:00:00 2001 From: Hammy Date: Sun, 11 Oct 2020 06:53:12 +0100 Subject: [PATCH] Displaying information about the animals --- Personal/Interfaces/Animals/Helper.java | 32 +++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Personal/Interfaces/Animals/Helper.java diff --git a/Personal/Interfaces/Animals/Helper.java b/Personal/Interfaces/Animals/Helper.java new file mode 100644 index 0000000..585ce5e --- /dev/null +++ b/Personal/Interfaces/Animals/Helper.java @@ -0,0 +1,32 @@ +public class Helper { + + private final Animal[] animals; + private double averagePrice; + + public Helper(Animal[] animals) { + this.animals = animals; + } + + public void displayInformation() { + + int total = 0; + double sum = 0.0; + for (Animal animal : animals) { + StringBuilder stringBuilder = new StringBuilder(); + + stringBuilder.append("\n\nName: " + animal.animalName()); + stringBuilder.append("\nSound: " + animal.animalSound()); + stringBuilder.append("\nPrice: £" + animal.animalPrice()); + + System.out.println(stringBuilder.toString()); + + total++; + sum += animal.animalPrice(); + } + averagePrice = sum / total; + } + + public void displayAveragePrice() { + System.out.printf("\nThe Average Price For All The Animals Are: £%.2f", averagePrice); + } +}