Question

Design and code a JAVA program called ‘Grades’. ? Your system should store student’s name, and...

Design and code a JAVA program called ‘Grades’. ?

Your system should store student’s name, and his/her course names with grades. ?

Your system should allow the user to input, update, delete, list and search students’ grades. ?

Each student has a name (assuming no students share the same name) and some course/grade pairs. If an existing name detected, user can choose to quit or to add new courses to that student. ?

Each student has 1 to 5 courses, each course has a unique name and a grade from 0 to 100. ?

The course name has to be one of these 5 courses: Database, Data Structure, Operating System, Mathematics, and System Design.

Your system should provide below functions:

1. Add a student with course and grade pairs by: a. Spelling out the student’s name, and then provide “Course name” and “Grade” of that course to add a new student. b. Or add new course/grade pair to an existing student.

2. Delete a. A student by spelling out the student’s name. b. Or courses of a student by providing student’s name and course names.

3. Search a student’s grades by: a. Providing only the student’s name which will results to a list of course/grade pairs. Plus the average grade among all courses of that student. b. Or by providing student’s name and course(s) name(s) which will results to the grade of that course or grades of multiple courses.

4. Update student’s grades by: Providing student’s name, and then provide “Course name” of the required course and put the new “Grade”.

5. List all student/grade pairs of a course by: providing “Course name”. The list should be shown in descending orders of the grades, for same grades, list in ascending alphabetical order of students’ names. Also, the average grade should be shown.

Thank you so much for the work! really need your help!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE TO COPY:

import java.util.ArrayList;

import java.util.Arrays;

import java.util.Collections;

import java.util.Comparator;

import java.util.HashMap;

import java.util.Scanner;

public class Grades {

public static void main(String[] args) {

HashMap<String, HashMap<String, Double>> students=new HashMap<String, HashMap<String, Double>>();

Scanner obj=new Scanner(System.in);

int choice=-1;

char ch=' ';

String name=null, course=null;

double grade=0;

do {

switch(choice)

{

case 1:

System.out.println("Enter the student's name.");

name=obj.nextLine().toLowerCase();

System.out.println("Enter the course name.");

course=obj.nextLine().toLowerCase();

System.out.println("Enter the grade.");

grade=Double.parseDouble(obj.nextLine());

if(!students.containsKey(name))

{

students.put(name, new HashMap<String, Double>());

}

students.get(name).put(course, grade);

break;

case 2:

System.out.println("1. Delete student.");

System.out.println("2. Delete course of student.");

choice=Integer.parseInt(obj.nextLine());

System.out.println("Enter the student's name.");

name=obj.nextLine().toLowerCase();

if(choice==1)

{

students.remove(name);

}

else {

System.out.println("Enter the course name.");

course=obj.nextLine().toLowerCase();

students.get(name).remove(course);

}

break;

case 3:

System.out.println("1. Search for student's complete grades.");

System.out.println("2. Search for student's grades in multiple courses.");

choice=Integer.parseInt(obj.nextLine());

System.out.println("Enter the student's name.");

name=obj.nextLine().toLowerCase();

if(choice==1)

{

//print all grades

Object list[]=students.get(name).keySet().toArray();

System.out.printf("\n%30s%30s\n", "Course", "Grade");

double avg=0;

for(int i=0; i<list.length; i++)

{

System.out.printf("%30s%30f\n", (String)list[i], students.get(name).get((String)list[i]));

avg+=students.get(name).get((String)list[i]);

}

avg/=list.length;

System.out.println("Average Grade: "+avg);

}

else {

String list[]=new String[5];

int index=0;

do {

System.out.println("\nEnter a course name.");

course=obj.nextLine().toLowerCase();

list[index++]=course;

System.out.println("Do you want to enter another course? (Y/N)");

ch=obj.nextLine().charAt(0);

}while(ch=='Y' || ch=='y');

System.out.printf("\n%30s%30s\n", "Course", "Grade");

double avg=0;

for(int i=0; i<list.length; i++)

{

System.out.printf("%30s%30f\n", list[i], students.get(name).get(list[i]));

avg+=students.get(name).get(list[i]);

}

avg/=list.length;

System.out.println("Average Grade: "+avg);

}

break;

case 4:

System.out.println("Enter the student's name.");

name=obj.nextLine().toLowerCase();

System.out.println("Enter the course name.");

course=obj.nextLine().toLowerCase();

System.out.println("Enter the new grades.");

grade=Double.parseDouble(obj.nextLine());

students.get(name).put(course, grade);

break;

case 5:

{

System.out.println("Enter course name.");

String course_=obj.nextLine().toLowerCase();

ArrayList<String> names=new ArrayList<String>();

Object names_[]=students.keySet().toArray();

  

for(int i=0; i<names_.length; i++)

if(students.get((String)names_[i]).containsKey(course_))

names.add((String)names_[i]);

  

Comparator<String> cmp=new Comparator<String>()

{

public int compare(String a, String b)

{

if(students.get(a).get(course_)>students.get(b).get(course_))

return -1;

else if(students.get(a).get(course_)==students.get(b).get(course_))

return -1;

else

return 1;

}

};

  

Collections.sort(names, cmp);

double avg=0;

int stuCount=0;

System.out.printf("\n%30s%30s%30s\n", "Student Name", "Course Name", "Grades");

for(int i=0; i<names.size(); i++)

{

avg+=students.get(names.get(i)).get(course_);

System.out.printf("%30s%30s%30f\n", names.get(i), course_, students.get(names.get(i)).get(course_));

}

System.out.println("\nAverage Grade: "+(avg/names.size()));

}

break;

}

System.out.println("\n\n1. Insert");

System.out.println("2. Delete");

System.out.println("3. Search");

System.out.println("4. Update");

System.out.println("5. List all students grades by course name");

System.out.println("6. Exit");

choice=Integer.parseInt(obj.nextLine());

}while(choice!=6);

}

}

