Skip to content

Commit

Permalink
worked on Student.java and StudentTester.java, not Student2.java or S…
Browse files Browse the repository at this point in the history
…tudentTester2.java
  • Loading branch information
Ardusa committed Feb 20, 2024
1 parent c05abff commit 08e5130
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 22 deletions.
2 changes: 1 addition & 1 deletion MarvelCharacter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
4 changes: 4 additions & 0 deletions Pokemon.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
34 changes: 20 additions & 14 deletions Student.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
28 changes: 28 additions & 0 deletions Student2.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
67 changes: 60 additions & 7 deletions StudentTester.java
Original file line number Diff line number Diff line change
@@ -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<Student> 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());
}
}
11 changes: 11 additions & 0 deletions StudentTester2.java
Original file line number Diff line number Diff line change
@@ -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());
}
}
1 change: 1 addition & 0 deletions thing.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,6 @@ public static void main(String[] args) {
System.out.println(number1);
}
}
in.close();
}
}

0 comments on commit 08e5130

Please sign in to comment.