Implement the perfect hashed data structure and provide Java application that de
ID: 3683782 • Letter: I
Question
Implement the perfect hashed data structure and provide Java application that demonstrates that its four basic operation methods function properly. Your application should store nodes for a stadium ticket application where the ticket numbers range from 2000 to 100,000 for a 60,000 seat stadium. The ticket number will be the key field and the nodes will also store the purchaser's name. See Figure 5.4 for a description of the field widths.
Your application will continually present the user with a menu to perform the 6 basic operations (insert, fetch, delete, update, output all, and exit the program)
Fig 5.4:
Ticket number Name 342556 Mr. Jones 28 bytes 4 bytesExplanation / Answer
import java.sql.Connection;
import java.util.Scanner;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
class choices
{
private int ticket num;
private Purchaser name;
Scanner sc = new Scanner(System.in);
boolean isAgain = true;
public void InsertMethod()
{
System.out.println("Enter ticket num ");
id = sc.nextInt();
em.setTN(num);
System.out.println("Enter Employee Name: ");
name = sc.next();
em.setPUR_Name(name);
}
public void UpdateMethod()
{
System.out.println("Enter Employee Id whose record you want to update: ");
id = sc.nextInt();
em.setTN(num);
System.out.println("Enter Purchase new Name whose id is:"+id);
name = sc.next();
em.setPUR_Name(name);
}
public void DeleteMethod()
{
System.out.println("Enter stadium TN whose record you want to Delete: ");
num= sc.nextInt();
}
public boolean askAgain()
{
System.out.println("Press 1 to display menu again, press any other key to exit");
ch = sc.nextInt();
if(ch == 1)
return true;
else
return false;
}
public void choice() throws ClassNotFoundException, SQLException
{
do
{
try
{
int choice;
Test t = new Test();
EmpDbComponent db = new EmpDbComponent();
ResultSet rs;
System.out.println("Enter you choice 1.>Press 1 to Display 2.>Press 2 to Insert 3.> Press 3 to Update 4.> press 4 to Delete 5.> Press 5 to Exit ");
choice = sc.nextInt();
switch(choice)
{
case 1:
{
System.out.println("--- -----");
System.out.println("Id Name");
System.out.println("--- -----");
rs = db.fetchRecords(t.getConnection());
while(rs.next())
{
System.out.print(rs.getInt(1)+" ");
System.out.print(rs.getString(2)+" ");
}
break;
}
case 2:
{
InsertMethod();
Stadium PUR = new PUR(num,name);
int i = db.insertRecords(t.getConnection(), emp);
if(i == 0)
System.out.println("Not inserted successfully");
else
System.out.println("Inserted Successfully");
break;
}
case 3:
{
UpdateMethod();
Stadium PUR = new PUR(num);
int i = db.updateRecord(t.getConnection(), PUR);
if(i == 0)
System.out.println("Not Updated Succesfully");
else
System.out.println("Congratulation your record is updated Successfully");
break;
}
case 4:
{
DeleteMethod();
Stadium PUR = new PUR(num,name);
int i = db.deleteRecord(t.getConnection(), PUR);
if(i == 0)
System.out.println("Not Deleted Succesfully");
else
System.out.println("Deleted Successfully");
break;
}
case 5:
{
System.exit(0);
}
default:
{
System.out.println("Your Choice is not from the given list..");
break;
}
}isAgain = askAgain();
}
catch(Exception e)
{
e.printStackTrace();
}
}while(isAgain);
}
}
public class Test {
public Connection getConnection() throws ClassNotFoundException, SQLException
{
String user = "root";
String pass = "";
String url = "jdbc:mysql://localhost/javapractices";
String conn = "com.mysql.jdbc.Driver";
Class.forName(conn);
Connection con= DriverManager.getConnection(url,user,pass);
/* end of connection */
return con;
}
public static void main(String args[]) throws SQLException, ClassNotFoundException
{
choices ch = new choices();
ch.choice();
}
}