diff --git a/MarvelCharacter.java b/MarvelCharacter.java index c3b3954..c328a03 100644 --- a/MarvelCharacter.java +++ b/MarvelCharacter.java @@ -39,7 +39,7 @@ public int randComic() { } public static void main(String[] args) { - MarvelCharacter avenger1 = new MarvelCharacter(); + // MarvelCharacter avenger1 = new MarvelCharacter(); MarvelCharacter spiderMan = new MarvelCharacter("Spider-Man", "webbing projection", 300); MarvelCharacter symbiote = new MarvelCharacter("Venom", "shapeshifting", 144); System.out.println(symbiote.getName()); diff --git a/Pokemon.java b/Pokemon.java index fd84c0b..ee497b9 100644 --- a/Pokemon.java +++ b/Pokemon.java @@ -30,6 +30,10 @@ public boolean knockedOut() { return hp <= 0; } + public String getBestAttack() { + return bestAttack; + } + public static void main(String[] args) { Pokemon charmander = new Pokemon("Charmander", "Blaze", 39); diff --git a/Student.java b/Student.java index c62e85c..2ca6910 100644 --- a/Student.java +++ b/Student.java @@ -1,28 +1,34 @@ public class Student { private String name; - private int totalQuizScore; - private int numberOfQuizzes; + private int[] quizScores; - public Student(String name) { + public Student(String name, int[] quizScores) { this.name = name; - this.totalQuizScore = 0; - this.numberOfQuizzes = 0; + this.quizScores = quizScores; } - public String getName() { - return name; + public int getQuizScore(int quizNumber) { + return quizScores[quizNumber]; + } + + public void setQuizScore(int quizNumber, int newScore) { + quizScores[quizNumber] = newScore; } - public void addQuiz(int score) { - totalQuizScore += score; - numberOfQuizzes++; + public String getName() { + return name; } - public int getTotalScore() { - return totalQuizScore; + public void setName(String newName) { + name = newName; } - public int getAverageScore() { - return totalQuizScore / numberOfQuizzes; + @Override + public String toString() { + String result = name + ": "; + for (int score : quizScores) { + result += score + " "; + } + return result; } } diff --git a/Student2.java b/Student2.java new file mode 100644 index 0000000..c0956cb --- /dev/null +++ b/Student2.java @@ -0,0 +1,28 @@ +public class Student2 { + private String name; + private int totalQuizScore; + private int numberOfQuizzes; + + public Student2(String name) { + this.name = name; + this.totalQuizScore = 0; + this.numberOfQuizzes = 0; + } + + public String getName() { + return name; + } + + public void addQuiz(int score) { + totalQuizScore += score; + numberOfQuizzes++; + } + + public int getTotalScore() { + return totalQuizScore; + } + + public int getAverageScore() { + return totalQuizScore / numberOfQuizzes; + } +} diff --git a/StudentTester.java b/StudentTester.java index c7be001..d97dce0 100644 --- a/StudentTester.java +++ b/StudentTester.java @@ -1,11 +1,64 @@ +import java.util.ArrayList; + public class StudentTester { public static void main(String... args) { - Student student = new Student("John Doe"); - student.addQuiz(10); - student.addQuiz(20); - student.addQuiz(30); - System.out.println("Student name: " + student.getName()); - System.out.println("Student total score: " + student.getTotalScore()); - System.out.println("Student average score: " + student.getAverageScore()); + ArrayList students = new ArrayList<>(); + students.add(new Student("Aubrey Graham", new int[] { 46, 57, 68, 79, 90 })); + students.add(new Student("Shéyaa Joseph", new int[] { 98, 87, 76, 65, 54 })); + students.add(new Student("Navy Wilburn", new int[] { 82, 93, 74, 85, 96 })); + students.add(new Student("Symere Woods", new int[] { 31, 41, 51, 61, 71 })); + students.add(new Student("Kiari Cephus", new int[] { 54, 65, 76, 87, 98 })); + + System.out.println("Name \t\t\t Quiz 1 \t Quiz 2 \t Quiz 3 \t Quiz 4 \t Quiz 5"); + System.out.println("-".repeat(100)); + for (Student student : students) { + System.out.printf("%s \t|\t %d \t|\t %d \t|\t %d \t|\t %d \t|\t %d \n", student.getName(), + student.getQuizScore(0), + student.getQuizScore(1), student.getQuizScore(2), student.getQuizScore(3), student.getQuizScore(4)); + } + System.out.println(); + + // Changing the name of a student + students.get(1).setName("Jaques Webster"); + + System.out.println("Name \t\t\t Quiz 1 \t Quiz 2 \t Quiz 3 \t Quiz 4 \t Quiz 5"); + System.out.println("-".repeat(100)); + for (Student student : students) { + System.out.printf("%s \t|\t %d \t|\t %d \t|\t %d \t|\t %d \t|\t %d \n", student.getName(), + student.getQuizScore(0), + student.getQuizScore(1), student.getQuizScore(2), student.getQuizScore(3), student.getQuizScore(4)); + } + System.out.println(); + + // Setting the quiz score of a student + students.get(2).setQuizScore(3, 100); + + System.out.println("Name \t\t\t Quiz 1 \t Quiz 2 \t Quiz 3 \t Quiz 4 \t Quiz 5"); + System.out.println("-".repeat(100)); + for (Student student : students) { + System.out.printf("%s \t|\t %d \t|\t %d \t|\t %d \t|\t %d \t|\t %d \n", student.getName(), + student.getQuizScore(0), + student.getQuizScore(1), student.getQuizScore(2), student.getQuizScore(3), student.getQuizScore(4)); + } + System.out.println(); + + // Replace a student with a new student + students.set(2, new Student("Kanye West", new int[] { 85, 61, 77, 93, 100 })); + + System.out.println("Name \t\t\t Quiz 1 \t Quiz 2 \t Quiz 3 \t Quiz 4 \t Quiz 5"); + System.out.println("-".repeat(100)); + for (Student student : students) { + System.out.printf("%s \t|\t %d \t|\t %d \t|\t %d \t|\t %d \t|\t %d \n", student.getName(), + student.getQuizScore(0), + student.getQuizScore(1), student.getQuizScore(2), student.getQuizScore(3), student.getQuizScore(4)); + } + System.out.println(); + + System.out.println("ToString Demonstration:"); + System.out.println(students.get(0).toString()); + System.out.println(students.get(1).toString()); + System.out.println(students.get(2).toString()); + System.out.println(students.get(3).toString()); + System.out.println(students.get(4).toString()); } } diff --git a/StudentTester2.java b/StudentTester2.java new file mode 100644 index 0000000..1400daa --- /dev/null +++ b/StudentTester2.java @@ -0,0 +1,11 @@ +public class StudentTester2 { + public static void main(String... args) { + Student2 student = new Student2("John Doe"); + student.addQuiz(10); + student.addQuiz(20); + student.addQuiz(30); + System.out.println("Student name: " + student.getName()); + System.out.println("Student total score: " + student.getTotalScore()); + System.out.println("Student average score: " + student.getAverageScore()); + } +} diff --git a/thing.java b/thing.java index 3cf1fa1..f56f6ae 100644 --- a/thing.java +++ b/thing.java @@ -121,5 +121,6 @@ public static void main(String[] args) { System.out.println(number1); } } + in.close(); } }