Question
In this problem, we will exercise java object and classes. Create a class called StudentGrades and put that as StudentGrades.java. 1. It has the following
In this problem, we will exercise java object and classes. Create a class called StudentGrades and put that as StudentGrades.java.
1. It has the following variables:
a) a private class variable called studentCounter (int) and it is initialized to zero. b) a private instance variable called studentName (string) c) a private instance variable called scores [array of double]. d) a private instance variable called coursesLetterGrade [2D array of string]. This 2D array has scores.length number of rows and 2 columns. First column stores course name and second column stores letter grade for that course. However, you do not have to specify the size of the array at this moment. It should be done in the constructor described next.
2. It has a public static method getLetterGrade() that takes a double type score and return the corresponding letter grade based on the following grading scale: A: 90 100, B: 80-89.99, C: 70-79.99, D: 60-69.99, F: <60. 3. Create a constructor that takes a string and initializes the value of studentName. It also increases the value of studentCounter.
4. Create another constructor that takes a string name, a string course array, and a double score array. This constructor initializes the value of studentName, copy the score array to the scores array of the class, and fill up the courseLetterGrade 2D array with the course name and letter grades based on the score array. During this process, it takes the help of the getLetterGrade method. Note: For safety of the argument score array passed to this constructor, you must use System.arraycopy method to copy the array. Otherwise, a use of simple assignment of the array will copy the reference. We do not want the reference to be copied. This constructor also increases the value of studentCounter.
5. Create a method called getName() to return the value of the name. 6. Create a method called getAverageScore(). It returns the average score by calculating it (double). 7. Create a method called displayGrades(). It displays the student name first and then displays the course names, letter grades, and scores in a tabular format. One course per row. 8. Create a public method called getStudentCounter() that returns the current value of studentCounter. Create a test class that will utilize the StudentGrades class. Name of the class is StudentGradesTest and put it in StudentGradesTest.java. It contains the main function and it performs the following operations: 1. You will get the number of students (ns) and the number of courses (nc) from the command prompt. The maximum number of students and number of courses are 5. 2. In your program, you should use try-catch block in the appropriate places for exception handling of type ArrayIndexOutOfBound Exception. 3. Declare an array of 5 student names and initialize it with the following names: {Adam Smith, Nusair Ahmed, Muhammad Mustafa, Christian Thomsen, Debashish Roy} 4. Declare a course array of 5 courses with the following course names: {Java programming, Data Science, Database Systems, Computer Organization, Data Structure} 5. Create an array of size ns to store the scores. 6. Create an array for nc number of courses. We will pick first nc number of courses from course array declared above. 7. Create an array of ns number of StudentGrades class.
8. For each StudentGrades (lets say we are looping using i): a) Take ith student name from the student name array. b) Create a double array for nc number of scores and fill up the array with nc number of random integer generated using secured random number class. While generating the numbers, make them double (maybe by multiplying the number with 1.0). The range should be (45 to 95). c) Create the ith StudentGrades object by passing the name, the course and score array you generated in this loop.
9) Call the displayGrades() method for each object to display their grade details 10) Declare a double array and store the average score for each StudentGrade object. Use the getAverageScore() method of the objects for this purpose. 11) Then display the name of the student who got the highest average score. Use the getName() method for this purpose. Then use the getLetterGrade() method to display the letter grade of the highest average score. 12) Optional: use the java.util.Array class to sort the double array created in sequence 10 above. The print the sorted array. Finally, create an ArrayList with the content from the double array and print the ArrayList.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started