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

1. Write a java program that will determine a students grade point average for a

ID: 3539248 • Letter: 1

Question

1. Write a java program that will determine a students grade point average for a semseter. Ask the student how many classes they had. In a loop ask for the letter grade and the credit hour value for each class. You will need to determine the grade point value based on the letter grade(use a switch, and A= 4.0, B = 3.0....), and keep track of the credit hours. For example

//this goes inside the loop

prompt for letter grade
prompt for credit hour

switch (letterGrade)
{

case: 'A'
case: 'a': totalCreditForGPA= totalCreditForGPA + (creditHour * 4.0);
totalCreditHours= totalCreditHours + creditHour;
break;
........
end switch
end loop

GPA Calculation
output GPA

Display the GPA for the semester (totalCreditForGPA divided by totalCredit hour

2.Lottery! Write a program that will generate a 2 digit lottery number. The user will have 5 chances to guess the number. To assist the user you will tell them if their guess is too high or too low and try again. Be sure to tell them if they gues it right!

Explanation / Answer

Second answer.




import java.util.Scanner;



public class GPA {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

System.out.println("This program will determine a students grade point average for a semseter. ");

System.out.println("How many classes you had");

int numberOfClasses = scanner.nextInt();

char[] letterGrade = new char[numberOfClasses];

int[] gradePointValue = new int[numberOfClasses];

int[] creditHourValue = new int[numberOfClasses];

double totalCreditHours = 0.0;

int totalCreditForGPA = 0;

double GPA = 0.0;


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

System.out.println("Enter letter grade for class "+(i+1));

String letter = scanner.next();

char[] array = letter.toCharArray();

letterGrade[i] = array[0];

gradePointValue[i] = getGradePoint(letterGrade[i]);

totalCreditForGPA += gradePointValue[i];


System.out.println("Enter credit hour value: ");

creditHourValue[i] = scanner.nextInt();

totalCreditHours += creditHourValue[i];

}


GPA = totalCreditForGPA / totalCreditHours;


System.out.println("The total GPA calculated is : "+GPA);

}


public static int getGradePoint(char character) {

switch (character) {

case 'A':

case 'a': return 4;

case 'B':

case 'b': return 3;

case 'C':

case 'c': return 2;

case 'D':

case 'd': return 1;

case 'E':

case 'e': return 0;

default : System.out.println("Enter valid details");


}

return character;

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote