Assignment 1B - Scorelist Flashcards

1
Q

How would you make a private DeepCopy method?

A
private int[] deepCopy(int a[])
    {
        int[] temp = new int[a.length];
        for (int k = 0; k < a.length; ++k)
        {
            temp[k] = a[k];
        }
        return temp;
    }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

create a ScoreList default constructor that has a quantity parameter between 0 and 100 with random integers.

A
public ScoreList(int quantity) 
{
        Random rand = new Random();
        scores = new int[quantity];
    int max = 100;
    for(int i = 0; i < scores.length; i++) {
        scores[i] = rand.nextInt(max +1);
    }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Given the following javadoc information, create a
ScoreList constructor that utilizes the DeepCopy method:

/**

 * Constructor with Student Grades Provided
 * Initilized a nrely created ScoreList object initializing its scores array using the supplied array.
 * @param students, an array of student grades
 * /
A
public ScoreList(int students[])
    {
        scores = deepCopy(students);
    }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Create an accessor method using deepCopy and Scores.

A
public int[] getScores()
    {
        return deepCopy(scores);
    }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Create an mutator method using deepCopy and Scores.

A
public ScoreList setScores(int scores[])
    {
        this.scores = deepCopy(scores);
        return this;
    }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Create a toString to list the scores.

A
@Override
    public String toString()
    {
    String gradeString = "";
    for (int i = 0; i < scores.length; i++)
        gradeString += scores[i] + " ";
    return gradeString;
    }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Create an equals method to compare the scores.

A
@Override
    public boolean equals(Object o)
    {
        if(o instanceof ScoreList) {
            return Arrays.equals(scores, ((ScoreList)o).scores);
        }
        return false;
    }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Create a method that inputs an array of scores and returns letter grades.

A
public char[] getLetterGrades()
    {
        char[] letterGrades = new char[scores.length];
        int i=0;
        for(int m : scores)
        {
            if(m >= 90)
                letterGrades[i] = 'A';
            else if(m >= 80)
                letterGrades[i] = 'B';
            else if(m >= 70)
                letterGrades[i] = 'C';
            else if(m >= 60)
                letterGrades[i] = 'D';
            else
                letterGrades[i] = 'F';
            i++;
        }
        return letterGrades;
    }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Create a sortScores method

A

public int[] sortScores()
{
for(int i=0; i

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

create a highestScore method

A
public int highestScore ()
    {
        int max = scores[0];
        for (int i = 1; i < scores.length; i++)
        {
            if (scores[i] > max) { max = scores[i]; }
        }
        return max;
    }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

create a lowestScore method

A
public int lowestScore()
    {
        int min = scores[0];
        for (int i = 0; i < scores.length; i++)
        {
            if (scores[i] <= min)
            {
                min = scores[i];
            }
        }
        return min;
    }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Create a method that outputs an average

A
public double average()
    {
        int length = scores.length;
        double sum = 0;
        for(int i = 0; i
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Create a median method

A
public double median()
    {
        int n = scores.length;
        sortScores();
        if (n % 2 != 0)
            return (double)scores[n / 2];
        return (double)(scores[(n - 1) / 2] + scores[n / 2]) / 2.0;
    }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Create a mode method

A
public double mode()
    {
        int []modeArray=new int[101];
        int i,mode;
        for(i=0;imodeArray[mode])
                mode=i;
        return mode;
    }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly