Question

Project 2 Due April 15° 11:59pm. You could use an the implementation. y of the following programming language to do CH Java P
1 2 965 69 566 5669 5596 /9959/69996999/699/9 110/31/851/9271/52-4 91//81/232/0710/5/57 11262172211113391121 MM: F F F F M M
Project 2 Due April 15° 11:59pm. You could use an the implementation. y of the following programming language to do CH Java Python You will implement a student class with data members (ID, gender, DoB, Major, GPA). You will implement a gradebook class using (Inherit from) TWO of the following data structures. Array Singly Linked list ea Binary Search Tree You need to at least implement the followin gradebook. operations for the 1) FindHighestGPA0 returns the student who has the highest GPA 2) Insert insert a student record to the gradebook 3) Delete(studentID) delete a student record using student ID from the gradebook 4) Search(studentID) returns the student who has the student ID Test your code using the data in student data.txt. Import and parsing the data is suggested. DO NOT type in these data. Write an essay to discuss the advantages and disadvantages of using the Four data structures (Array, Singly Linked list, Heap, Binary Search Tree) to implement a student grade system considering the time efficiency and space efficiency You will do a 10 thoughts in the essay Submission check list mins presentation to demo your code and your 1. Source code [10 points] 2. Screenshots of test result and a document to explain your screenshots [10 points] 3. Essay [10 points] 4. Presentation PPT[10 points
1 2 965 69 566 5669 5596 /9959/69996999/699/9 110/31/851/9271/52-4 91//81/232/0710/5/57 11262172211113391121 MM: F F F F M M F F M M M F F M F F M 20 6562473 3162711982-121115242 STuh0a 4-9-7-5-4-1-0-2-9-3-0-0-8-1-3-9-2|8-4-8
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Student.java

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.LinkedList;
import java.util.Scanner;

public class Student {
   LinkedList<StudentDetails> linkedList = new LinkedList<>();

   final String fileName = "data.txt";

   File file = new File(fileName);

   static FileWriter fileWriter;

   void readFile() throws IOException {
       File file = new File(fileName);

       BufferedReader br = new BufferedReader(new FileReader(file));

       String str;

       while ((str = br.readLine()) != null ) {
           String arr[] = str.split(" ");
           linkedList.add(new StudentDetails(arr[0], arr[1], arr[2], arr[3], Float.parseFloat(arr[4])));

           }
   }

   void writeToFile(String data) {
       try {
           if(fileWriter==null)
               fileWriter = new FileWriter(file);
      
           fileWriter.write(data+"\n");

           fileWriter.flush();
       } catch (IOException e) {
           e.printStackTrace();
       }
   }

   void findHighestGPA() {
       float highestGPA = linkedList.get(0).getGPA();
       for (int i = 1; i < linkedList.size(); i++) {
           if (linkedList.get(i).getGPA() > highestGPA) {
               highestGPA = linkedList.get(i).getGPA();
           }
       }
       System.out.println("Higest GPA is " + highestGPA);
   }

   void delete(String studentID) {
       for (int i = 0; i < linkedList.size(); i++) {
           if (linkedList.get(i).getID().equalsIgnoreCase(studentID)) {
               linkedList.remove(i);
               System.out.println("Data removed");
           }
       }
   }

   void search(String studentID) {
       for (int i = 0; i < linkedList.size(); i++) {
           if (linkedList.get(i).getID().equalsIgnoreCase(studentID)) {

               System.out.println(linkedList.get(i).toString());
           }
       }
   }

   public static void main(String[] args) throws IOException {
       Scanner scanner = new Scanner(System.in);
       String ID, gender, DoB, Major;
       float GPA;

       Student student = new Student();
   student.readFile(); // read file and add data to linked list for further easily processing
       char ch = 0;
       do {
           System.out.println("1.Find highest GPA ");
           System.out.println("2.Insert data ");
           System.out.println("3.Delete data ");
           System.out.println("4.Search data ");
           int n = scanner.nextInt();
           switch (n) {
           case 1:// find highest Gpa
               student.findHighestGPA();
               break;
           case 2:// insert
              
               System.out.println("Enter student ID ");
               ID = scanner.next();
               System.out.println("Enter student gender ");
               gender = scanner.next();
               System.out.println("Enter student DoB ");
               DoB = scanner.next();
               System.out.println("Enter student Major ");
               Major = scanner.next();
               System.out.println("Enter student GPA ");
               GPA = scanner.nextFloat();
               String data = ID + " " + gender + " " + DoB + " " + Major + " " + GPA;
               student.writeToFile(data);
               student.linkedList.clear();
               student.readFile(); // read file and add data to linked list for further easily processing
              
               break;
           case 3:// delete

               System.out.println("Enter student ID ");
               student.delete(scanner.next());
               break;
           case 4:// search

               System.out.println("Enter student ID ");
               student.search(scanner.next());
               break;
           }
           System.out.println("Do you want to continue? ");
           ch = scanner.next().charAt(0);
       } while (ch == 'Y' || ch == 'y');

       // close the file as program is terminating

       student.fileWriter.close();
   }

   // Model or POJO class
   class StudentDetails {
       private String ID, gender, DoB, Major;
       private float GPA;

       public StudentDetails(String iD, String gender, String doB, String major, float gPA) {
           setID(iD);
           setGender(gender);
           setDoB(doB);
           setMajor(major);
           setGPA(gPA);
       }

       public String getID() {
           return ID;
       }

       public void setID(String iD) {
           ID = iD;
       }

       public String getGender() {
           return gender;
       }

       public void setGender(String gender) {
           this.gender = gender;
       }

       public String getDoB() {
           return DoB;
       }

       public void setDoB(String doB) {
           DoB = doB;
       }

       public String getMajor() {
           return Major;
       }

       public void setMajor(String major) {
           Major = major;
       }

       public float getGPA() {
           return GPA;
       }

       public void setGPA(float gPA) {
           GPA = gPA;
       }

       @Override
       public String toString() {
           return ID + " " + gender + " " + DoB + " " + Major + " " + GPA;
       }

   }
}

Output

1.Find highest GPA
2.Insert data
3.Delete data
4.Search data
2
Enter student ID
JU-3
Enter student gender
M
Enter student DoB
19/12/95
Enter student Major
CS
Enter student GPA
60
Do you want to continue?
y
1.Find highest GPA
2.Insert data
3.Delete data
4.Search data
1
Higest GPA is 60.0
Do you want to continue?
y
1.Find highest GPA
2.Insert data
3.Delete data
4.Search data
4

Enter student ID
ju-3
JU-3 M 19/12/95 CS 60.0
Do you want to continue?
y
1.Find highest GPA
2.Insert data
3.Delete data
4.Search data
3
Enter student ID
ju-3
Data removed
Do you want to continue?
y
1.Find highest GPA
2.Insert data
3.Delete data
4.Search data
4
Enter student ID
Ju-3
Do you want to continue?
n

Add a comment
Know the answer?
Add Answer to:
Project 2 Due April 15° 11:59pm. You could use an the implementation. y of the following programm...
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
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