jGRASP Java language B04 - Academic admission system Write a program in a java f
ID: 3907612 • Letter: J
Question
jGRASP Java language
B04 - Academic admission system
Write a program in a java file called Admissions.java
You will write a program that will either accept or deny graduate admissions based on the grades obtained in the undergraduate program.
The conversion from letter grades to GPA points is the following:
Your program will call a method askUserGrade, that asks the user for the letter grade obtained in an undergraduate course and returns the corresponding GPA points. In order for the user to finish entering grades, the user will enter "EXIT" and your program will return -1.
Back in the main method, your program will accumulate the GPA points and count the number of grades entered by the user. When the user enters EXIT, then your program stop asking for more grades. When the program stops asking for grades, it will call a method named computeAverageGPA that, based on the accumulated points and the number of grades entered, will compute and return the average GPA points.
Then, your program will call a method named askForProgram, where the user will enter either "masters" or "phd", but in any combination of lowercase and uppercase letter. Your method will return the user input.
Back in the main method, your program will call the processApplication, where the program will decide whether or not the application is accepted depending on the average GPA, the program the user is applying to and the following rules. Your method will print the final decision:
- If the user is applying to the Masters program, then he/she needs a GPA above 3.0
- If the user is applying to the PhD program, then he/she needs a GPA above 3.5
NOTE:The user can enter any combination of uppercase and lowercase letters for "masters" or "phd". You can assume users will always enter any of these two values.
That is, the user can enter "Masters", "MASTERS", "masters", "MaStErS", "PHD", "phd", "PhD", etc. but not "doctorate", "bachelors", etc.
LETTER GRADE GPA points A+ 4.3 A 4.0 A- 3.7 B+ 3.3 B 3.0 B- 2.7 C+ 2.3 C 2.0 C- 1.7 D+ 1.3 D 1.0 D- 0.7 F 0.0Explanation / Answer
ScreenShot
---------------------------------------------------------
Program
/* This program check the acceptance of a university based on grade */
//Package for I/O operations
import java.util.*;
//Admission class
public class Admission {
//Method for student to enter grade return corresponding grades to main
public static ArrayList<Double> askUserGrade() {
//Read input
Scanner sc=new Scanner(System.in);
//List to save user input's corresponding grade
ArrayList<Double>GPA=new ArrayList<Double>();
//Loop through until exit
String val="";
while(!"EXIT".equals(val)) {
System.out.println("Enter the letter grade:");
val=sc.nextLine();
if("A+".equals(val)) {
GPA.add(4.3);
}
else if("A".equals(val)) {
GPA.add(4.0);
}
else if("A-".equals(val)) {
GPA.add(3.7);
}
else if("B+".equals(val)) {
GPA.add(3.3);
}
else if("B".equals(val)) {
GPA.add(3.0);
}
else if("B-".equals(val)) {
GPA.add(2.7);
}
else if("C+".equals(val)) {
GPA.add(2.3);
}
else if("C".equals(val)) {
GPA.add(2.0);
}
else if("C-".equals(val)) {
GPA.add(2.7);
}
else if("D+".equals(val)) {
GPA.add(1.3);
}
else if("D".equals(val)) {
GPA.add(1.0);
}
else if("D-".equals(val)) {
GPA.add(0.7);
}
else if("F".equals(val)) {
GPA.add(0.0);
}
}
return GPA;
}
//Method to calculate average grade
public static double computeAverageGPA(ArrayList<Double>GPA,int count){
double total=0.0,avg=0.0;
for (int i=0;i<GPA.size();i++){
total+=GPA.get(i);
}
avg=total/count;
return avg;
}
//Method to prompt user the course they are applying
public static String askForProgram(){
Scanner sc=new Scanner(System.in);
System.out.println("Which course are you going to enroll(masters/phd):");
String course=sc.nextLine();
return course;
}
//Main method
public static void main(String[] args) {
//Call user grade asking question
ArrayList<Double>GPA=askUserGrade() ;
//Average calculating method call
double avg=computeAverageGPA(GPA,GPA.size());
//course asking call
String course=askForProgram();
//Convert result into lowercase
course=course.toLowerCase();
//Check acceptance
if("masters".equals(course)){
if(avg>3.0){
System.out.println("You are accepted");
}
else{
System.out.println("You Rejected");
}
}
else if("phd".equals(course)){
if(avg>3.5){
System.out.println("You are accepted");
}
else{
System.out.println("You Rejected");
}
}
}
}
------------------------------------------------------
Output
----jGRASP exec: java Admission
Enter the letter grade:
A+
Enter the letter grade:
A
Enter the letter grade:
B
Enter the letter grade:
C
Enter the letter grade:
EXIT
Which course are you going to enroll(masters/phd):
phd
You Rejected
----jGRASP: operation complete.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.