In: Computer Science
11) Enter the following using Java.
Use for loop to enter student id, student name, major and grades. Also grades should display their letter grades based on their conditions.
After that display the name of students and their info, and also their letter grade
After that display the sum of all grades and the average
Output Example:
Student ID: 0957644
Student Name: Pedro Hernandez
Student Major: Business Information Systems
Grades for Fall 2020:
Introduction to Computer Science using Java: 85, B
Statistics: 85, B
Introduction to Psychology: 92, A
English Composition II: 84, B
Sum = 346
Average= 86.5, B
Code
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Testq {
public static void main(String[] args) throws IOException {
BufferedReader console = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Please Enter Number of Students details you want to enter: ");
int userInput = Integer.parseInt(console.readLine());
double sum=0;
for (int i = 0; i < userInput; i++) {
System.out.print("Student ID: ");
String sid = console.readLine();
System.out.print("Student Name: ");
String sname = console.readLine();
System.out.print("Student Major: ");
String smajor = console.readLine();
System.out.println("Grades for Fall 2020: ");
System.out.print("Introduction to Computer Science using JAVA: ");
String marksJava = console.readLine();
sum += Double.parseDouble(marksJava.split(",")[0]); //calculate sum of marks.
System.out.print("Statistics: ");
String marksStats = console.readLine();
sum += Double.parseDouble(marksStats.split(",")[0]);
System.out.print("Introduction to Psychology: ");
String marksPhyschology = console.readLine();
sum += Double.parseDouble(marksPhyschology.split(",")[0]);
System.out.print("English Composition II: ");
String marksEnglish = console.readLine();
sum += Double.parseDouble(marksEnglish.split(",")[0]);
System.out.print("Sum = " + sum + "\n");
double average = sum/4;
if(average >=90)
System.out.print("Average= " + average + ", A");
if(average >=80 && average <90)
System.out.print("Average= " + average + ", B");
if(average <80)
System.out.p rint("Average= " + average + ", C");
}
}
}
Input/Output:
Please Enter Number of Students details you want to enter:
1
Student ID: 0957644
Student Name: Pedro Hernandez
Student Major: Business Information System
Grades for Fall 2020:
Introduction to Computer Science using JAVA: 85,B
Statistics: 85,B
Introduction to Psychology: 92,A
English Composition II: 84,B
Sum = 346.0
Average= 86.5, B
Screenshot for reference :
Please, please UPVOTE, it's really important to me. Thanks