Question

In this homework, you will design a program to perform the following task: Write a program...

In this homework, you will design a program to perform the following task:

Write a program that would allow a user to enter student names and Final grades (e.g. A,B,C,D,F) from their courses. You do not know how many students need to be entered. You also do not know how many courses each of the students completed. Design your program to calculate the Grade Point Average (GPA) for each student based on each of their final grades. The program should output the Student name along with the GPA.

There are 5 components of your submission including:

Program Description- A detailed, clear description of the program you are building.

Analysis- Demonstrates your thought process and steps used to analyze the problem. Be sure to include the required input and output and how you will obtain the required output from the given input? Also, include your variable names and definitions. Be sure to describe the necessary formulas and sample calculations that might be needed. Talk about how your design will allow any number of students and final grades to be possible inputs.

Test plan - Prepare at least 1 set of input data (Test data) along with their expected output for testing your program. This test case should include at least 10 students. Your test data can be presented in the form of a table as follows (note: feel free to adapt to your design)

Flowchart

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program Code:

//import the util package to

//use the Scanner class

import java.util.*;

//StudentGPAImplementation class that will read the student name

//and grades of the courses.

//Displays the respective course grades and their GPA's

public class StudentGPAImplementation

{

     //main method

     public static void main(String args[])

     {

          //Object to the Scanner class to read input

          Scanner in=new Scanner(System.in);

          //to add the array of grades values

          ArrayList<ArrayList<Character>> studScoreGrades=new ArrayList<ArrayList<Character>>();

          //to add the array of student names

          ArrayList<String> studNames=new ArrayList<String>();

          //count variables

          int count=0;

          int incre=0;

          //to store each student GPA's

          double averageGrades[];

          //one choice to add students

          //one choice to add grades

          char choice='Y';

          char ch='y';

         

          //the loop contains the logic to add the student

          //and their respective details.

          do

          {

              incre++;

              //prompt the user to enter the name of the student

              System.out.println("Enter name of the student "+(incre)+": ");

              studNames.add(in.next());

              //create a character arraylist to store the grades of

              //each student

              ArrayList<Character> grades=new ArrayList<Character>();

              count=0;

             

              //logic to read the grades of the courses

              do

              {                 

                   System.out.println("Enter the grade of course "+(count+1)+": ");

                   grades.add(in.next().charAt(0));

                   System.out.println("Would like to add more grades? Press Y or y to continue.");

                   ch=in.next().charAt(0);

                   count++;

              }while(ch=='y'||ch=='Y');

              //add the arraylist of grades to the studScroreGrades.

              studScoreGrades.add(grades);

              System.out.println("Would like to add more students? Press N or n to discontinue.");

              choice=in.next().charAt(0);

          }while(choice=='Y' || choice=='y');

         

         

          int length;

          length=studScoreGrades.size();

          averageGrades=new double[length];

         

          //logic to compute the each individual average GPA's of the

          //students

          for(int i=0;i<studScoreGrades.size();i++)

          {            

              averageGrades[i]=computeAverage(studScoreGrades.get(i));

          }

         

          //print the output

          System.out.println("\n\nThe GPA's of the students are: ");

          for(int i=0;i<studNames.size();i++)

          {

              System.out.println("Student Name: "+studNames.get(i));

              System.out.print("Grades are: ");

              displayGPAs(studScoreGrades.get(i));

              System.out.println("GPA: "+ averageGrades[i]);

          }

     }

    

     //static method to compute the Average GPA's and this

     //method returns double

     public static double computeAverage(ArrayList<Character> grade)

     {

          //to keep the count of number of times, the grades are assigned

          int count[]=new int[5];

          int gradeA=0;

          int gradeB=0;

          int gradeC=0;

          int gradeD=0;

          int gradeF=0;

          //logic to find the number of times the student

          //has scored the same grade in over all courses

          for(int i=0;i<grade.size();i++)

          {

              if(grade.get(i)=='A')

              {

                   count[0]++;

                   gradeA+=4;

              }

              else if(grade.get(i)=='B')

              {

                   count[1]++;

                   gradeB+=3;

              }

              else if(grade.get(i)=='C')

              {

                   count[2]++;

                   gradeC+=2;

              }

              else if(grade.get(i)=='D')

              {

                   count[3]++;

                   gradeD+=1;

              }

              else if(grade.get(i)=='F')

              {

                   count[4]++;

                   gradeF+=0;

              }

          }

          int total=0;

          double average=0;

          //logic to find the total number of courses

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

          {

              total+=count[i];

          }

          //logic to compute the GPA

          average=(gradeA+gradeB+gradeC+gradeD+gradeF)/(total*1.00);

         

          //return the value

          return average;

     }

