Question

Write a java code : Student ID at University is composed of year of admission and...

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, name, GPA).
You need to :
1-Create a new class Student.
2- Use class Singly Linked List, however you need to replace data to be of type Student.
3- Build class Tree0fList that is similar to class Tree, it has the following methods:
a- insert(Student) to insert a new student. It should be inserted based on his ID in a tree node that has linked list of students in that year, if no node created yet for that year (this is the first student) then a new node should be created.
b- find( int ID) it returns a student with that ID or null.
c- remove (int id ): it searchers for student with the input id and remove his record, if that record was the last one in the linked list , then that node should be removed.
d- Print (int ): it receives an integer number represents the year and prints students name who were admitted in that year.
e- lessGPA(int x), it returns an array list of all students whose GPA is less than or equal x.
4- Test your structure in a test application (main method).

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

JAVA PROGRAM:

import java.util.ArrayList;
import java.util.Scanner;

public class University {

public static void main(String[] args) {
new University().run();
}

static class Student {

Student left = null;
Student right = null;
int id;
String name;
String address;
double GPA;

public Student(int id, String name, String address, double GPA) {
this.id = id;
this.name = name;
this.address = address;
this.GPA = GPA;
}


public String toString() {
return "Student{" + "id=" + id + ", name=" + name + ", address=" + address + ", GPA=" + GPA + '}';
}
  
}

public void run() {

Student root = new Student(123,"John","USA",20.0);
Scanner sc = new Scanner(System.in);
while(true){

System.out.println("1. insert 2. find 3. print 4. studentWithGPA 5.exit");
int choice = sc.nextInt();
  
if(choice == 1){
System.out.println("Enter id: ");
int id = sc.nextInt();
System.out.println("Enter name: ");
String name = sc.nextLine();
System.out.println("Enter Address: ");
String address = sc.nextLine();
System.out.println("Enter GPA: ");
double GPA = sc.nextDouble();
insert(root,id,name,address,GPA);
}
  

else if(choice == 2){
System.out.println("Enter id to search: ");
int id = sc.nextInt();
Student record = find(root,id);
}

else if(choice == 3){
print(root);
}
  

else if(choice == 4){
System.out.println("Enter GPA to search: ");
double GPA = sc.nextDouble();
ArrayList<Student> data = StudentWithGPA(root,GPA);
for(int i=0;i<data.size();i++){
System.out.println(data.get(i));
}
}

else{
break;
}
}
}


public void insert(Student node, int id,String name,String address,double GPA) {
if (id < node.id) {
if (node.left != null) {
insert(node.left, id,name,address,GPA);
} else {
System.out.println(" Inserted " + id + " to left of "
+ node.id);
node.left = new Student(id,name,address,GPA);
}
} else if (id > node.id) {
if (node.right != null) {
insert(node.right, id,name,address,GPA);
} else {
System.out.println(" Inserted " + id + " to right of "
+ node.id);
node.right = new Student(id,name,address,GPA);
}
}
}
  

public Student find(Student node, int id){
if(node.id == id){
return node;
}
while(node != null){
if(node.id == id){
return node;
}
else{
node = node.right;
}
}
return null;
}
  

public void print(Student node) {
if (node != null) {
print(node.left);
System.out.println(" Traversed " + node);
print(node.right);
}
}
  

public ArrayList<Student> StudentWithGPA(Student node, double GPA){
ArrayList<Student> nodes = new ArrayList<Student>();
while(node != null){
if(node.GPA <= GPA){
nodes.add(node);
}
node = node.right;
}
return nodes;
}
}


answered by: ANURANJAN SARSAM
Add a comment
Know the answer?
Add Answer to:
Write a java code : Student ID at University is composed of year of admission 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
  • I need code in java The Student class: CODE IN JAVA: Student.java file: public class Student...

    I need code in java The Student class: CODE IN JAVA: Student.java file: public class Student {    private String name;    private double gpa;    private int idNumber;    public Student() {        this.name = "";        this.gpa = 0;        this.idNumber = 0;    }    public Student(String name, double gpa, int idNumber) {        this.name = name;        this.gpa = gpa;        this.idNumber = idNumber;    }    public Student(Student s)...

  • Student class: Instance variables name id Constructors: Default constructor Constructor that has id and name passed...

    Student class: Instance variables name id Constructors: Default constructor Constructor that has id and name passed to the constructor Methods: Accessors int getID( ) String getName( ) Class Roster: This class will implement the functionality of all roster for school. Instance Variables a final int MAX_NUM representing the maximum number of students allowed on the roster an ArrayList storing students Constructors a default constructor should initialize the list to empty strings a single parameter constructor that takes an ArrayList<Student> Both...

  • java A University would like to implement its students registery as a binary search tree, calledStudentBST....

    java A University would like to implement its students registery as a binary search tree, calledStudentBST. Write an Student node class, called StudentNode, to hold the following information about an Student: - id (as a int) - gpa (as double) StudentNode should have constructors and methods (getters, setters, and toString()) to manage Write the StudentBST class, which is a binary search tree to hold objects of the class StudentNode. The key in each node is the id. : import.java.ArrayList; public...

  • 13. Given the following structure struct node { struct node *next; int id; }; Write a...

    13. Given the following structure struct node { struct node *next; int id; }; Write a code to insert a new node into the linked list as the last node of the linked list struct node *insertLast(stuct node **head, int newId) { } 14. Given the following structure struct node { struct node *next; int id; }; Write a code to insert a new node into the linked list after a node with the same id as the input parameter...

  • Write a C++ program that includes the following: Define the class Student in the header file Stu...

    Write a C++ program that includes the following: Define the class Student in the header file Student.h. #ifndef STUDENT_H #define STUDENT_H #include <string> #include <iostream> using namespace std; class Student { public: // Default constructor Student() { } // Creates a student with the specified id and name. Student(int id, const string& name) { } // Returns the student name. string get_name() const { } // Returns the student id. int get_id () const { } // Sets the student...

  • In Java programming language Please write code for the 6 methods below: Assume that Student class...

    In Java programming language Please write code for the 6 methods below: Assume that Student class has name, age, gpa, and major, constructor to initialize all data, method toString() to return string reresentation of student objects, getter methods to get age, major, and gpa, setter method to set age to given input, and method isHonors that returns boolean value true for honors students and false otherwise. 1) Write a method that accepts an array of student objects, and n, the...

  • Using Java coding, complete the following: This program should implement a LinkedList data structure to handle...

    Using Java coding, complete the following: This program should implement a LinkedList data structure to handle the management of student records. It will need to be able to store any number of students, using a Linked List. LinearNode.java can be used to aid creating this program Student should be a class defined with the following:    • String name    • int year    • A linked list of college classes (college classes are represented using strings)    • An...

  • I have a C++ code that lets me enter, display and delete a student record. I...

    I have a C++ code that lets me enter, display and delete a student record. I need to implement a function that prints the average grade score of the students I input. Below is my code and a picture of how my code looks right now. #include<iostream> #include<stdlib.h> using namespace std; //Node Declaration struct node {    string name;    string id;    int score;    node *next;   }; //List class class list {        private:        //head...

  • Question 1 (24 Marks] 1. (4 marks) Write an immutable Person class in Java which provides...

    Question 1 (24 Marks] 1. (4 marks) Write an immutable Person class in Java which provides the following. • Two attributes: lastName and first Name of type String. • Appropriate initialization, accessors/mutator methods. 2. (6 marks) Write a Student class that is a subclass of Person class (in the previous question) which provides the following. • Two attributes: A unique student ID of type String and GPA of type float; the student ID is initialized when a Student object gets...

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

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