
May 4th, 2008, 10:09 AM
|
|
Registered User
|
|
Join Date: May 2008
Posts: 1
Time spent in forums: 39 m 48 sec
Reputation Power: 0
|
|
|
Homework - ScoresArray (Class has array contained in instance variable)
Hello. I would appreciate it, if someone could look at this program and help me out. I think I have a good start. Maybe everyone can help me out with a specific step? (One person does step 1, the other does step 2, etc).
Directions for code:
http://www.fileden.com/files/2007/4/25/1016937/ScoresArray.doc
Code:
// Nishant Jindal
// May 5th 2008
// ScoreArray (JN49_2)
class ScoreArray
{
// instance variables // step 1
private int[] scores = new int [0];
int numScores = 0;
// constructor // step 2
ScoreArray(int maxScores, int nScores)
{
scores = new int [maxScores];
nScores = 0;
numScores = nScores;
}
// methods
public String toString() // step 3
{
String msg = "{";
for ( int i = 0; i < scores.length; i++)
{
if (msg.length() > 1)
msg += ", ";
msg += scores[i];
}
return msg + "}";
}
// msg = "Number of slots in array: " + scores.length;
// return msg;
// }
public void addScore(int score) // step 4
{
}
public int lowScore() // step 5
{
int lowestScore = 0;
return lowestScore;
}
public int positionSmallest(int startPosition) // step 6
{
int smallestPos = 0;
return smallestPos;
}
public void swap (int position1, int position2) // step 7
{
int x = 0;
x = scores[position1];
scores[position1] = scores[position2];
scores[position2] = x;
}
public void lowToHigh() // step 8
{
}
}
class ScoreArrayTest // step 9
{
public static void main (String[] args)
{
}
}
|