Question

(7) Student grade point statistics [Problem description] There is a need to make statistics of the grade points of the studen
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Sol:

  CODE IN JAVA:

package javaapplication1;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

/**
*
* @author pc
*/
//clas student
class Student
{

//getters
public String getName() {
return name;
}

public String getId() {
return Id;
}

public int[] getGrades() {
return grades;
}

public int getClasss() {
return Class;
}

public int getGpa() {
return gpa;
}
//course and credit array
String courses[]={"Advanced Mathematics","Physics","English","Hindi","Chemistry","Biology","Computer Basics","C++","Data Structure","Computer Networks"};
int credit[]={6,5,4,2,2,2,2,2,2,2};
//setter
public void setGrades(int[] grades) {
this.grades = grades;
}
//constructor to initialize the name , id and class value
public Student(String name, String Id,int Class) {
this.name = name;
this.Id = Id;
this.Class=Class;
}
//calculate gpa of this student
public void calculateGPA()
{
gpa=grades[0]*credit[0]+grades[1]*credit[1]+grades[2]*credit[2]+grades[3]*credit[3]+grades[4]*credit[4]+grades[5]*credit[5]+grades[6]*credit[6]+grades[7]*credit[7]+grades[8]*credit[8]+grades[9]
*credit[9];
gpa=gpa/(29);
// its 4 if in between 90 and 100 , 3 if in between 80 and 90 and so on...
if(gpa>90 && gpa<=100)
gpa=4;
else if(gpa>80 && gpa<=90)
gpa=3;
else if(gpa>70 && gpa<=80)
gpa=2;
else
gpa=1;
}
//data members
private String name;
private String Id;
private int grades[]=new int[10];
private int Class;
private int gpa;
}
//to sort by GPA in descending order
class SortbyGPA implements Comparator<Student>
{
// Used for sorting in ascending order of
// roll number
public int compare(Student a, Student b)
{
return b.getGpa() - a.getGpa();
}
}
//main class
public class GradePointStatistics {
public static void main(String[] args) throws Exception{
//arryalist which contain all the students , intially empty
ArrayList<Student> arr=new ArrayList<Student>();
int n=6;//classes in this grade
int noOfStudent=20;//students
int m=10;//courses
int gradePoints[][]=new int[n][noOfStudent];
Scanner sc=new Scanner(new File("D:\\DataInput.txt"));//open file
int i=0;
sc.nextLine();//read first line but dont take it in use
while(sc.hasNextLine())
{
String str[]=sc.nextLine().split("\t");//split lines into array by \t
int grades[]=new int[10];//to put all the grades value in this array
grades[0]=Integer.parseInt(str[3]);
grades[1]=Integer.parseInt(str[4]);
grades[2]=Integer.parseInt(str[5]);
grades[3]=Integer.parseInt(str[6]);
grades[4]=Integer.parseInt(str[7]);
grades[5]=Integer.parseInt(str[8]);
grades[6]=Integer.parseInt(str[9]);
grades[7]=Integer.parseInt(str[10]);
grades[8]=Integer.parseInt(str[11]);
grades[9]=Integer.parseInt(str[12]);
//create student object
Student s=new Student(str[0],str[1],Integer.parseInt(str[2]));
//set its grades
s.setGrades(grades);
s.calculateGPA();//calculate GPA
arr.add(s);//add this student into arraylist
}
  
//prinitng GPA SHEET
System.out.println("----------------GPA Sheet----------------");
System.out.println("Class\tStudentId\tStudentName\tGPA");
for(int j=0;j<arr.size();j++)
{
Student s=arr.get(j);
System.out.println(s.getClasss()+"\t"+s.getId()+"\t"+s.getName()+"\t"+s.getGpa());
}
  
System.out.println("");
  
//Print top 30 % by GPA
ArrayList<Student> arr1=arr;
Collections.sort(arr1, new SortbyGPA());//sort in descending order
int thirtyPercent=n*noOfStudent*30/100;//find how many comes under top 30 %
//ranking
System.out.println("--------------Top 30% Students on the basis of GPA-----------------");
System.out.println("StudentNumber\tClass\tGPA");
for(int j=0;j<thirtyPercent;j++)
{
Student s=arr.get(j);
System.out.println(s.getId()+"\t"+s.getClasss()+"\t"+s.getGpa());
}
System.out.println("");
  
//total GPA by class
System.out.println("----------------Total GPA------------------");
System.out.println("Class\tTOTAl GPA");
for(int j=0;j<arr.size();j=j+noOfStudent)
{
int totalGPA=0;
//calcultae total GPA for the class j having noOfStudents
for(int t=0;t<noOfStudent;t++)
{
Student s=arr.get(j+t);
totalGPA+=s.getGpa();
}
//if j is in between 0 and 20 then its 1st class and so on..
if(j>=0 && j<20)
{
System.out.print("1\t");
}
else if(j>=20 && j<40)
{
System.out.print("2\t");
}if(j>=40 && j<60)
{
System.out.print("3\t");
}if(j>=60 && j<80)
{
System.out.print("4\t");
}if(j>=80 && j<100)
{
System.out.print("5\t");
}if(j>=100 && j<120)
{
System.out.print("6\t");
}
//now print totalGPA
System.out.println(totalGPA);
}
  
//to take user input
Scanner si=new Scanner(System.in);
System.out.println("Please enter Id of student to inquire");
String id=si.next();//take id as user input
int j;
for( j=0;j<arr1.size();j++)
{
if(arr1.get(j).getId().equalsIgnoreCase(id))//if this id matches with any id inside array list of top 30%
{
//then print ranking
System.out.println("--------------Top 30% Students on the basis of GPA-----------------");
System.out.println("StudentNumber\tClass\tGPA");
for(int t=0;t<thirtyPercent;t++)
{
Student s=arr.get(t);
System.out.println(s.getId()+"\t"+s.getClasss()+"\t"+s.getGpa());
}
System.out.println("");
break;
}
}
//if no match found then print the below shown message..
if(j==arr1.size())
{
System.out.println("The student is not among top 30%");
}
}
}

