TOPIC: Introduction to classes, attributes, methods
In Assignment 4 we kept track of student numerical scores and equivalent letter grades. The scores were stored in an array, and the grades were stored in a second array. The relationship between the arrays was implicitly based on the index: for example, it was assumed that studentScore[3] is related to studentGrade[3] because they both are for student number 3. In object-oriented programming, we can make this relationship explicit by creating an object and keeping the data together in the object's properties. We can also include pieces of related code in the object's methods.
TASK
Your task is to write code that will be able to create Student objects and store the score and grade data together in the objects as properties. The student object will also be able to print its own data to the screen. You will also write code for a GradingScheme class that will have the functionality to convert any integer score to a letter grade. Then, you will create a user-specified number of students, generate random scores for the students, and convert them to letter grades. Finally, you will calculate the average score, rounded average score, and the average letter grade that corresponds to the rounded average score.
INSTRUCTIONS
1. Create a new class file Student in the project's source package. Write a Student class that will allow us to store student score and student grade in the same object. Also write a printStudent method that will print the student details to the screen.
a. The Student class should have these properties: public int students public int score public char grade
b. The printStudent method will print to the screen the data about the student object. Itshould print: Student ID: id; Score: the score is grade where id, score, and grade are the object's data properties. The method should have the following signature, i.e., it returns no value and it requires no parameter: public void printStudent()
2. Create a new class file GradingScheme in the project's source package. This class will have the functionality to convert an integer score to a letter grade by using its own built-in scheme, so we can use it to convert student scores to grades for all student objects.
a. Use the following to create the class constants:
public static final int [][] GRADING_SCHEME =...;
public static final int SCHEME_LETTER=0;
public static final int SCHEME_MINIMUM=1;
b. Write a method convertScore that will take an integer as a parameter and return its corresponding letter grade as a char. It should have the following signature:
public char convertScore(int score)
This method could be implemented as a if-else-if tree or more efficiently as a loop. The method starts with the numerical score in the score variable, and should classify it into a letter grade based on the GRADING_SCHEME array data. The method needs to return a char variable.
3.In the driver, write a test case to see if the Student and the GradingScheme code works:
a. Create a GradingScheme object and save its reference in a variable. HINT: This is similar to creating a Scanner object and saving it in a variable keyboard from the previous labs.
b. Create one Student object, save its reference in a variable and set its student id and studentscore properties to some test values.
c. Use the grading scheme object's conversion method to convert the student's object score to grade and save it in the student object's grade property. HINT: This can be done in one line or in multiple steps:
i. get the student object's score
ii. pass it to the grading scheme object's method for conversion
iii. store the result of the conversion
iv. set the student object's grade to the result
d. Print out the line "Test student:" and use the student object's printStudent method to print the student details. Make sure that the grade matches the score.e. For example, if the student's id is 786, and the student's score is 78, the output should be:
4. Once you're sure the code works, comment out the printing code.
5. Ask the user for a number of students to create.
6. Declare and dimension an array of appropriate size that will hold student objects as its elements. HINT: the variable type of the array elements is Student.
7. Use a loop to go through the array and do the following for each array element:
a. create a new Student object and save its reference in the array element for future use
b. set the Student object's id so that the students are numbered from 1 to (number of students)HINT: the array elements are numbered from 0 to (number of students-1), so use the loop counter appropriately
c. generate a random score for the student and store it in score. Use Random class' methodnextInt(int end) to get numbers from 0 to (end-1). Make student scores be in the range50-100 inclusive.
d. covert the student score to a letter grade by using the GradingScheme object's conversionmethod.
e. Finally, use the student's printStudent method to print the student details to the screenf.Note that for steps b-e you must use the saved reference to the student object from step a.
8. Use a loop to compute an average score of all students.
9. Use a Math's class round method to round the average score to a whole number. HINT: This method takes a double as a parameter and returns a long. Cast the long to an int to save the rounded value in an int variable.
10. Use the grading scheme object's conversion method to get an average letter grade from the rounded average score.
11. Print the average score, rounded average score, and average grade to the screen, see Sample output
This assignment has been answered 6 times in private sessions.
© 2024 Codify Tutor. All rights reserved