I need help creating a small phone book application that uses hash table. This is for my school assignment. I'm very new to Java so I can't really get my head around this.
I have a basic layout of the code on how the application would function, i'm just lost on how to implement the hash table.
I'm not allowed to use the built in data structures in Java, so I have to build the hash table from scratch. I am, however, able to use the native hashCode() function for the hash table.
here is my code and some notes in it:
import java.util.Scanner;
public class PhoneBook {
public static void main(String[] args) {
boolean exitPhoneBook = false;
Scanner userInput = new Scanner(System.in);
while (exitPhoneBook == false) {
System.out.println("What do you want to do?");
System.out.println("1. Add a contact");
System.out.println("2. Show a contact");
System.out.println("3. Delete a contact");
System.out.println("4. Show all contacts");
System.out.println("5. Exit");
System.out.print("Select a number: ");
int action = userInput.nextInt();
switch (action){
case 1:
addContact();
break;
case 2:
showContact();
break;
case 3:
deleteContact();
break;
case 4:
showAll();
break;
case 5:
System.out.println("Goodbye!");
exitPhoneBook = true;
break;
default:
System.out.println("Invalid option.");
System.out.print("Select a number: ");
break;
}
}
}
static void addContact(){
//takes in four strings from user (first name, last name, phone number, email)
}
static void showContact(){
//takes in two strings from user (first name, last name)
}
static void deleteContact(){
//takes in two strings from user (first name, last name)
}
static void showAll(){
//prints out all the contact in the hash table
}
}