Output:

GPA Sheet- Clas Studen Id StudentlTame GPA 20002 RANI 3 xx003 CANESH 2 XX004 SHrvats3 xx005 RAVI3 xx007 RASHMI 3 xx008 SHYAMA

xx105 TAPDO 3 xx106 NOBITA 2 107 RUCHIIA 3 X108 SHYAMA 3 xx109 GANNU2 xx110 MAHIMA 3 xx111 SHANDH 3 112 RICHA 2 X.113 ROLI xx

Xx216 RADS 2 Xx217 SHANKAR 3 XX218 VRINDA 2 xx219 STA 3 xx220 PAUL3 X302 RAMA 2 xx305 TAP 3 XX306 NOBITA 2 X309 GANNU 2 xx311

StudentNumbe Class GPA XX001 1 Xx002 1 xx004 1 XX005 1 xx007 1 XX008 1 Xx0101 Xx0111 xx013 1 xx014 1 XX016 1 xx017 1 Xx0191 x

Total GPA 2 Class TOTAl GPA Please enter Id of student to inquire XX017 Top 30% Students on the basis of GPA 8 StudentNumbe C

xx007 1 XX0101 xx011 1 13 1 XX01 XX0161 X017 XX01 XX020 1 XX101 2 X.102 2 X《104 2 Xx105 2 Xx107 2 X《108 2 XX110 2 XX113 2 XX1

Add a comment
Know the answer?
Add Answer to:
(7) Student grade point statistics [Problem description] There is a need to make statistics of the grade points o...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Problem Specification: Write a C++ program to calculate student’s GPA for the semester in your class. For each student, the program should accept a student’s name, ID number and the number of courses...

    Problem Specification:Write a C++ program to calculate student’s GPA for the semester in your class. For each student,the program should accept a student’s name, ID number and the number of courses he/she istaking, then for each course the following data is needed the course number a string e.g. BU 101 course credits “an integer” grade received for the course “a character”.The program should display each student’s information and their courses information. It shouldalso display the GPA for the semester. The...

  • what is the solution for this Java problem? Generics Suppose you need to process the following...

    what is the solution for this Java problem? Generics Suppose you need to process the following information regarding Students and Courses: A Student has a name, age, ID, and courseList. The class should have a constructor with inputs for setting name, ID and age. The class should have setters and getters for attributes name, ID and age, and a method addCourse, removeCourse, printSchedule. courseList: use the generic class ArrayList<E> as the type of this attribute addCourse: this method takes as...

  • You are asked to build and test the following system using Java and the object-oriented concepts ...

    You are asked to build and test the following system using Java and the object-oriented concepts you learned in this course: Project (20 marks) CIT College of Information technology has students, faculty, courses and departments. You are asked to create a program to manage all these information's. Create a class CIT to represents the following: Array of Students, each student is represented by class Student. Array of Faculty, each faculty is represented by class Faculty. Array of Course, each course...

  • Program 5 Due 10/25 C-String and Two-dimensional Array Use An input data file starts with a...

    Program 5 Due 10/25 C-String and Two-dimensional Array Use An input data file starts with a student's name (on one line). Then, for each course the student took last semester, the file has 2 data lines. The course name is on the first line. The second line has the student's grade average (0 to 100) and the number of credits for the course Sample data: Jon P. Washington, Jr. Computer Science I 81 4 PreCalculus 75 3 Biology I 88...

  • Python: Printing Student Data Ask the user: "How many students are in the class?" Read in...

    Python: Printing Student Data Ask the user: "How many students are in the class?" Read in the number of students If there are students For each student Ask for the name of the student: "Enter the name of student:" Read in the name of the student If the student's name is greater than 24 characters Do not display this student's data Do not ask for their gpa Print: "Name of student cannot exceed 24 characters." Ask for the gpa of...

  • Questions of this part analyze the students’ understanding in analyzing the given scenario and practical skills...

    Questions of this part analyze the students’ understanding in analyzing the given scenario and practical skills to build Class diagrams studied in chapters 8, 10 and 12of IT242. The “SES” administration would desire to have a database system to keep track of students, instructors, courses, assessments, and grades. Read the following paragraph to answer the given questions. The system maintains courses’ information. For each course, the system keeps a unique course code, name and credit hours. Each course offered in...

  • c++ implement a student class Determine the final scores, letter grades, and rankings of all students...

    c++ implement a student class Determine the final scores, letter grades, and rankings of all students in a course. All records of the course will be stored in an input file, and a record of each student will include the first name, id, five quiz scores, two exam scores, and one final exam score. For this project, you will develop a program named cpp to determine the final scores, letter grades, and rankings of all students in a course. All...

  • Create a class named Student, where each Student consists of a student id (a number between...

    Create a class named Student, where each Student consists of a student id (a number between 0 and 99999), grade level (1-12), and a full name. Include set and get methods for all fields. Save this as Student.java. Then, write an application that declares a Student object and prompts the user for the three required pieces of information, one at a time. For student id, keep prompting until the user enters a valid number (0-99999). Likewise, keep prompting for a...

  • Write the code to maintain a list of student records. The main flow of your program...

    Write the code to maintain a list of student records. The main flow of your program should be to read all information from file(s) and place it in arrays, loop and do stuff with the records (e.g., add, update, look up, etc.), before exiting optionally write the new information back to the file(s) before exiting. Please note the files are only accessed at the beginning and the end, do not change the files during the "do stuff loop" (unless you...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT