Using Java Please use the existing code given below Create two classes: Student Faculty Each class stores a name and id.
Posted: Sun May 15, 2022 1:19 pm
Using Java
Please use the existing code given below
Create two classes:
Student
Faculty
Each class stores a name and id. Students have a gpa (floating
point number) while Faculty has an integer that keeps track of the
number of credits taught.
Create a hash table to store student and faculty data (they will
be stored separately, not in the same variable)
The hashing function for student is as follows:
student ((id*3) / 14)
The hashing function for faculty is as follows:
The last 2 digits of the id.
To place an item in the table, the hash value should then be
modded with the size of the internal array.
So for example if the array is size 10, if you have a student
with id 4, the hash would be: (4*3) / 12, 12/14 = 0, 0 % 10 = 0, so
the item should be placed in index 0.
The hash table should use linear probing to handle collisions,
you do not need
to handle the case of the table being filled to capacity.
A class which provides a menu to work with the data is provided,
you are allowed to make changes to the file as needed (and you'll
need to change the code for option 1 for the assignment)
Your hash table must use an array for internal storage of data
and provide the following methods:
Constructor that sets the size of the internal array
public void setDeafault(item)
sets an object to return if getByKeyOrDefault is is called for a
non present item
public int add(item)
places item in the table and returns the index it was stored in, or
-1 if the item could not be added.
getByKeyOrDefault(int hash, int key)
returns the item with the specified hash and key, or the default
value if the requested item is not present
get(item)
Returns an item with a matching key to the requested item, or null
if not present
getByKey(int hash, int key)
returns the item with the specified hash and key, or null if the
requested item is not present
delete(T value)
Deletes the value from the hash table that has the key matching the
value requested
delete(int key, int hash)
Deletes the value from the hash table that has the requested key
and hash value
The provided code uses the following interface:
public interface HashableItem {
public int getHash();
public int getKey();
}
The provided code is not the code that will be used for grading
, you need to implement all of the mentioned methods, and your
table should work with an arbitrary given size, not just 10 as used
in the provided code.
============================================================================================
Code Provided:
Hash_Project
/*
* Click
nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt
to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java
to edit this template
*/
package hash_project;
import java.util.Scanner;
/**
*
* @author John
*/
public class Hash_project {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
HashTable265<Student> studentTable = new
HashTable265<>(10);
HashTable265<Faculty> facultyTable = new
HashTable265<>(10);
Scanner input = new Scanner(System.in);
int sel;
while(true)
{
System.out.printf("1) Author Info\n2) Add Student\n3) Add
Faculty\n4) Get Student Data\n");
System.out.printf("5) Get Faculty Data\n6) Delete Student\n7)
Delete Faculty\n0) Exit\n");
sel = input.nextInt();
if (sel == 1)
{
//TODO: put author info
System.out.println("Name");
}
else if (sel == 2)
{
Student newStudent = new Student();
System.out.println("Enter student name\n");
while((newStudent.name = input.nextLine()).isEmpty());
System.out.println("Enter student ID\n");
newStudent.studentID = input.nextInt();
studentTable.add(newStudent);
}
else if (sel == 3)
{
Faculty newFaculty = new Faculty();
System.out.println("Enter faculty name\n");
while((newFaculty.name = input.nextLine()).isEmpty());
System.out.println("Enter faculty ID\n");
newFaculty.facultyID = input.nextInt();
facultyTable.add(newFaculty);
}
else if (sel == 4)
{
System.out.println("Enter student ID you wich to
retrieve\n");
int id = input.nextInt();
Student find = new Student();
find.studentID = id;
System.out.printf("\n-----------\n%s\n-----------\n",
studentTable.get(find));
}
else if (sel == 5)
{
System.out.println("Enter faculty ID you wich to
retrieve\n");
int id = input.nextInt();
Faculty find = new Faculty();
find.facultyID = id;
System.out.printf("\n-----------\n%s\n-----------\n",
facultyTable.get(find));
}
else if (sel == 6)
{
System.out.println("Enter student ID you wich to delete\n");
int id = input.nextInt();
Student find = new Student();
find.studentID = id;
studentTable.delete(find);
}
else if (sel == 7)
{
System.out.println("Enter faculty ID you wich to delete\n");
int id = input.nextInt();
Faculty find = new Faculty();
find.facultyID = id;
facultyTable.delete(find);
}
}
}
}
=============================================================================
HashableItem
/*
* Click
nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt
to change this license
* Click
nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to
edit this template
*/
package hash_project;
/**
*
* @author John
*/
public interface HashableItem {
public int getHash();
public int getKey();
}
Please use the existing code given below
Create two classes:
Student
Faculty
Each class stores a name and id. Students have a gpa (floating
point number) while Faculty has an integer that keeps track of the
number of credits taught.
Create a hash table to store student and faculty data (they will
be stored separately, not in the same variable)
The hashing function for student is as follows:
student ((id*3) / 14)
The hashing function for faculty is as follows:
The last 2 digits of the id.
To place an item in the table, the hash value should then be
modded with the size of the internal array.
So for example if the array is size 10, if you have a student
with id 4, the hash would be: (4*3) / 12, 12/14 = 0, 0 % 10 = 0, so
the item should be placed in index 0.
The hash table should use linear probing to handle collisions,
you do not need
to handle the case of the table being filled to capacity.
A class which provides a menu to work with the data is provided,
you are allowed to make changes to the file as needed (and you'll
need to change the code for option 1 for the assignment)
Your hash table must use an array for internal storage of data
and provide the following methods:
Constructor that sets the size of the internal array
public void setDeafault(item)
sets an object to return if getByKeyOrDefault is is called for a
non present item
public int add(item)
places item in the table and returns the index it was stored in, or
-1 if the item could not be added.
getByKeyOrDefault(int hash, int key)
returns the item with the specified hash and key, or the default
value if the requested item is not present
get(item)
Returns an item with a matching key to the requested item, or null
if not present
getByKey(int hash, int key)
returns the item with the specified hash and key, or null if the
requested item is not present
delete(T value)
Deletes the value from the hash table that has the key matching the
value requested
delete(int key, int hash)
Deletes the value from the hash table that has the requested key
and hash value
The provided code uses the following interface:
public interface HashableItem {
public int getHash();
public int getKey();
}
The provided code is not the code that will be used for grading
, you need to implement all of the mentioned methods, and your
table should work with an arbitrary given size, not just 10 as used
in the provided code.
============================================================================================
Code Provided:
Hash_Project
/*
* Click
nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt
to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java
to edit this template
*/
package hash_project;
import java.util.Scanner;
/**
*
* @author John
*/
public class Hash_project {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
HashTable265<Student> studentTable = new
HashTable265<>(10);
HashTable265<Faculty> facultyTable = new
HashTable265<>(10);
Scanner input = new Scanner(System.in);
int sel;
while(true)
{
System.out.printf("1) Author Info\n2) Add Student\n3) Add
Faculty\n4) Get Student Data\n");
System.out.printf("5) Get Faculty Data\n6) Delete Student\n7)
Delete Faculty\n0) Exit\n");
sel = input.nextInt();
if (sel == 1)
{
//TODO: put author info
System.out.println("Name");
}
else if (sel == 2)
{
Student newStudent = new Student();
System.out.println("Enter student name\n");
while((newStudent.name = input.nextLine()).isEmpty());
System.out.println("Enter student ID\n");
newStudent.studentID = input.nextInt();
studentTable.add(newStudent);
}
else if (sel == 3)
{
Faculty newFaculty = new Faculty();
System.out.println("Enter faculty name\n");
while((newFaculty.name = input.nextLine()).isEmpty());
System.out.println("Enter faculty ID\n");
newFaculty.facultyID = input.nextInt();
facultyTable.add(newFaculty);
}
else if (sel == 4)
{
System.out.println("Enter student ID you wich to
retrieve\n");
int id = input.nextInt();
Student find = new Student();
find.studentID = id;
System.out.printf("\n-----------\n%s\n-----------\n",
studentTable.get(find));
}
else if (sel == 5)
{
System.out.println("Enter faculty ID you wich to
retrieve\n");
int id = input.nextInt();
Faculty find = new Faculty();
find.facultyID = id;
System.out.printf("\n-----------\n%s\n-----------\n",
facultyTable.get(find));
}
else if (sel == 6)
{
System.out.println("Enter student ID you wich to delete\n");
int id = input.nextInt();
Student find = new Student();
find.studentID = id;
studentTable.delete(find);
}
else if (sel == 7)
{
System.out.println("Enter faculty ID you wich to delete\n");
int id = input.nextInt();
Faculty find = new Faculty();
find.facultyID = id;
facultyTable.delete(find);
}
}
}
}
=============================================================================
HashableItem
/*
* Click
nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt
to change this license
* Click
nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to
edit this template
*/
package hash_project;
/**
*
* @author John
*/
public interface HashableItem {
public int getHash();
public int getKey();
}