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

Help please!! Best and correct answer gets 900 points!! Thanks in advance!! In t

ID: 3771150 • Letter: H

Question

Help please!! Best and correct answer gets 900 points!! Thanks in advance!!

In the Grade Report programming example, the class Student contains two array instance variables, coursesEnrolled and courseGrades, to store the courses a student is taking and the grades in those courses. Redo the grade Report programming example by defining the CLASS: CourseAndGrade that has two instance variables--courseEnrolled of type Course and courseGrade of type char. Add appropriate constructors and methods in this CLASS to manipulate the instance variables. In the CLASS Student, use an array instance variable cousesEnrolled of type CourseAndGrade to store the couses a student is taking and the grade for each course.

Explanation / Answer

This below java code is written as per given in problem statement.
1. Created class called CourseAndGrade which have the data members described in problem.
2. Created default constructor with default values
3. Created setValues method to initialise the data from student class.
4. created display method to display the data.
5. Created class student class with display method ..
6. Created object for CourseAndGrade class inside student class and passed arguments to CourseAndGrade class.
7. Created main method with object declaration of student class.
8. Passed arguments to student display method so that it will pass to CourseAndGrade setValues method.

class CourseAndGrade
{
   private String[] courseEnrolled = new String[100];
   private char[] courseGrade = new char[100];

   // Default CourseAndGrade constructor assign empty
   public CourseAndGrade()
   {
       for(int i = 0; i <10; i++)
           {
               courseEnrolled[i] = "";
               courseGrade[i] = '0';
           }
   }

   // Default CourseAndGrade constructor assign with parameters
   public void setValues(String course[], char grade[])
   {
       for(int i = 0; i <course.length; i++)
           {
               courseEnrolled[i] = course[i];
               courseGrade[i] = grade[i];
           }
   }

   // Display CourseAndGrade Information with Course Name and Grade
   public void display()
   {
       for(int i = 0; i < 10; i++)
       {
           System.out.println("Course is :"+courseEnrolled[i]+" Grade is :"+courseGrade[i]);
       }
   }


}
public class student1
{
   CourseAndGrade obj;
   public void display(String course2[], char grade2[])
   {
       obj = new CourseAndGrade();      
       obj.setValues(course2,grade2);
       obj.display();
   }

   public static void main(String[] args)
   {
       String course1[] = {"CSE", "ECE", "IT", "MCA", "MPA","TLC","HCL","HLC","POR","JOI"};
       char grade1[] = {'A','B','A','D','E','F','A','G','J','D'};
       student1 s = new student1();
       s.display(course1,grade1);
   }
}