 |
 |
I need Java help!
|
 |
|
 |
|
Senior User
Join Date: Dec 2002
Location: Canada.
Status:
Offline
|
|
import psJava.KeyIn;
public class ExamStats {
private int [ ] scores;
public ExamStats (int num) {
scores = new int [num];
}
public void readScores () {
for (int i = 0; i < scores.length; i++)
scores[i] = KeyIn.readInt("Exam score for the next student:");
}
public int findMin () {
if (scores.length > 0) {
int minSoFar = scores[0];
for (int i = 1; i < scores.length; i++) {
if (scores[i] < minSoFar)
minSoFar = scores[i];
}
return minSoFar;
}
else
return 0;
}
public int findMax () {
if (scores.length > 0) {
int maxSoFar = scores[0];
for (int i = 1; i < scores.length; i++) {
if (scores[i] > maxSoFar)
maxSoFar = scores[i];
}
return maxSoFar;
}
else
return 0;
}
public double computeAverage () {
int sum = 0;
for (int i = 0; i < scores.length; i++)
sum += scores[i];
if (scores.length > 0)
return (double)sum / (double)scores.length;
else
return 0;
}
public double computeStaDeviation(double average) {
int sumSquares = 0;
for (int i = 0; i < scores.length; i++)
sumSquares += scores[i] * scores[i];
if (scores.length > 0)
return Math.sqrt((double) sumSquares / scores.length - average * average);
else
return 0;
}
public String toString () {
String examStr = "";
for (int i = 0; i < scores.length; i++) {
examStr = examStr + scores[i] + " ";
}
return examStr;
}
}
Compile Time Errors (the bold text):
Error: package psJava does not exist
Error: cannot find symbol
symbol : variable KeyIn
location: class ExamStats
Basically I do not understand how to remedy this. I tried searching online and through my notes, and I cannot find an answer.
|
|
..13" MacBook Pro | 2.53gHz | 4gb RAM | 320gb Seagate Momentus XT | OSX.6.6.. // iPhone 4 32gb
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Dec 2002
Status:
Offline
|
|
You haven't instantiated the KeyLn object first in that procedure. A correction would look something like this:
public void readScores () {
Keyln input = new Keyln();
for (int i = 0; i < scores.length; i++)
scores[i] = input.readInt("Exam score for the next student:");
}
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Dec 2002
Location: Canada.
Status:
Offline
|
|
It's not KeyLn it's KeyIn. I've checked my notes, and the way I posted the code is exactly how it is in the notes. I do not get why this is happening.
|
|
..13" MacBook Pro | 2.53gHz | 4gb RAM | 320gb Seagate Momentus XT | OSX.6.6.. // iPhone 4 32gb
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Nov 2005
Location: Seattle, WA, USA
Status:
Offline
|
|
Nonetheless, you still need to instantiate the object. sray must have meant "KeyIn", and not "KeyLn". Otherwise, his suggestion is valid.
|
Any ramblings are entirely my own, and do not represent those of my employers, coworkers, friends, or species
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Dec 2002
Location: Canada.
Status:
Offline
|
|
Actually it was caused because I didn't have the psJava package in my extensions.
I do appreciate your posts though because they're still useful to me.
|
|
..13" MacBook Pro | 2.53gHz | 4gb RAM | 320gb Seagate Momentus XT | OSX.6.6.. // iPhone 4 32gb
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Oct 2004
Location: Downtown Austin, TX
Status:
Offline
|
|
Java puked all over that because it couldn't find the package. For future reference, Sun's provided packages usually start with Sun.java.* etc etc. Any other packages need to be copied to the extensions directory, but you know that now.
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Feb 2004
Status:
Offline
|
|
1) Any other packages need to be added to the application classpath! Adding something to the Extesions directory (the global classpath) is the worst you can do because it may screws other apps.
2) The readInt(...) method might be a static method in which case KeyIn.readInt(...) is correct.
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: May 2003
Status:
Offline
|
|
psJava is almost certainly a package provided for you by your professor. Contact your professor for help with getting your environment set up. If you are getting this code from elsewhere, you will not be able to use it without modifying it to use standard libraries.
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Oct 2001
Status:
Offline
|
|
When using the command line, look at the -classpath (and -cp) params to the javac and java commands. (Use man or java/javac [no args] for info on these)
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|