This class handles entering only one grade for a student.

  It is contained by class Student and accesses class StudentGrades.


  Author: Ahmad Mobasseri


import java.util.Scanner;


public class StudentAGrade


// Data

// Since only one method then made all data local.


// Constructor

//public StudentAGrade()      {     }


// Enter a grade, by prompting the user to specify which grade type, sequence number and grade.

// 1st parameter: 'h' for homework, 'p' for project, 'e' for exam

// 2nd parameter: '1' for a homework or project or exam number 1 and so on

// 3rd parameter: ':' as a dilimeter

// 4th parameter: the grade.

// Example: h2:3 for homework 2, grade is 3.   

      public static void enterAGrade(StudentGrades studentGrades) //Since only one method in this class, 

      {                 // then made it static then no need to create object of this class just to call 1 method

            String arrayNum;

            int arrayNumInt;

            String hwArrayElement;

            String projArrayElement;

            String examArrayElement;


            String tempAGrade="";

            System.out.println("Enter a task and grade (ex: h2:3)");

            Scanner scanner = new Scanner(System.in).useDelimiter("\\s*\n\\s*");

            tempAGrade = scanner.next();

            arrayNum = tempAGrade.substring(1,2);

//          int arrayNumInt = (int)tempAGrade.charAt(1) - (int)'0';   //NOTE: how to do by char

            arrayNumInt = Integer.parseInt(arrayNum);

            arrayNumInt -=1;




            case 'h': hwArrayElement = tempAGrade.substring(3, tempAGrade.length());

                    studentGrades.setHwArrayElement(hwArrayElement, arrayNumInt);


            case 'p': projArrayElement = tempAGrade.substring(3, tempAGrade.length());

                    studentGrades.setProjArrayElement(projArrayElement, arrayNumInt);


            case 'e': examArrayElement = tempAGrade.substring(3, tempAGrade.length());

                    studentGrades.setExamArrayElement(examArrayElement, arrayNumInt);    


        default:  System.out.println("Invalid entry");