In: Computer Science
Write a simple Java program that does the following:
1) Declare a constant of type String to hold the words "Oakland
University".
2) Declare variables of the type stated, and Prompt the user to
enter in the following information and store in the variables
a. Their current GPA on a 4.0 scale, into a variable of type
double
b. The number of credits they have so far into a variable of type
int
c. The amount of tuition they paid so far into a variable of type
int
d. Their last name, into a String variable
e. Their first initial, into a char variable
3) Create a variable of type char. Determine and assign a letter
grade to it using the following rules and if else statement. (Note:
this is not our class grading scheme.)
a. gpa < 1 F
b. 1 <= gpa < 2.5 D
c. 2.5 <= gpa < 3 C
d. 3 <= gpa <= 3.5 B
e. 3.5 < gpa <= 4 A
4) Create a variable of type double. Cast the either of the
variables tuition or credits to
double to calculate the tuition dollars per credit hour and assign
it to the new variable. .
5) Print out to the system console a single String using escape
characters that outputs
multiple lines with the following information, formatted the same
as this example. In
other words, the first column should indicate what is being output,
and the second column
shows the value. Use variable names in your output String, not
literals. You can use tab
escape characters to set up the second column.
a. your first initial and last name, with a period and space
following your first initial
(from problem 2)
b. your university (from problem 1)
c. your Letter GPA grade (from problem 3)
d. Your tuition cost per credit hour (from problem 4)
import java.util.Scanner;
public class StudentCred {
public static void main(String[] args) {
final String unName = "Oakland
University";
Scanner sc = new
Scanner(System.in);
//reading gpa
System.out.println("Enter
gpa:");
double gpa = sc.nextDouble();
//reading credits
System.out.println("Enter number of
credits: ");
int credits = sc.nextInt();
//reading fee
System.out.println("Enter total
tution fee: ");
int tutionFee = sc.nextInt();
//reading name
System.out.println("Enter lastName:
");
String lastName =
sc.nextLine();
lastName = sc.nextLine();
//reading initial
System.out.println("Enter initial:
");
char initial =
sc.next().charAt(0);
char grade;
//finding grade
if (gpa < 2.5)
grade =
'D';
else if (gpa >= 2.5 &&
gpa < 3)
grade =
'C';
else if (gpa >= 3 && gpa
<= 3.5)
grade =
'B';
else
grade =
'A';
//finding fee
double dollorsPerCredit = tutionFee
/ (double) credits;
System.out.println("Name : " +
lastName + "." + initial);
System.out.println("University Name
:" + unName);
System.out.println("GPA grade: " +
grade);
System.out.println("Tution cost per
credit hour: " + dollorsPerCredit);
}
}
Note : If you like my answer please rate and help me it is very Imp for me