Facebook
From Aaron Amankwaah, 3 Years ago, written in Java.
Embed
Download Paste or View Raw
Hits: 52
  1. // Aaron Amankwaah
  2. // 09/23/2020
  3. // HW1-V2 #4
  4.  
  5. // Implement a class Student. A student has a name and a total quiz score. Supply an appropriate
  6. // constructor, and methods getName(), addQuiz(int score), getTotalScore(), and
  7. // getAverageScore(). To compute the latter, also need to store the number of quizzes that the
  8. // student took.
  9.  
  10. import java.util.ArrayList;
  11. import java.util.*;
  12.  
  13. public class Student{
  14. public static void main(String[] args){
  15.     System.out.println("This is Homeowrk 1 - Question #4. By Aaron Amankwaah, Output Below! \n");
  16.     // ArrayList<Student> students = new ArrayList<Student> ();
  17.     Student jerry = new Student("Jerry",0.0);
  18.     add(jerry);
  19.     jerry.addQuiz(86);
  20.     jerry.getTotalScore();
  21.     jerry.getAverageScore();
  22.  
  23.     // students.get(0).addQuiz(86);
  24.     // students.get(0).getTotalScore();
  25.     // students.get(0).getAverageScore();
  26.  
  27.  
  28.     System.out.printf("Quizzes total score : %1.0f\n", jerry.getTotalScore());
  29.     System.out.println("\n Avverage Quiz Score: " + jerry.getAverageScore());
  30.  
  31. }
  32.  
  33. public static class Student{
  34. private ArrayList<Double> quizzes = new ArrayList<Double> ();
  35. private String name; double quizTotal;
  36. private ArrayList<Student> students = new ArrayList<Student> ();
  37. //constructor
  38. public static Student(String name, double quizTotal){
  39. name = name;
  40. quizTotal = quizTotal;
  41. }
  42. public static addStudent(Student identifier) {
  43.     students.add(identifier);
  44.     }
  45. //Add item to cash register
  46. public static void addQuiz(int score){
  47.  quizzes.add(score);
  48.  quizTotal += score;
  49. }
  50. //Get total price for current sale
  51. public static int getTotalScore(){
  52.     return quizTotal;
  53. }
  54. public static double getAverageScore(){
  55.  return quizTotal/quizzes.size();
  56. }
  57. public static String getName(){
  58.     return name;
  59. }
  60.  
  61. }
  62. }