PROGRAM SCREENSHOTS:

OUTPUT:

In case of any doubt, please let me know in the comments section. I'll get it resolved :):) Don't forget to give a THUMBS UP!!! :):)

Add a comment
Know the answer?
Add Answer to:
Design and code a JAVA program called ‘Grades’. ? Your system should store student’s name, and...
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
  • Write a program that asks the user for a student name and asks for grades until...

    Write a program that asks the user for a student name and asks for grades until the user enters a non-number input, it should then ask if the user wants to enter another student, and keep doing the process until the user stops adding students. The student’s must be stored in a dictionary with their names as the keys and grades in a list. The program should then iterate over the dictionary elements producing the min, max, and mean of...

  • The application should be in JAVA and allow: 1. Collect student information and store it in...

    The application should be in JAVA and allow: 1. Collect student information and store it in a binary data file. Each student is identified by an unique ID. The user should be able to view/edit an existing student. Do not allow the user to edit student ID. 2. Collect Course information and store it in a separate data file. Each course is identified by an unique ID. The user should be able to view/edit an existing course information. User is...

  • Create a new NetBeans project called PS1Gradebook. Your program will simulate the design of a student...

    Create a new NetBeans project called PS1Gradebook. Your program will simulate the design of a student gradebook using a two-dimensional array. It should allow the user to enter the number of students and the number of assignments they wish to enter grades for. This input should be used in defining the two-dimensional array for your program. For example, if I say I want to enter grades for 4 students and 5 assignments, your program should define a 4 X 5...

  • 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...

  • In JAVA please! Write program for exercises You will write a Graphical User Interface(GUI) application to manage student...

    In JAVA please! Write program for exercises You will write a Graphical User Interface(GUI) application to manage student information system. The application should allow: 1. Collect student information and store it in a binary data file. Each student is identified by an unique ID. The user should be able to view/edit an existing student. Do not allow student to edit ID. 2. Collect Course information and store it in a separate data file. Each course is identified by an unique...

  • PYTHON PROGRAMMING Instructions: You are responsible for writing a program that allows a user to do...

    PYTHON PROGRAMMING Instructions: You are responsible for writing a program that allows a user to do one of five things at a time: 1. Add students to database. • There should be no duplicate students. If student already exists, do not add the data again; print a message informing student already exists in database. • Enter name, age, and address. 2. Search for students in the database by name. • User enters student name to search • Show student name,...

  • 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...

  • Java - In NetBeans IDE: • Create a class called Student which stores: - the name...

    Java - In NetBeans IDE: • Create a class called Student which stores: - the name of the student - the grade of the student • Write a main method that asks the user for the name of the input file and the name of the output file. Main should open the input file for reading . It should read in the first and last name of each student into the Student’s name field. It should read the grade into...

  • using the java programming language Design a "Student Record Management System" in java including the following...

    using the java programming language Design a "Student Record Management System" in java including the following functionalities: 1 Input: Input student num, DOB, address, phone number etc. Input course titles, course number, time/locations. Input grade of each course for each student. 2 Process: Calculate GPA for each student. Sort and search on given criteria. 3 Output: Search by student num, show the student's information (including all courses and grades). Search by course num, show course information (including all students and...

  • Write the following program in C++. Review structures, pointers and dynamic memory allocation from CSIT 839....

    Write the following program in C++. Review structures, pointers and dynamic memory allocation from CSIT 839. Also, review pointers and dynamic memory allocation posted here under Pages. For sorting, you can refer to the textbook for Co Sci 839 or google "C++ sort functions". I've also included under files, a sample C++ source file named sort_binsearch.cpp which gives an example of both sorting and binary search. The Bubble sort is the simplest. For binary search too, you can refer to...

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
ADVERTISEMENT