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

Create a student object that has the following characteristics; name and an arra

ID: 3769714 • Letter: C

Question

Create a student object that has the following characteristics; name and an array of grades (i.e., 4 test scores). The four test scores reflect four distinct tests (i.e., test1, test2, test3, test4). Create an array list of students. Initialize and add four students to the array list. Subsequently do these operations. All these should be implemented in a separate method:

• Print the name of all the students in the list (forward). Print the names in uppercase. (3 points)

• Print the name of all the students in the list (reverse). Print all uppercase (3 points)

• Print the name and one test (e.g., test1). If the test score is odd, make it to the nearest even. If the test score is even then divide by 2 (10 points)

• Print the student name with the highest average test scores - print name and average (10 points)

• Remove the student object with the lowest test average. (5 point)

• shuffle the array list and print the list (forward and reverse) (2 point)

• Create a new array list containing two students: add the list to the previous list. Print the list containing both (first and the second list) (3 point)

• 4 points for implementing all these operations as methods

Explanation / Answer

/***
* The java program that implements all functions as methods
* and print their corresponding results to console
* */
//TestStudent.java
import java.util.ArrayList;
public class TestStudent
{
   public static void main(String[] args)
   {
      
      
       //Create an array list of type Student
       //Add four Student objects
       ArrayList<Student>arrayList=new ArrayList<Student>();
       double std1scores[]={4,3,2,1};
       arrayList.add(new Student("Jarina", std1scores));
       double std2scores[]={1,3,4,1};
       arrayList.add(new Student("Johnson", std2scores));
       double std3scores[]={1,3,3,2};
       arrayList.add(new Student("Panaj", std3scores));
       double std4scores[]={4,3,4,2};
       arrayList.add(new Student("Sekhar", std4scores));
      
       System.out.println("Print Names");
       System.out.println("----------------");
       //print names
       printNames(arrayList);
      
       System.out.println("Print Names in Reverse");
       System.out.println("----------------");
       //print reverse order
       printReverse(arrayList);
      
       System.out.println("Print Test Score");
       System.out.println("----------------");
       //print test scores
       printTestScore(arrayList);  
      
       System.out.println("Print Highest average Test Score");
       System.out.println("----------------");
       //print high average test score
       printHighAverageTestScore(arrayList);
      
       System.out.println("Print Lowest average Test Score");
       System.out.println("----------------");
       //print lowest test scores
       printLowAverageTestScore(arrayList);  
      
      
       System.out.println("shuffle student objects");
       System.out.println("----------------");
      
       //calling shuffle method
       shuffle(arrayList);  
      
       System.out.println("Print shuffle student objects");
       System.out.println("----------------");
       //calling printNames(arrayList)
       printNames(arrayList);
      
       System.out.println("Adding two new Student objects");
      
       //Create a newlist
       ArrayList<Student>newlist=new ArrayList<Student>();
       //Add two Studnets to the newlist
       double score1[]={3,3,4,4};
       newlist.add(new Student("Manas", score1));
       double score2[]={4,4,2,1};
       newlist.add(new Student("Jain", score2));
      
       ArrayList<Student>combinedList=add(arrayList,newlist);
       System.out.println("printing combined list");
       System.out.println("--------------------------");
       printNames(combinedList);
      
      
   }

   //Method that add arraylist and newlist and returns the combined list
   private static ArrayList<Student> add(ArrayList<Student> arrayList, ArrayList<Student> newlist)
   {      
       ArrayList<Student>combinedList=new ArrayList<Student>();      
       for (int i = 0; i < arrayList.size(); i++) {          
           combinedList.add(arrayList.get(i));          
       }
       for (int i = 0; i < newlist.size(); i++) {          
           combinedList.add(newlist.get(i));      
       }      
       return combinedList;
      
   }

