Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This program must consist of two classes. 1. The first class should define the G

ID: 3855596 • Letter: T

Question

This program must consist of two classes. 1. The first class should define the GUI and handle the database interactions. The second class named Student, should define the student record. It must have instance variables for the student name, major and two variables that are used to compute the GPA. A variable that contains the total number of credits completed and a second variable that contains the total quality points, which are the numeric value of the grade received in a course times the number of credit hours. It should not contain the student ID. The class should have the following three methods: 2. A constructor that is used when new student records are created. It should accept the name and major as parameters and initialize the fields that are used to compute the GPA to zero. The second method courseCompleted should accept the course grade and credit hours and update the variables used to compute the GPA. It will be called when an Updote request is made. The third method should override toString and return a labeled string containing the student name, major and GPA. a. b. c. Finally when a student has not yet completed any course, the GPA should be displayed as 4.0. The google recommended Java style guide, provided as link in the week 2 content, should be used to format and document your code. Specifically, the following style guide attributes should be addressed Header comments include filename, author, date and brief purpose of the program. In-line comments used to describe major functionality of the code. Meaningful variable names and prompts applied. . .Class names are written in UpperCamelCase. Variable names are written in lowerCamelCase. Constant names are in written in All Capitals. Braces use K&R; style. In addition the following design constraints should be followed: Declare all instance variables private Avoid the duplication of code Also any exceptions thrown by nonnumeric inputs should be properly handled · Test cases should be supplied in the form of table with columns indicating the input values, expected output, actual output and if the test case passed or failed. This table should contain 4 columns with appropriate labels and a row for each test case. Note that the actual output should be the actual results you receive when running your program and applying the input for the test record. Be sure to select enough different scenarios to completely test the program. Submission requirements Deliverables include allava files (Java) and a single word (or PDF) document. The Java files should be named appropriately for your applications. The word (or PDF) document should include screen captures showing the successful compiling and running of each of the test cases. Each screen capture should be properly labeled clearly indicated what the screen capture represents. The test cases table should be included in your word or PDF document and properly labeled as well Submit your files to the Project 4 assignment area no later than the due date listed in your LEO classroom. You should include your name and P4 in your word (or PDF) file submitted (e.g firstnamelastnameP4.docx or firstnamelastnameP4.pdf.

Explanation / Answer

//StudentDatabase.java import java.util.HashMap; public class StudentDatabase { private final HashMap db; public StudentDatabase() { this.db = new HashMap(); } public boolean add(int id, String name, double gpa) { if (db.containsKey(id)) return false; db.put(id, new StudentRecord(name, gpa)); return true; } public boolean remove(int id) { if (!db.containsKey(id)) return false; db.remove(id); return true; } public StudentRecord get(int id) { return db.get(id); } } //StudentRecord.java public class StudentRecord { private String name; private double gpa; public StudentRecord(String name, double gpa) { this.name = name; this.gpa = gpa; } public String getName() { return name; } public double getGpa() { return gpa; } public void setName(String newName) { name = newName; } public void setGpa(double newGpa) { gpa = newGpa; } } //StudentDbGui.java import javax.swing.*; import java.awt.GridLayout; import java.awt.event.*; public class StudentDbGui { private StudentDatabase db; private JTextField idField; private JTextField nameField; private JTextField gpaField; private JComboBox selectionBox; private JButton processBtn; private JFrame frame; private class ProcessRequest implements ActionListener { public void actionPerformed(ActionEvent event) { int id = Integer.parseInt(idField.getText()); String selection = (String) selectionBox.getSelectedItem(); if (selection == "Insert") insert(id); else if (selection == "Delete") remove(id); else if (selection == "Find") find(id); } private void insert(int id) { String name = nameField.getText(); double gpa = Double.parseDouble(gpaField.getText()); if (!db.add(id, name, gpa)) { String msg = "Student with id "+id+" is already in database"; JOptionPane.showMessageDialog(frame, msg, "Insert Error", JOptionPane.ERROR_MESSAGE); } } private void remove(int id) { if (!db.remove(id)) { String msg = "Database doesn't contain any student with id "+id; JOptionPane.showMessageDialog(frame, msg, "Delete Error", JOptionPane.ERROR_MESSAGE); } } private void find(int id) { StudentRecord rec = db.get(id); if (rec == null) { String msg = "Cannot find any student with id " + id; JOptionPane.showMessageDialog(frame, msg, "Find Error", JOptionPane.ERROR_MESSAGE); } else { nameField.setText(rec.getName()); gpaField.setText(""+rec.getGpa()); } } } public StudentDbGui(String title) { db = new StudentDatabase(); idField = new JTextField(); nameField = new JTextField(); gpaField = new JTextField(); selectionBox = new JComboBox(); selectionBox.addItem("Insert"); selectionBox.addItem("Delete"); selectionBox.addItem("Find"); processBtn = new JButton("Process Request"); processBtn.addActionListener(new ProcessRequest()); frame = new JFrame(title); frame.setLayout(new GridLayout(6, 2, 16, 8)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new JLabel("Id:")); frame.add(idField); frame.add(new JLabel("Name:")); frame.add(nameField); frame.add(new JLabel("Major:")); frame.add(gpaField); frame.add(new JLabel("Choose Selection:")); frame.add(selectionBox); frame.add(processBtn); frame.pack(); frame.setVisible(true); } public static void main(String[] args) { new StudentDbGui("Project 4"); } }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote