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
Project 2 Due April 15° 11:59pm. You could use an the implementation. y of the following programm...
Write a java code : Student ID at University is composed of year of admission and students number. we aim to implement a structure that improves operations of inserting and searching for a student. To enhance these operations, we will build a tree of linked lists (TreeOfLists) to combine advantages of both structures. Each node in this tree contains a linked list of all students who were admitted in that year. Each node in the linked list represents a student(id,...
Can you please help with the below? 1) Which of the following is true about using a 2-3-4 tree? a. It is designed to minimize node visits while keeping to an O(log n) search performance b. It is designed to self-balance as new values are inserted into the tree c. As soon as a node becomes full, it performs the split routine d. None of the above 2) Which of the following is true about a binary search tree? a. ...
Project 4 simulation with conway's rules for life - revisited due before 4/30 11:59pm, autograded by project 4 zylab, limited to 10 submissions. We will be using the concepts from project 2 to test the more recent concepts of linked lists, pointers, and file I/O. The initial data points will be stored in a file (specification of the layout of the file below), each grid of values will be dynamically allocated and then referenced via a pointer in a linked...
Hw08FinalProjectStudentList.txt: (Data structure is Array List) 1,Simon,Jefferson,gy3085,4.0,2019 2,John,Johnson,xy1242,3.9,2019 3,Kayla,Anderson,as1324,3.8,2019 4,David,Kidman,re5423,3.8,2017 5,Mary,Coleman,ze7698,3.8,2018 Description: This assignment is going to evaluate your overall knowledge of the Java Programming. You shall implement a program which can store and retrieve student list. The program has a menu that you can take input from console, and the user can choose between the items. The program data is in the HwO8FinalProjectStudentList.txt file. Required Items: 1. The program must show a menu to user and ask the user...
Hw08FinalProjectStudentList.txt 1,Simon,Jefferson,gy3085,4.0,2019 2,John,Johnson,xy1242,3.9,2019 3,Kayla,Anderson,as1324,3.8,2019 4,David,Kidman,re5423,3.8,2017 5,Mary,Coleman,ze7698,3.8,2018 Description: This assignment is going to evaluate your overall knowledge of the Java Programming. You shall implement a program which can store and retrieve student list. The program has a menu that you can take input from console, and the user can choose between the items. The program data is in the HwO8FinalProjectStudentList.txt file. Required Items: 1. The program must show a menu to user and ask the user can either choose between the...
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...
Instructions Part 1 - Implementation of a Doubly Linked List Attached you will find the code for an implementation of a Singly Linked List. There are 3 files: Driver.java -- testing the List functions in a main() method. LinkNode.java -- Class definition for a Node, which is the underlying entity that stores the items for the linked list. SinglyLinkedList.java -- Class definition for the Singly Linked List. All the heavy lifting happens here. Task 1 - Review & Testing: Create...
1. State and explain the definition of big-O. 2. Explain why we use big-O to compare algorithms. 3. Explain why binary search runs in O(log n) time. 4. Under what conditions is it possible to sort a list in less than O(nlog n) time? 5. List and explain the worst-case and average-case running times for each Vector method below: (a) insert(iterator here, Object item) (b) insertAtHead (c) insertAtTail (aka push back) (d) get(iterator here) (e) get(index i) (f) remove(iterator here)...
Assignment #2: List - Array Implementation Review pages 6-7 in "From Java to C++" notes. Due Friday, February 9th, 2017 @ 11:59PM EST Directions Create a List object. Using the following definition (List.h file is also in the repository for your convenience) for a list, implement the member functions (methods) for the List class and store the implementation in a file called List.cpp. Use an array to implement the list. Write the client code (the main method and other non-class...
C++ Assignment Project 1 - NodeList Building upon the the ListNode/List code I would like you to extend the interface of a list to have these member functions as well. struct ListNode { int element; ListNode *next; } Write a function to concatenate two linked lists. Given lists l1 = (2, 3, 1)and l2 = (4, 5), after return from l1.concatenate(l2)the list l1should be changed to be l1 = (2, 3, 1, 4, 5). Your function should not change l2and...