   //Method shuffle that shuffles the array list
   private static void shuffle(ArrayList<Student> arrayList)   
   {
        for ( int i = arrayList.size()-1; i > 0; i-- )
        {
            int rand = (int)(Math.random()*(arrayList.size()-1));
            Student temp = arrayList.get(i);
            arrayList.remove(i);
            arrayList.add(i, arrayList.get(rand));
            arrayList.remove(rand);
            arrayList.add(rand,temp);
        }
  
   }

  
   //Method that prints the highest average test score
   private static void printHighAverageTestScore(ArrayList<Student> arrayList) {
      
       double maxaverage=0;          
       maxaverage=arrayList.get(0).getTest1()+
               arrayList.get(0).getTest2()+
               arrayList.get(0).getTest3()+
               arrayList.get(0).getTest4();
      
       String name=arrayList.get(0).getName();
       for (int index = 1; index < arrayList.size(); index++) {                  
           double score=arrayList.get(index).getTest1()+
                   arrayList.get(index).getTest2()+
                   arrayList.get(index).getTest3()+
                   arrayList.get(index).getTest4();          
           if(score>maxaverage){
               maxaverage=score;
               name=arrayList.get(index).getName();
           }
       }
      
       System.out.println("Student with maximum average score");
       System.out.println("Name : "+name);
       System.out.println("Average : "+maxaverage);
      
   }
  
   //Method that prints the lowest average test score
   private static void printLowAverageTestScore(ArrayList<Student> arrayList)
   {
      
       double minaverage=0;          
       minaverage=arrayList.get(0).getTest1()+
               arrayList.get(0).getTest2()+
               arrayList.get(0).getTest3()+
               arrayList.get(0).getTest4();      
       String name=arrayList.get(0).getName();
       for (int index = 1; index < arrayList.size(); index++) {                  
           double score=arrayList.get(index).getTest1()+
                   arrayList.get(index).getTest2()+
                   arrayList.get(index).getTest3()+
                   arrayList.get(index).getTest4();          
           if(score<minaverage){
               minaverage=score;
               name=arrayList.get(index).getName();
           }
       }      
       System.out.println("Student with minimum average score");
       System.out.println("Name : "+name);
       System.out.println("Average : "+minaverage);
      
   }

   //Method that prints the name and test scores
   private static void printTestScore(ArrayList<Student> arrayList) {
      
       for (int index = 0; index < arrayList.size(); index++) {
           double score=arrayList.get(index).getTest1();
           if(score%2==1)
               score++;
           else
               score=score/2;          
           System.out.println("Name: "+arrayList.get(index).getName());
           System.out.println("Score: "+score);
       }
   }

  
   //Print names in upper case letters
   private static void printNames(ArrayList<Student> arrayList)
   {      
       for (int index = 0; index < arrayList.size(); index++) {          
           System.out.println(arrayList.get(index).getName().toUpperCase());
       }
      
   }
  
   //Print list in reverse order in upper case letters
   private static void printReverse(ArrayList<Student> arrayList)
   {      
       for (int index = arrayList.size()-1; index >=0; index--) {          
           System.out.println(arrayList.get(index).getName().toUpperCase());
       }
      
   }
}


---------------------------------------------------------------------

Sample Output:

Print Names
----------------
JARINA
JOHNSON
PANAJ
SEKHAR
Print Names in Reverse
----------------
SEKHAR
PANAJ
JOHNSON
JARINA
Print Test Score
----------------
Name: Jarina
Score: 2.0
Name: Johnson
Score: 2.0
Name: Panaj
Score: 2.0
Name: Sekhar
Score: 2.0
Print Highest average Test Score
----------------
Student with maximum average score
Name : Sekhar
Average : 13.0
Print Lowest average Test Score
----------------
Student with minimum average score
Name : Johnson
Average : 9.0
shuffle student objects
----------------
Print shuffle student objects
----------------
PANAJ
SEKHAR
JOHNSON
JARINA
Adding two new Student objects
printing combined list
--------------------------
PANAJ
SEKHAR
JOHNSON
JARINA
MANAS
JAIN

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote