Question

Create a GPA calculator in Java. Ask the end user for the credit hours and letter...

Create a GPA calculator in Java. Ask the end user for the credit hours and letter grade for each class. Once the user is finished with the data entry, calculate and output the overall GPA for the given input.

For example, if four classes are input, each of which is a three-hour course, with grades of A, B, B, and B, the overall GPA will be 3.25.

The exact user interaction is up to you. As long as the requirements above are met, the code is readable (and properly documented), and the application is user-friendly.

Letter Grade

Grade Point Value per Credit Hour

A-4

B-3

C-2

D-1

F-0

And the semester GPA is the total grade points divided by total credit hours.

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

Code:

import java.util.Scanner;
public class Main
{
   public static void main(String[] args) {
       Scanner input=new Scanner(System.in); //Scanner class object creation
       int total=0;
       int total_credit_hours=0; //declaring variables
       while (true)
       {
       System.out.print("Enter the Credit Hours and Grade (Press -1 and Q to exit): "); //asking user to enter data for exit press -1 and Q
       int credit_hours=input.nextInt();
       char grade=input.next().charAt(0); //take credit_hours and grade as input
if (credit_hours==-1 && grade=='Q') //if credit hours is -1 then break
break;
switch(grade) //switch case
       {
       case 'A': total=total+(credit_hours * 4); // if grade is A multiply with 4
       break ;
      
       case 'B': total=total+(credit_hours * 3); //if b multiply with 3
       break ;
       case 'C': total=total+(credit_hours * 2); //if c multiply with 2
       break ;
       case 'D': total=total+(credit_hours * 1); //if d multiply with 1
       break ;
       case 'E': total=total+(credit_hours * 0); //if e multiply with 0
       break ;
       default:
       break;
       }
total_credit_hours=total_credit_hours+credit_hours; //sum of total hours
       }
       float overall_gpa=total/(float)(total_credit_hours); //overall_gpa calculation
       System.out.println("The overall GPA will be: " + overall_gpa); //printing overall gpa
   }
}

Code Screenshots and Output:

Note: if you have any queries please post a comment thanks a lot..always available to help you...

Add a comment
Know the answer?
Add Answer to:
Create a GPA calculator in Java. Ask the end user for the credit hours and letter...
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
  • Create a program in Python to change Grades in number and find the GPA of the...

    Create a program in Python to change Grades in number and find the GPA of the user Problem: The user wants an easy calculator to calculate their GPA. They want to enter the letter grade (A, B, C, D, F) for 5 classes, the credit hours (1, 2, 3,4, 5) and then run the program to calculate the GPA (3.50- 4.00 A, 3.49 – 2.50 B, 2.49 -1.60 C, 1.59 – .50 D, .49 -0 F) for the semester. Task...

  • Task: You want to calculate a student's GPA for a number of classes taken by the...

    Task: You want to calculate a student's GPA for a number of classes taken by the student during a single semester. (In C# (C sharp)) Inputs: 1. the student's name 2. Class names for the classes taken by the student 3. Class letter grade for the classes taken by the student 4. Class credit hours for the classes taken by the student Processing: 1. Accept and process classes until the user indicates they are finished 2. accumulate the number of...

  • Matlab a) Write a MATLAB code that takes the grade letters from the user and provide him/her with the GPA for that seme...

    Matlab a) Write a MATLAB code that takes the grade letters from the user and provide him/her with the GPA for that semester Enter your grades (letters): AABBC (input) Your GPA is 3.2 output) b) Write a Matlab user defined function to that takes a letter grade and return a numeric grade as shown in the table below. Any other value should give an error message (Invalid Grade). You function name should be Letter2Grade Use the following information to calculate...

  • Modify your PredictGPA.java file from Lab 2 to create a method called GPA that takes a...

    Modify your PredictGPA.java file from Lab 2 to create a method called GPA that takes a string argument (the grade) and returns the corresponding value (ie 4.0 for an A, 3.33 for a B+, etc). Use this method call to reduce the “redundant” code that you had in Lab 2. The program must otherwise still run correctly as to the directions in Lab 2 and compute the GPA after using the method calls to determine the appropriate grade values. Trying...

  • Java Description You are given the task of reading a student’s name, semester letter grades, and...

    Java Description You are given the task of reading a student’s name, semester letter grades, and semester hours attempted from one file; calculating the semester GPA; and writing the student’s name and semester GPA to another file. GPA Calculation GPA = Total Quality Points / Hours Attempted Quality Points for each class = Grade Conversion Points * Hours Attempted The letter grades with corresponding point conversions is based upon the following table: Letter Grade Conversion Points A 4 points B...

  • In Matlab. Use loops. 2. Create an algorithm to allow the user to enter a list...

    In Matlab. Use loops. 2. Create an algorithm to allow the user to enter a list of courses they have taken along with the grades received and the credit hours for each course, and then calculate the user's GPA. The program should first ask the user to type either Yes or No in response to the question, "Do you want to enter a grade?" If the answer is Yes, the user should be asked to enter the name of the...

  • Java programming only Create a Java program that inputs a grade from the user. The grade input from the user will be an...

    Java programming only Create a Java program that inputs a grade from the user. The grade input from the user will be an integer. Once the input is stored, use an if-else-if block of code to determine the letter grade of the inputted integer grade. Do not use a bunch of if statements by themselves to solve this problem. You will print an error message for inputs greater than 100 and for inputs less than 0. Both errors must be...

  • Python GPA calculator: Assume the user has a bunch of courses they took, and need to...

    Python GPA calculator: Assume the user has a bunch of courses they took, and need to calculate the overall GPA. We will need to get the grade and number of units for each course. It is not ideal to ask how many courses they took, as they have to manually count their courses. Programming is about automation and not manual work. We will create a textual menu that shows 3 choices. 1. Input class grade and number of units. 2....

  • Must be written in JAVA Code Write a program that will read in a file of student academic credit data and create a list of students on academic warning. The list of students on warning will be written...

    Must be written in JAVA Code Write a program that will read in a file of student academic credit data and create a list of students on academic warning. The list of students on warning will be written to a file. Each line of the input file will contain the student name (a single String with no spaces), the number of semester hours earned (an integer), the total quality points earned (a double). The following shows part of a typical...

  • /** * File: GradeCalculator . java * Description: Instances of this class are used to calculate...

    /** * File: GradeCalculator . java * Description: Instances of this class are used to calculate * a course average and a letter grade. In order to calculate * the average and the letter grade, a GradeCalculator must store * two essential pieces of data: the number of grades and the sum * of the grades. Therefore these are declared as object properties * (instance variables). * Each time calcAverage (grade) is called, a new grade is added to *...

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