Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write this program in Java Given the following UMLC is for a private member, for

ID: 3812461 • Letter: W

Question

Write this program in Java Given the following UMLC is for a private member, for a public member, and underline is for a static is Student Score name: String The name of this Studentscore (default "John Doe') scores: double0 Array of scores for this StudentScore. The number of this Studentscore objects created Student Score Default Construct creates scores array with 4 elements and updates the numObj. Studentscore (name: String, Construct accepts a name and a array of real numbers scores double(D (double date type), and assigns them to the name and scores data members; updates the numObj. getNameo: String Returns the name of this object getScore0: double0 Returns the score of this object (must duplicate the array) setScore (score: doubleO) Changes the contents of the score get Numobio int Returns the numbers of Studentscore objects created calAveo: double Calculate the average score toStringo; Strring Returns the all the values of the private data members Note: for the contents in the array, use either a loop to concatenate all the data in the array into String or use toString0 method in the Arrays class (Arrays class is in java util pakage) 1. Implement the Studentscore class. 2. Write a test program to Create at least 2 StudentScore object to test the methods of StudentSocre Must create array to input the exam scores Bonus (up to 25 points) generates an array that holds N objects ofstudentscore class

Explanation / Answer

import java.util.Scanner;


public class StudentScore {

   private String name = "John Doe";//name default as John Doe
   private double[] scores;// to store scores
   private static int numObj;// to check the number of oj created
   //default constructor
   public StudentScore(){
      
   }
   //parameterized constructor
   public StudentScore(String name, double scores[]){
       this.name = name;
       this.scores = scores;
       numObj++;
   }
   //method to get Name
   public String getName() {
       return name;
   }
   //method to get Scores
   public double[] getScores() {
       return scores;
   }
   //method to set Scores
   public void setScores(double[] scores) {
       this.scores = scores;
   }
   //method to get count of obj created
   public static int getNumObj() {
       return numObj;
   }
   //to cal Average
   public double calAve(){
       double avg=0;
       for(int i=0;i<this.scores.length;i++){
           avg=avg+this.scores[i];
       }
       return avg/this.scores.length;
      
   }
  
   @Override
   public String toString() {
       String examScore="";
       for(int i=0;i<this.scores.length;i++){
           examScore=examScore.concat(String.valueOf(this.scores[i]))+" ";
       }
       return String.format("Number of the object created: %s%nStudent name: %s%nExam scores:%s%naverage %s",
               getNumObj(),getName(),examScore,calAve());
   }
  
   public static void main(String[] args) {
      
       System.out.print("How many Objects of StudentScore=> ");
       Scanner scan = new Scanner(System.in);
       String val=scan.nextLine();
       int num=Integer.parseInt(val);
       for(int i=0; i<num;i++){
           System.out.print("Enter student "+(i+1)+" name => ");
           String name=scan.nextLine();
           System.out.print("How many score for "+name+" => ");
           int scoreNum=scan.nextInt();
           scan.nextLine();
           System.out.println("Enter all "+scoreNum+" scores =>");
           double sValues[]= new double[scoreNum];
           for(int j=0;j<scoreNum;j++){
               sValues[j]=scan.nextDouble();
               scan.nextLine();
           }
          
           StudentScore s= new StudentScore(name,sValues);
           System.out.println("info for student "+(i+1));
           System.out.println(s.toString());
       }
   }

  
  
}

-output--

How many Objects of StudentScore=> 2
Enter student 1 name => Alan
How many score for Alan => 2
Enter all 2 scores =>
10
20
info for student 1
Number of the object created: 1
Student name: Alan
Exam scores:10.0   20.0  
average 15.0
Enter student 2 name => Walker
How many score for Walker => 3
Enter all 3 scores =>
10
20
30
info for student 2
Number of the object created: 2
Student name: Walker
Exam scores:10.0   20.0   30.0  
average 20.0

-output---

Note: Feel free to ask Question in case of any doubt. God bless you!