In: Computer Science
Write a complete JAVA program, including comments (worth 2 pts -- include a good comment at the top and at least one more good comment later in the program), to process data for the registrar as follows: NOTE: Include prompts. Send all output to the screen.
1. Read in the id number of a student, the number of credits the student has, and the student’s grade point average (this is a number like 3.25). Print the original data right after you read it in. A typical set of values could be: 1234 21 2.25 Print something like this: student 1234 has 21 credits and has a grade point average of 2.25
2. If the student has 60 credits or less print this is a lowerclassman, otherwise print this is an upperclassman. Keep a count of how many upperclassmen there are.
3. Compute an adjusted gpa as follows: divide the number of credits by the gpa. Print this value.
4. If the adjusted gpa is 20 or greater, print a message saying this student is above average. Otherwise, print a message saying the student is not above average.
5. a.Compute how many credits the student needs to graduate with 120 credits. Print this message.
b. Determine how many semesters it will take the student to graduate assuming the student takes 15 credits per semester. Print this value as an integer. For example, if the student has 80 credits, print “Student needs 40 credits to graduate. It will take 3 semesters to graduate.” (40/15 +1) But if student has 75 credits, there are 45 remaining to graduate, and that will also take 3 semesters. (45/15) So you many need to determine if the number of credits remaining is divisible by 15.
6. Repeat the entire series of calculations for the next student, and the next, until every student has been processed. You must decide how to tell when every student has been processed. Make sure that this method is described in a comment.
7. Print the following values with appropriate message: the total number of students. how many of the students are upperclassmen (#2 above). the percent (with 3 decimal places) of students who are upperclassmen. Suggestion: You will need two separate counters for these tasks.
Java code for the given question:
import java.util.*;
public class SGrades{
public static void main(String args[]){
int sid=-1, ncredits=0;
float gpa=0;
Boolean cont = true;
String ip, nt;
char ct;
StringTokenizer st;
Scanner sc; //= new Scanner(System.in);
int count=0, uman=0, tk=0;
while (cont){
ip = "";
sc = new Scanner(System.in);
System.out.println("Enter Stud Id, No. of Credits and GPA");
sid = sc.nextInt();
ncredits = sc.nextInt();
gpa = sc.nextFloat();
count++;
System.out.println("Student " + sid + " has " + ncredits + "
credits and has a grade point average of " + gpa);
if( ncredits <= 60 )
System.out.println("Student " + sid + " is a lowerclassman");
else{
System.out.println("Student " + sid + " is a upperclassman");
uman++;
}
float adj_gpa = ncredits / gpa;
System.out.println("Adjusted GPA for Student " + sid + " is: " +
adj_gpa);
if( adj_gpa >= 20 )
System.out.println("Student " + sid + " is above average");
else
System.out.println("Student " + sid + " is a not above
average");
int to_grad = 120 - ncredits;
System.out.println("Student " + sid + " needs " + to_grad + "
credits to graduate");
int n_sems;
if ( to_grad%15 == 0 )
n_sems = to_grad / 15;
else
n_sems = (to_grad / 15) + 1;
System.out.println("Student " + sid + " needs " + n_sems + "
semesters to graduate ");
//Asking the user to repeat the process for next student or not
System.out.println("Do you want to assess one more
student(y/n)");
ct = sc.next().charAt(0);
if( ct== 'n' || ct=='N' )
cont = false;
//sc.close();
}
System.out.println("Total Number of Students: " + count);
System.out.println("Number of upperclassman: " + uman);
float uman_per = ((float)(uman/count)*100);
System.out.println("Percentage of upperclassman: "+
uman_per);
}
}