Hello, im having problems when i compile this program. After setParam is invoked
ID: 3635246 • Letter: H
Question
Hello, im having problems when i compile this program. After setParam is invoked. Fillarray is giving me Invalid entry when user enter 'f' or 'F' import java.io.IOException; import java.util.Scanner; import java.util.Random; public class Finals { public static void main(String[] args) throws IOException { int c; // user choice int nStudents; // number of students int nQuizes; // number of quizes int SPok; // set parameters int FAok; // fill array long[] studentIDs = new long[DefineConstants.MAXSTUDENTS]; int[][] studentQScores = new int[DefineConstants.MAXSTUDENTS][DefineConstants.MAXQUIZES]; SPok = 0; FAok = 0; nStudents = 0; nQuizes = 0; System.out.println("***************************************************"); System.out.println(" WELCOME TO THE GRADEBOOK, PREPARE TO BE AMAZED!!!"); System.out.println("***************************************************"); while (true) { System.out.print(" Quit Help SetParams FillArray DisplayResults "); System.out.print(" Select Q H S F or D and press Enter: "); while ((c = System.in.read()) == ' '); if (c == 'q') c = 'Q'; if (c == 'h') c = 'H'; if (c == 's') c = 'S'; if (c == 'f') c = 'F'; if (c == 'd') c = 'D'; switch (c) { case 'Q': Quit(); break; case 'H': getHelp(); break; case 'S': setParams(nStudents, nQuizes); SPok = 1; FAok = 0; break; case 'F': if (SPok != 0) { fillArray(studentIDs, studentQScores, nStudents, nQuizes); FAok = 1; } else System.out.print("You must SetParams first "); break; case 'D': if (FAok != 0) displayResults(studentIDs, studentQScores, nStudents, nQuizes); else { if (SPok != 0) System.out.print(" You must FillArray first "); else System.out.print(" You must SetParams first "); } break; default: System.out.printf("Invalid entry <%c>", c); break; } } } private static void displayResults(long[] sIDs, int[][] sQScores, int nS, int nQ) { int i; int j; int n; int MAXQUIZES = 5; double[] quizAvgs = new double[MAXQUIZES]; int[] quizMaxs = new int[MAXQUIZES]; int[] quizMins = new int[MAXQUIZES]; int[] quizMeds = new int[MAXQUIZES]; byte[][] quizGrid = new byte[MAXQUIZES][101]; // Grade rang 0 - 100 --> // 101 Elements for (i = 0; i < nQ; i ) { quizAvgs[i] = 0.0; quizMaxs[i] = 0; quizMins[i] = 100; for (j = 0; j < 101; j ) quizGrid[i][j] = 0; } System.out.print(" Student ID:"); for (j = 0; j < nQ; j ) System.out.printf("Quiz ", j 1); for (i = 0; i < nS; i ) { System.out.printf(" %d", sIDs[i]); for (j = 0; j < nQ; j ) { System.out.printf(" =", sQScores[i][j]); quizAvgs[j] = (i * quizAvgs[j] sQScores[i][j] / (i 1)); if (sQScores[i][j] > quizMaxs[j]) quizMaxs[j] = sQScores[i][j]; if (sQScores[i][j] < quizMins[j]) quizMins[j] = sQScores[i][j]; quizGrid[j][sQScores[i][j]] = 1; } } for (i = 0; i < nQ; i ) { n = 0; for (j = 0; j < 101; j ) if (quizGrid[i][j] != 0) n ; n = (n 1) / 2; for (j = 0; j < 101; j ) if (quizGrid[i][j] != 0) n--; quizMeds[i] = j - 1; } System.out.print(" Maxs:"); for (i = 0; i < nQ; i ) System.out.printf("=", quizMaxs[i]); System.out.print(" Mins:"); for (i = 0; i < nQ; i ) System.out.printf("=", quizMins[i]); System.out.print(" Avgs:"); for (i = 0; i < nQ; i ) System.out.printf("%6.2f", quizAvgs[i]); System.out.print(" Meds:"); for (i = 0; i < nQ; i ) System.out.printf("=", quizMeds[i]); System.out.print(" "); } private static void fillArray(long[] sIDs, int[][] sQScores, int nS, int nQ) { int i; int j; int FIRSTSID = 75678; for (i = 0; i < nS; i ) { (sIDs)[i] = FIRSTSID i; for (j = 0; j < nQ; j ) (sQScores)[i][j] = (int) (((float) rand()) / 324.5); } } private static float rand() { Random rand = new Random(); int number = 0; { for (int counter = 1; counter <= 1; counter ) { number = rand.nextInt(100); System.out.println(number); } } return number; } private static void setParams(int nS, int nQ) { int n; new String(new char[80]); Scanner keyboard = new Scanner(System.in); n = 0; while (n < 1 || n > 50) { System.out.print("Please enter the number of students(1-50):"); n = keyboard.nextInt(); } nS = n; n = 0; while (n < 1 || n > 5) { System.out.print("Please enter the number of quizes per student(1-5):"); n = keyboard.nextInt(); } nQ = n; } private static void getHelp() { System.out.println(" ______________________HELP MENU__________________________" " Welcome to the Help Menu, here you will find tips to using this program." " " " The first step is to click the 'SET PARAMETERS' button. Here you will " " input the number of students (up to 50) and number of quizzes for each " " student (up to 5.) " " " " Next you will select the 'FILL ARRAY' button. This button will open up" " the menu to select the ID numbers and quiz grades for each student and " " quiz, then store them within the paremeters set in 'SET PARAMETERS'." " " " Finally you will click the 'DISPLAY' button. This button will compile all" " the data you entered in the last two sections and display the results." " This program computes and displays the lowest, highest, average, and" " medium for each grade of each set of quizzes." " " " As an added note if you wish to quit this program at any time, simply" " press the 'QUIT' button and the program will close"); } private static void Quit() { System.out.print(" ADIOS "); System.exit(0); } final class DefineConstants { public static final int MAXSTUDENTS = 50; public static final int MAXQUIZES = 5; public static final int FIRSTSID = 75678; } }Explanation / Answer
I've done the edited code on my computer which is compiling well but there's no time left, so I couldn't answer Please rate me lifesaver and i'll make sure the answer is in your inbox! i don't do this generally but due to this reason i am... please understand
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.