Class Test 2 - Memo
Class Test 2 - Memo
Name of Moderator
_____________________
IMPORTANT INSTRUCTIONS
a) Create a class called TestScores that keeps a record of student tests. The class should have the
two data field that declares an array as testScores and initialize it to {60, 50, 67}, the moduleName
to capture the module names. Within the TestScore class include the following:
Declaration and initialization of TestScore Array: (2)
private int[] testScores = {60,55,67};√√
A set and get method for the testScores and moduleName (12)
Solution:
return moduleName; √
this.moduleName = moduleName; √
testScores[number] = score; √√
return testScores[number]; √√
Solution:
b) Create an application known as TestScoreDemo that displays the default test scores. (4)
Solution:
module.display();√√
c) Amend the application you created in question 1b) to include the following:
1. Declare an object that allows the user to add two modules that the student marks will be
linked to. (2)
Solution:
2. Prompt the user to input two modules (NPRG62120 and NITE62110) and the student marks
for each module. (12)
o NB: The test scores should be linked to an individual module. For instance, the test
scores for NPRG62120 are {80, 65, 55} and NITE62110 are {55, 68, 89}.
Solution:
name = input.nextLine();
modules[y].setModuleName(name); √√
score = input.nextInt();
modules[y].setTestScores(x, score); √√
input.nextLine();√√
}
}
3. Display the student marks per module as captured in question c2). (8)
Solution:
System.out.println();
4. Include the segment of code that will allow the user to search for a particular module and the
program should respond by displaying the module and the marks of the students linked to the
module. (10)
Solution:
name = input.nextLine();½
if(name.equals√(modules[y].getModuleName()))√√
System.out.println(modules[y].getTestScores(x)+ ""); √√
System.out.println();
d) Create a new class called TestScore1 and copy the segments of code in TestScore to the newly
created class TestScore1. (4)
o Within TestScore1, move the segments of code in question c (1- 4) and store them into a
nonstatic method called getTestMarksData that receives a TestScore1 parameter. (6)
Solution:
package testscoresjune;
import java.util.Scanner;
/**
* @author Eva.Mamabolo
*/
public class TestScore1 { [4] Creating a new class and copy the copy across
return moduleName;
this.moduleName = moduleName;
testScores[number] = score;
return testScores[number];
String name;
int score;
module.display();
System.out.println(" ");
int x, y;
name = input.nextLine();
modules[y].setModuleName(name);
score = input.nextInt();
modules[y].setTestScores(x, score);
input.nextLine();
System.out.println();
name = input.nextLine();
if(name.equals(modules[y].getModuleName()))
System.out.println(modules[y].getTestScores(x)+ "");
System.out.println();
e) Create a new application called TestScore1Data that will display the student marks. (4)
Solution:
public class TestScoreJune1 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {