Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

NEED ANSWER TO PART 3 AND 4, ALSO PLS CORRECT 1 AND 2 IF ANY MISTAKE 1. The application class The application class that keeps

NEED ANSWER TO PART 3 AND 4, ALSO PLS CORRECT 1 AND 2 IF ANY MISTAKE

1. The application class

The application class that keeps track of student information at your college: names, identification numbers, and grade point averages.

When launched, the user will be asked to input the maximum size of the data set, the initial number of students and the initial data set. Once this is complete, the user will be presented with the following menu: Enter: 1 to insert a new student's information, 2 to fetch and output a student's information, 3 to delete a student's information, 4 to update a student's information, 5 to output all the student information, 6 to exit the program

2. .The application (main) class is given, use the data structure class described(given below-UOAUTILITIES). Begin by coding the portion of it described below and test/debug that code. When the user selects an operation from the menu, simply output a message stating that the operation was performed (e.g. Delete operation performed) to a message box and redisplay the menu. You will complete the application (below).

// declare the data structure and load the initial data set

// input and parsing of the maximum number of nodes, max

// input and parsing of the initial number of students, n

// solicit and perform user requested operations on the data set

// output the menu to an input dialog box

// parse the menu choice into an integer

// while (true)

// { switch statement with six cases to output the operation selected or invoke System.exit(0)

// output the menu input dialog box

// parse the menu choice into an integer

// }

3. The completed application class (Application dependent: Student database at our college)

Complete the application begun above, as describes below. Test and debug it. Be sure to inform the user of success the success or failure to complete the requested operation, inside each case of the switch statement.

// declare the data structure object and load the initial data set

// input and parsing of the maximum number of nodes, max

// declare an object in the data structure class (defined in Step 2) and pass max to its constructor

// input of the initial number of students, n

// declare an object in the node definition class (defined in Step 1)

// a for loop that

// executes n times invoking the StudentListing classs input method (see pg 102)

// Invokd the insert method and then insert the StudentListing node to the data structure

// perform user requested operations on the data set

// output the menu to a message box

// parse the menu choice into an integer

// while (true)

// { switch statement to invoke insert, fetch, delete, update,

// showAll,//in the data structure class, or System.exit(0)

// output the menu message box

// parse the menu choice into an integer

// }

4. Modify the data structure class so that it expands (doubles in size) when full

public class UOAUtilities { private int next; private int size; private StudentListing[ ] data;

public UOAUtilities ( ) { next = 0; size = 100; data = new StudentListing[size]; }//end of constructor

public UOAUtilities (int s) { next = 0; data = new StudentListing[s]; size = s; }//end of constructor

public boolean insert(StudentListing newNode) { if(next >= size) // the structure is full return false; data[next]= newNode.deepCopy( ); // store a deep copy of the clients node if(data[next] == null) return false; next = next + 1; // prepare for the next insert return true; }// end of insert method

public StudentListing fetch(String targetKey) { StudentListing node; StudentListing temp; // access the node using a sequential search int i = 0; while ( i < next && !(data[i].compareTo(targetKey) == 0)) { i++; } if(i== next) // node not found return null; //deep copy the node's information into the client's node node = data[i].deepCopy( ); // move the node up one position in the array, unless it is the first node if(i != 0) // bubble-up accessed node { temp = data[i-1]; data[i-1] = data[i]; data[i] = temp; } return node; } // end of fetch method

public boolean delete(String targetKey) {// access the node using a sequential search int i = 0; while (i < next && !(data[i].compareTo(targetKey) == 0)) { i++; } if(i == next) // node not found return false; //move the last node into the deleted node's position data[ i] = data[ next -1]; data[next-1] = null; next = next - 1; return true; // node found and deleted }//end of the delete method

public boolean update(String targetKey, StudentListing newNode) { if(delete(targetKey) == false) // node not in the structure return false; else if( insert(newNode ) == false) // insufficient memory return false; else return true; // node found and updated }// end of update method public void showAll( ) { for(int i = 0; i< next; i++) System.out.println(data[i].toString( )); }// end showAll method }//end of class UOAUtilities

Solution:

import java.util.Map; //Class which contains all the methods public class StudentGradesPlanner { private StudentMockDB mockDB = new StudentMockDB(); void displayMainMenu() { System.out.println("-----------Enter :------------"); System.out.println("1: To insert a new student's information"); System.out.println("2: To Fetch and output student's information"); System.out.println("3: To delete a student's information"); System.out.println("4: To update a student's information"); System.out.println("5: to output all student's information"); System.out.println("6: to exit the program"); } void saveStudentData(Student student) { mockDB.studentMap.put(student.id, student); } Student getData(String id) { return mockDB.studentMap.get(id); } void deleteStudentData(String id) { mockDB.studentMap.remove(id); } void updateStudentInformation(String id, Student student) { mockDB.studentMap.put(id, student); } void displayAll() { for (Map.Entry stringStudentEntry : mockDB.studentMap.entrySet() { System.out.println(stringStudentEntry.getKey() + " " +stringStudentEntry.getValue().toString()); } } } //STUDENT Class public class Student { String id; String name; String grade; @Override public String toString() { return "Student{" + "id='" + id + '\'' + ", name='" + name + '\'' + ", grade='" + grade + '\'' + '}'; } public String getId() { return id; } public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getGrade() { return grade; } public void setGrade(String grade) { this.grade = grade; } } // Mock database class to store all data using hashmap import java.util.HashMap; import java.util.Map; public class StudentMockDB { Map studentMap = new HashMap<>(); } //MAIN Class import java.util.Scanner; import static java.lang.System.exit; public class Main { public static void main(String args[]) { StudentGradesPlanner gradesPlanner = new StudentGradesPlanner(); Scanner sc = new Scanner(System.in); System.out.println("Enter max size of data set"); // Max size of data set int max_size = sc.nextInt(); System.out.println("Enter initial number of students"); // Initial number of students int number = sc.nextInt(); sc.nextLine(); int count = 0; System.out.println("Enter student initial data"); while (count < number) { // Read an initial data set System.out.println("Student Count " + (count + 1)); System.out.println("enter id of student"); String id = sc.nextLine(); System.out.println("enter name of student"); String name = sc.nextLine(); System.out.println("enter grade of student"); String grade = sc.nextLine(); Student student = new Student(); student.id = id; student.name = name; student.grade = grade; gradesPlanner.saveStudentData(student); count++; } gradesPlanner.displayMainMenu(); while (sc.hasNext()) { int optionChosen = sc.nextInt(); switch (optionChosen) { case 1: { sc.nextLine(); System.out.println("enter id of student"); String id = sc.nextLine(); System.out.println("enter name of student"); String name = sc.nextLine(); System.out.println("enter grade of student"); String grade = sc.nextLine(); Student student = new Student(); student.id = id; student.name = name; student.grade = grade; gradesPlanner.saveStudentData(student); gradesPlanner.displayMainMenu(); break; } case 2: { sc.nextLine(); System.out.println(" Enter student's id to fetch his information"); String data = sc.nextLine(); Student studentData = gradesPlanner.getData(data); System.out.println(" Student data for id" + data + " is " + studentData); gradesPlanner.displayMainMenu(); break; } case 3: { sc.nextLine(); System.out.println("Enter student id to delete his/her information"); String data = sc.nextLine(); gradesPlanner.deleteStudentData(data); System.out.println("Student's information deleted successfully"); gradesPlanner.displayMainMenu(); break; } case 4: { sc.nextLine(); System.out.println("To update student's information enter student id first"); String id = sc.nextLine(); System.out.println("Enter student's complete information in pattern {id, " + "name, grade}"); String data = sc.nextLine(); String[] newStudentData; newStudentData = data.split(","); Student newStudent = new Student(); newStudent.id = newStudentData[0]; newStudent.name = newStudentData[1]; newStudent.grade = newStudentData[2]; gradesPlanner.updateStudentInformation(id, newStudent); gradesPlanner.displayMainMenu(); break; } case 5: { gradesPlanner.displayAll(); gradesPlanner.displayMainMenu(); break; } case 6: { exit(0); break; } } } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Spatial Databases 2nd Symposium Ssd 91 Zurich Switzerland August 1991 Proceedings Lncs 525

Authors: Oliver Gunther ,Hans-Jorg Schek

1st Edition

3540544143, 978-3540544142

More Books

Students also viewed these Databases questions

Question

How will the members be held accountable?

Answered: 1 week ago

Question

a. Do team members trust each other?

Answered: 1 week ago

Question

a. How will the leader be selected?

Answered: 1 week ago