     //displayGPAs will display the grades of the each individual

     //student

     public static void displayGPAs(ArrayList<Character> grade)

     {

          for(int i=0;i<grade.size();i++)

          {

              System.out.print("Course "+(i+1)+":"+grade.get(i)+" ");

          }

     }

}

Sample output:

Enter name of the student 1:

ALEX

Enter the grade of course 1:

A

Would like to add more grades? Press Y or y to continue.

Y

Enter the grade of course 2:

A

Would like to add more grades? Press Y or y to continue.

Y

Enter the grade of course 3:

A

Would like to add more grades? Press Y or y to continue.

Y

Enter the grade of course 4:

B

Would like to add more grades? Press Y or y to continue.

Y

Enter the grade of course 5:

B

Would like to add more grades? Press Y or y to continue.

N

Would like to add more students? Press N or n to discontinue.

Y

Enter name of the student 2:

RICHARD

Enter the grade of course 1:

B

Would like to add more grades? Press Y or y to continue.

Y

Enter the grade of course 2:

B

Would like to add more grades? Press Y or y to continue.

Y

Enter the grade of course 3:

C

Would like to add more grades? Press Y or y to continue.

Y

Enter the grade of course 4:

C

Would like to add more grades? Press Y or y to continue.

Y

Enter the grade of course 5:

D

Would like to add more grades? Press Y or y to continue.

N

Would like to add more students? Press N or n to discontinue.

Y

Enter name of the student 3:

PARKER

.

.
.

.

.

Enter name of the student 10:

DAVID

Enter the grade of course 1:

B

Would like to add more grades? Press Y or y to continue.

Y

Enter the grade of course 2:

B

Would like to add more grades? Press Y or y to continue.

Y

Enter the grade of course 3:

C

Would like to add more grades? Press Y or y to continue.

Y

Enter the grade of course 4:

C

Would like to add more grades? Press Y or y to continue.

Y

Enter the grade of course 5:

A

Would like to add more grades? Press Y or y to continue.

N

Would like to add more students? Press N or n to discontinue.

N

The GPA's of the students are:

Student Name: ALEX

Grades are: Course 1:A Course 2:A Course 3:A Course 4:B Course 5:B GPA: 3.6

Student Name: RICHARD

Grades are: Course 1:B Course 2:B Course 3:C Course 4:C Course 5:D GPA: 2.2

Student Name: PARKER

Grades are: Course 1:C Course 2:C Course 3:C Course 4:D Course 5:A GPA: 2.2

Student Name: WILLIAM

Grades are: Course 1:A Course 2:A Course 3:A Course 4:A Course 5:A GPA: 4.0

Student Name: URAIN

Grades are: Course 1:F Course 2:F Course 3:C Course 4:C Course 5:D GPA: 1.0

Student Name: LEE-GUEON

Grades are: Course 1:B Course 2:A Course 3:B Course 4:C Course 5:A GPA: 3.2

Student Name: ERIC

Grades are: Course 1:C Course 2:C Course 3:C Course 4:C Course 5:D GPA: 1.8

Student Name: XAVIER

Grades are: Course 1:D Course 2:D Course 3:D Course 4:C Course 5:B GPA: 1.6

Student Name: KEPLER

Grades are: Course 1:A Course 2:B Course 3:C Course 4:D Course 5:F GPA: 2.0

Student Name: DAVID

Grades are: Course 1:B Course 2:B Course 3:C Course 4:C Course 5:A GPA: 2.8

Add a comment
Know the answer?
Add Answer to:
In this homework, you will design a program to perform the following task: Write a program...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT