JAVA your application will continually present the user with a menu to perform t
ID: 3808404 • Letter: J
Question
JAVA
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).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.
Explanation / Answer
package animat;
import java.util.Scanner;
public class aa {
static Scanner read=new Scanner(System.in);
static String[] hashtable=new String[1000000];
public static void main(String args[])
{int option=0;
System.out.println("1.insert, 2.fetch, 3.delete, 4.update, 5.output all, and 6.exit the program");
while(option!=6)
{
option=read.nextInt();
switch (option) {
case 1: insert();
break;
case 2: fecth();
break;
case 3: delete();
break;
case 4: update();
break;
case 5: outputall();
break;
case 6: System.out.println("thank u");
break;
default: System.out.println( "Invalid option");
break;
}
System.out.println("what option would you choose??");
}
}
private static void outputall() {
// TODO Auto-generated method stub
for(int i=0;i<hashtable.length;i++)
{
if(hashtable[i]!=null)
{
System.out.println("ticket no :"+i+" purchaser :"+hashtable[i]);
}
}
}
private static void update() {
// TODO Auto-generated method stub
System.out.println("enter ticket no to update");
int index=read.nextInt();
if(validateindex(index))
{
System.out.println("enter purchaser name");
String purchaser =read.next();
hashtable[index]=purchaser;
}
else
{
System.out.println("no such ticket");
}
}
private static void delete() {
// TODO Auto-generated method stub
System.out.println("enter ticket no to delete");
int index=read.nextInt();
if(validateindex(index))
{
hashtable[index]=null;
}
else
{
System.out.println("no such ticket");
}
}
private static void fecth() {
// TODO Auto-generated method stub
System.out.println("enter ticket no to fetch");
int index=read.nextInt();
if(hashtable[index]==null)
{
System.out.println("no such ticket");
}
else
{
System.out.println(hashtable[index]);
}
}
private static void insert() {
// TODO Auto-generated method stub
System.out.println("enter ticket no to inset");
int index=read.nextInt();
if(validateindex(index))
{
System.out.println("enter purchaser name");
String purchaser =read.next();
hashtable[index]=purchaser;
}
else
{
System.out.println("no such ticket");
}
}
private static boolean validateindex(int index)
{
if(index<2000||index>1000000)
{
return false;
}
return true;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.