This week we have done a mini project in groups. Jamie and I are finally in a group and we chose Project C. The main purpose of the project is to encapsulate the concept of grades on a test and assume that students grade are composed of a list of integers between 0 and 100. According to the question, the title of should be “test” and object inside test are grades of different tests. Then we create another class called “client”, which is used to run or test the methods. As the question has required “all grades can be randomly generated”, we need to import Random from Java predefined method first.
First of all, we created a constructor with only one parameter, which is the number of students. Then we created a new integer array and assigned the size of the array. We wrote a for-loop to assign random numbers to the array.

Then we wrote an accessor method to return the grade at designated index and a mutator which could set new grade to a designated index.

The first method we wrote a toString method which was to put the array to a String. Firstly, we created a new String called temp. Secondly, by running for-loop, we put the grade each index one by one into the new String, temp. Finally, we return the String temp.
The second method is equaled method. The parameter was two integers which represented the two indexes of grades users want to check whether they are equal or not. We create a boolean called result. Then we used an if-else statement to check. Finally, we return the boolean result.

The purpose of the third method is to do ascending sort by using bubble sort. Finally, it returns the ascending array.

The fourth method is to find mode, which means that the program is going to find numbers which occur in the list most frequent. We created a new array called counter which is used to find how many times a grade has occurred in the array. Then we created a new integer called max. In a for-loop, we found the maximum number in an array. At last, we return the integer in the array grades with the same index of max.

The fifth method is to find the median. Firstly, we sorted array grades in ascending order. The meaning of median is the value separating the higher half from the lower half of a data sample. So we could definitely return the number in the middle of the array.

The sixth method is to find the highest score of the test. First, we used bubble sort to form an ascending array. Then we return the grade with the largest index in grades.
The last method is to find the average score of the test. To be more accurate, we set average as primitive data type double. We add all grades in the test and divide the sum by the number of students. Then we return the average score.

Finally, we tested the program with the client. At first, there were some errors. We tried hard to debug these problems. At first, our program is not user-friendly. Then Mr. Pete suggested us to add more connections with users. Then we changed our program and we let users to input value of parameters by themselves. We eventually succeeded. Our satisfactions were fulfilled at that moment.



Through the mini-project, I have learned that we need to read the question carefully because there might be some hidden messages in the question. For example, at first, we set the class name as “MiniProjectC”. After Mr. Peter’s warning, we found that the main method should be called “test”, which is a hidden message in the question “encapsulate the concept of grades on a test”. Of course, there were frictions between Jamie and me, but both of us learned from the frictions. In this mini-program, I found that it was not a simple task when writing the code. I really enjoyed the process. I am looking forward to the next week!