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

***Using Java Please. Comments optional**** You are a programming intern at the

ID: 3753651 • Letter: #

Question

***Using Java Please. Comments optional****

You are a programming intern at the student transfer counselor's office. Having heard you are
taking CS 55, your boss has come to ask for your help with a task.
Students often come to ask her whether their GPA is good enough to transfer to some college to
study some major and she has to look up the GPA requirements for a school and its majors in a
spreadsheet to answer their question. She would like you to write a program that students can use
themselves to get their answer. She is providing you with the spreadsheet data.

CS Econ English

UCLA 3.7 3.5 3.2
UCB 3.8 3.4 3.3
UCI 3.6 3.7 3.4
UCSD 3.5 3.3 3.0


You will write a program, TransferAdvisor.java, which asks the user for the school name, the
major, and their GPA, and informs them whether their GPA is adequate for the school and major
selected, or by how much they need to improve it. If a school or major is not in the spreadsheet, the
user is informed. The school names and majors can be entered both as shown in the spreadsheet or in
all lowercase letters. The “You need to improve your GPA by ### ...” message should have 2 decimals
precision for the GPA regardless of the student GPA entered.
Below are a few runs of the program:
Enter the school name: UCLA
Enter the major: CS
Enter your GPA: 3.457
You need to improve your GPA by 0.24 to transfer to UCLA to study CS
-----------------
Enter the school name: ucsd
Enter the major: english
Enter your GPA: 3.12
You could transfer to ucsd to study english
------------------
Enter the school name: harvard
Enter the major: CS
Enter your GPA: 3.1
harvard is not in the school system
------------------
Enter
Enter
Enter
There
the school name: ucla
the major: astrology
your GPA: 2.6
is no astrology major at ucla
Hints:

To avoid a lot of duplication with the code dealing with the GPA comparison and print outs,
write a method that takes in the school name, the major name, the required GPA for that major in that
school and the student GPA, and prints out either the “You could transfer ...” or the “You need toimprove your GPA by ...”.

Avoid if/else if/... to match the school and the major. Switch/case makes the code cleaner.

Explanation / Answer


Given below is the code for the question.
To indent code in eclipse , select code by pressing ctrl+a and then indent using ctrl+i
Please do rate the answer if it was helpful. Thank you
import java.util.Scanner;
public class TransferAdvisor {
public static void printMessage(String school, String major, double GPAneeded, double GPAstud){
if(GPAstud >= GPAneeded)
System.out.println("You could transfer to "+ school + " to study " + major);
else{
double diff = GPAneeded - GPAstud;
System.out.printf("You need to improve your GPA by %.2f to transfer to %s to study %s", diff, school, major);
}
}
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
String school, major;
double GPAneeded, GPAStud;
System.out.print("Enter the school name: ");
school = keyboard.next();
System.out.print("Enter the major: ");
major = keyboard.next();
System.out.print("Enter your GPA: ");
GPAStud = keyboard.nextDouble();
switch(school.toUpperCase()){
case "UCLA":
switch(major.toUpperCase()){
case "CS":
printMessage(school, major, 3.7, GPAStud);
break;
case "ECON":
printMessage(school, major, 3.5, GPAStud);
break;
case "ENGLISH":
printMessage(school, major, 3.2, GPAStud);
break;
default:
System.out.println("There is no " + major + " major at " + school);
}
break;
case "UCB":
switch(major.toUpperCase()){
case "CS":
printMessage(school, major, 3.8, GPAStud);
break;
case "ECON":
printMessage(school, major, 3.4, GPAStud);
break;
case "ENGLISH":
printMessage(school, major, 3.3, GPAStud);
break;
default:
System.out.println("There is no " + major + " major at " + school);
}
break;
case "UCI":
switch(major.toUpperCase()){
case "CS":
printMessage(school, major, 3.6, GPAStud);
break;
case "ECON":
printMessage(school, major, 3.7, GPAStud);
break;
case "ENGLISH":
printMessage(school, major, 3.4, GPAStud);
break;
default:
System.out.println("There is no " + major + " major at " + school);
}
break;
case "UCSD":
switch(major.toUpperCase()){
case "CS":
printMessage(school, major, 3.5, GPAStud);
break;
case "ECON":
printMessage(school, major, 3.3, GPAStud);
break;
case "ENGLISH":
printMessage(school, major, 3.0, GPAStud);
break;
default:
System.out.println("There is no " + major + " major at " + school);
}
break;
default:
System.out.println(school + " is not in the school system.");
}
}
}

output
-----
Enter the school name: UCLA
Enter the major: CS
Enter your GPA: 3.457
You need to improve your GPA by 0.24 to transfer to UCLA to study CS
Enter the school name: ucla
Enter the major: astrology
Enter your GPA: 2.6
There is no astrology major at ucla

Enter the school name: ucsd
Enter the major: english
Enter your GPA: 3.12
You could transfer to ucsd to study english