Hi I am new in this forum. I need some help with this code and is for my intro to programming class. I did it following a pseudocode I found in other website but I am totally confused now. It is not working. Do nothing. Thanks
This is the assigment "Watson Elementary School contains 10 classrooms numbered 1 through 10. Each classroom can contain any number of students up to 35. Each student takes an achievement test at the end of the school year and receives a score from 0 through 100.
a. Write a Java program that accepts data for each student in the school—student ID, classroom number, and score on the achievement test then prints the classroom's average of the test scores. This program should use one or more arrays. Submit your code."
This is my code:
import javax.swing.JOptionPane;
public class Watson
{
public static void main(String args[])
{
String StringID, StringClassNum, StringScore = null;
int stuID;
int classNum = 0;
int score=0;
int avg = 0;
int SIZE = 10;
int QUIT = 999;
int numStud=35;
int totalScore []= new int [numStud] ;
int countClass[] = new int [SIZE];
StringID = JOptionPane.showInputDialog("Enter a student ID or " +
QUIT + " to quit ");
stuID = Integer.parseInt(StringID);
while(stuID != QUIT)
{
StringClassNum= JOptionPane.showInputDialog("Enter the classroom number for student");
classNum= Integer.parseInt(StringClassNum);
if (classNum >= 1 && classNum <= SIZE )
{
countClass[classNum-1] = countClass[classNum-1] + 1;
StringScore= JOptionPane.showInputDialog("Enter the score for student");
score= Integer.parseInt(StringScore);
totalScore[classNum-1] = totalScore[classNum-1] + score;
StringID = JOptionPane.showInputDialog("Enter a student ID or " +
QUIT + " to quit ");
stuID = Integer.parseInt(StringID);
}
else
System.out.println("Invalid classroom number");
}
while (classNum < SIZE)
{
if (countClass[classNum] == 0)
{ avg= 0;}
else
{
avg =totalScore[classNum]/countClass[classNum];
System.out.println(classNum );
System.out.println(avg);
}
}
classNum = classNum + 1;
}
}