I am in beginning Java and using Dr. Java to write my programs. I am trying to write an array that user input sets up the length of the array(#of students) that character grades are stored in. It is suppose to ask if you want a full print out, to update a students grade, or to exit. please let me exactly what is that I am doing wrong, I did include the error codes it is throwing, making it impossible to test accurately.
Thank you for your help:
import java.io.*; // import needed files
import java.util.*; // import more needed files
public class Grades{
public static void main (String []args){
int m, sid, asid, y, id, counter; //declare int variables
SimpleInput keyboard = new SimpleInput (); // for user input
System.out.println("Greetings, welcome to the class grade tracking system. ");
System.out.println("How many students are in the class?");
id = keyboard.nextInt();// first user imput asked to set up length of array
System.out.println("What would you like to do next? Please pick an option from the following menu.");
char grade[]= new char [id]; //declare array
for (int j=0; j<=1; j++){ //beginning of menu loop
{
System.out.println("Menu");
System.out.println("----");
System.out.println("1) Print Gradebook");
System.out.println("2) Update Grade");
System.out.println("3) Exit");
for (int i=0; i<=1; i++){ // beginning of grade input loop
m = keyboard.nextInt();
if (m == 2);{
System.out.println("Enter student id to update:");
sid = keyboard.nextInt();
if (sid < 1);System.out.println("Invalid ID. Please try again.");
i++;}
if (sid >=1);{
asid = sid - 1;
System.out.println("Enter new grade for "+sid+":");
char g = keyboard.nextChar(); //('cannot find symbol error keeps appearing...')
grade[asid] = 'g'; //stores letter grade in appropriate place in Array
System.out.print("New Grade for student # " + sid + "is " +g+ ".");
{
while(sid <1 || sid > id);{
System.out.println("Invalid ID. Please try again."); //incorrect int throws error
j++;} // sends user back to menu to try again.
}
if (m > 3 || m < 1)
System.out.println("Invalid choice. Please try again.");}
j++;} //sends user back to menu to try again.
if (m == 1);{ //variable m might not have been initialized
for (y = 0;y<=grade.length;y++); //create output loop for student and grade printout
int x= y + 1; //no one likes to be called student zero
System.out.println("Student" + x + "has a current grade of " +grade[y]);{ //prints student and letter grade.
}
if(m == 3);{ //(throws error 'variable m might not have been initialized') // if three is selected in main menu, program is exited.
System.out.println("Exiting Gradebook...Goodbye!"); }
}
}}}}