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

The following classes are defined, this is for me to study for my next test. Aft

ID: 3714542 • Letter: T

Question

The following classes are defined, this is for me to study for my next test. After all the classes are listed, there are some questions. The language is java too.

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

public class Course
{
     private String title;
   private int courseNumber;
   private int grades[];

     //initial values constructor
      public Course(String t, int cn, int g[]){
      title=t;
      courseNumber=cn;
      grades=g;
      }
           
      //get methods
      public String getTitle(){return title;}
      public int getCourseNum(){return courseNumber;}
      public int[] getGrades(){return grades;}

      //method to find average grade
      public double Average(){
      double sum=0;
      for(int i=0; i             sum=sum+grades[i];
      return sum/grades.length; // return average
      }
     
      //method that return maxim grade for a class
      public int maxGrade(){
      int max=grades[0];
      for(int i=1;i          if(grades[i]>max)
             max=grades[i];
      return max;
      }
     
      public String toString(){
      return String.format("%3d %s",courseNumber,title);
      }
}
---------------------------------------

public class Student
{
   private String name;
   private Course listOfCourse[];

   //initial valued constructor
   public Student(String n, Course list[]){
   name=n;
   listOfCourse=list;
   }
   
   //get methods
   public Course[] getList(){return listOfCourse;}
   public String getName(){return name;}

   //method to determine best courses based on Average grade
   //method returns the course with best average grade
   public Course Best(){
   Course c;
   c=listOfCourse[0];
   for(int i=1;i       if(c.Average()          c=listOfCourse[i];
   return c;
   }
  

   //toString method
   public String toString(){
   return name;
   }
}                                                                                                                                                       
---------------------------------------

public class Instructor
{
   private String name;
   private Student list[]; //list of students

   //inial valued constructor
   public Instructor(String n, Student s[])
   {
   name=n;
   list=s;
   }
  
   //get methods
   public Student[] getStudent()
   {
      return list;
   } // returns all the students of an instructor
}

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

public class Test {
    public static void main(String[] args)
    {
      int g1[]={90,89,40,70};
      int g2[]={100,90,80,70,100};
      int g3[]={89,95,80,70};
      int g4[]={99,79,80,60};
      int g5[]={100,100,80,90,100};
    int g6[]={100,50,80,95,100};
       
      Course list1[]=new Course[4];
      list1[0]=new Course("Programming 1", 180,g1);
      list1[1]=new Course("History", 120, g2);
      list1[2]=new Course("Mathematics", 136,g3);
      list1[3]=new Course("Data Mining", 251,g4);
        
      Course list2[]=new Course[2];
      list2[0]=new Course("Art", 104,g5);
      list2[1]=new Course("Music", 100,g6);
          
      Student L[]=new Student[2];
      L[0]=new Student("Sara", list1);
      L[1]=new Student("Mike",list2);
  
      Instructor A=new Instructor("James Gary",L);  
      }
}

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

1. What are the values of x,y,z?

x=A.getStudent()[1].getList()[0]

y=A.getStudent()[1].Best()

z=A.getStudent()[0]

2. By using only object A(in the Test class), write a statement to determine Mike’s best class.

Explanation / Answer

Answer 1:

x=A.getStudent()[1].getList()[0]
Gets the 2nd student's 1st course i.e for Mike's 1st course which is the Course object Course("Art", 104,g5);

y=A.getStudent()[1].Best()
Gets the best course for 2nd student i.e Mike's best course. The Art Course object has best average compared to Music. So y also has the Course object Course("Art", 104,g5)

z=A.getStudent()[0]
Gets the first Student object which is Student("Sara", list1);


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

Answer 2:
A.getStudent()[1].Best() determine's Mike's Best score.
[Mike is student at index 1 and his best course is objtained by using Best() method in Student class]

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