Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

write an application that creates a simple grade class and then writes grade obj

ID: 3725373 • Letter: W

Question

write an application that creates a simple grade class and then writes grade object data to a random access file object XLab 7-intermediate Co x ! 2400 lor gleaf drive per sx1Gsolved: Java write An AF- https://hostsited21.uwf.edu/d2/le/content/1017419/viewContent/3103159/View ktop m Secure Comput... domAccessFile class in the Java API. ivity 2. Write an application that creates a simple Grade class and then writes Grade Object data domAccessFile object 1. Grade Class 1. Instance varlables: studentID:byte (8 bit integer), grade:double 2. Constructors -two constructor: one default and one constructor with new student ID and m grade as parameters. 3. Accessor and mutator methods Use Eclipse's functionality to create these method quickly. 4. toString) "Student 4's grade is 88.0 2. RandomAccessDemo Class 1. Creates at least 8-Grade objects and write them to a RandomAccessFile, no need to store t objects after they are written to the file. Hint use a loop to create and store the objects. Ma sure a record size is determined for each grade. 2. Develop user interface that 1. Locates a grade record based on placement in the file, for example the user might wan the 5th grade, or the 3rd grade 2. Prints a statement identifying the grade and its location such as The fourth grade is for and belongs to student 25" 3. Ask the user if they wish to look up another grade or quit. 3. The program must catch and successfully handle (continue with out exiting) 1. NumberFormatException or InputMismatchException depending how you handle collecti the user input. 2. Any required checked exception. member to zip up all files and turn them in the appropriate dropbox. Use the naming nvention outlined in the Programming Project Submission Instruction Send to Binder Download Pret Activity Details Task: View this topic oe

Explanation / Answer

CODE:

public class GradeAverage {

    public static Scanner kbd = new Scanner(System.in);

    //Method that will calculate the sum

    public static int sum( int[] gradeArray, int size){

        int sum = 0;

        int [] temp = gradeArray;//tem array is set equal to original array

        for (int i = 0; i<gradeArray.length; i++){

            sum +=temp[i];//array numbers are added to calculate sum

        }

        return sum;//calculated sum is returned

    }

    //method that will calculate the average by receiving array and size

    //method will return average.

    public static double average(int[] gradeArray, int size){

        double average;

        int[] temp = gradeArray;

        int sum = 0;

        for (int i = 0; i<gradeArray.length; i++){

            sum +=temp[i];

        }

        //System.out.println("The sum is: " + sum);

        average = (double)sum/(double)size;

        return average;

    }

    //letterGrade method will determine what letter grade will be returned.

    public static String letterGrade(double gradeAverage){

        String lettrGrade = "";

        int quotient = (int)gradeAverage/10; //quotient will deterimine LetterGrade

        int remainder = (int)gradeAverage%10; // remainder will determine if a "+ or -"

        switch(quotient){//switch statement for cases if grade is A, B, C, D, F

        case 10://100% so just return A+;

            return "A+";

        case 9: //90-89 is a A

            lettrGrade="A";

            break;

        case 8: //80-89 is a B

            lettrGrade = "C";

            break;

        case 7: //70-79 is a C

            lettrGrade="C";

            break;

        case 6: //60-69 is a D :

            lettrGrade = "D";

            break;

        default:

            return "F";

        }

        switch (remainder){ //remainder switch statement will be used to

        //determine if a + or a - is added to the letter grade.

        //these are the cases that will receive "+"

        case 0: case 1: case 2: case 3: case 4:

            lettrGrade+="-";

            break;

        case 7: case 8: case 9:

            lettrGrade +="+";

        }

        return lettrGrade;//letter grade with final + or _

    }

    //DashLine method will print out a dash line for better readability.

    public static void DashLine(){

        for(int i = 0; i<20; i++){

            System.out.print("-");

        }

    }

    public static void main(String[] args) {

        int[] grades;//array where grades will be stored

        int numGrades;//will determine the size of the array.

        double gradeAverage; //will be set equal to the average method.

        int total;//will be set equal to the sum method.

        String cont = "";//empty string

        do{//loop will run as long as 'y' is entered

        System.out.print("HOW MANY GRADES DO YOU WISH TO ENTER?: ");

        numGrades = kbd.nextInt();

        grades = new int[numGrades];

        System.out.print(" PLEASE ENTER " + numGrades + " GRADES: ");

       for(int i = 0; i<grades.length; i++){

            grades[i]=kbd.nextInt();

            if(grades[i]>100 || grades[i]<0){

                System.out.println("GRADES CAN NOT EXCEED 100 or BE LESS THAN 1");

                i--;

            }            

        }

        total = sum(grades, numGrades);//calls on sum method

        gradeAverage = average(grades,numGrades);//calls on average method

        DashLine();//prints dashlines

        System.out.print(" The Total Sum is: " + total + " ");

        System.out.printf("The Average is: %.2f ", gradeAverage);

        String ltrGrade;

        ltrGrade= letterGrade(gradeAverage);

        if(!(ltrGrade.equalsIgnoreCase("F"))){//test if ltr grade is F,

            //if its not F, print the following

            System.out.println(" Your Final Letter Grade is a: "+ ltrGrade

                    +" YOU PASS!!");

        }

        else{//failing grade prints this.

            System.out.println(" Your Final Letter Grade is a: "+ ltrGrade

                    +" YOUR PRETTY DUMB!!");        

        }

        DashLine();//prints dash lines

        System.out.println(" DO YOU WANT TO ENTER MORE GRADES? Y or N");

        cont = kbd.next();

        for(int j = 0; j< 80; j++){//simulates clear screen.

            System.out.println();

        }

        }while(cont.equalsIgnoreCase("y"));

        kbd.close();

    }

        }