0

I am trying to figure out how I can turn my 4 basic pseudocode methods inside of my perfect hash class into workable methods that will eventually be used inside of a main method of my PerfectHash class. I know I haven't created the instance of the class yet, but I will.

You know like when you call the 4 methods using a stack, for example, you input parameters inside the methods, but my application will be able to take the key that's entered by the user and insert, fetch, delete, or update on it inside of the structure.

Do I need to put more thought into these methods or is the pseudocode enough to work for now? Here's what I have done so far. I know the first class compiles fine, but I am having trouble with the second class as I have already indicated above.

public class PerfectHash
{

  private StadiumTickets[] data; 


  public boolean insert(StadiumTickets newStadiumTicket)
  {
      // the direct insert hashed algorithm 

       pseudoKey = preProcessing(targetKey); 
       ip = pseudoKey; // direct hashing function 

       // insert the new ticket
        data[ip] = newStadiumTicket.deepCopy(); 
  }

  public StadiumTickets fetch(String targetKey)
  {

    // the fetch algorithm 
    // access the primary storage area 

     pseudoKey = preprocessing(targetKey); 
     ip = pseudoKey; // direct hashing function 

    if(data[ip]== null)
     { 
         return null; 
     } 
     else
     {
        return data[ip].deepCopy(); 
     }
   } 

   public boolean delete(String targetKey)
   { 
      // the delete direct hashed algorithm 

      // access the primary storage area 

         pseudoKey = preprocessing(targetKey);

       ip = pseudoKey; // direct hashing function 

      if(data[ip]== null)
      { 
         return false; 
       } 
      else 
      { 
        data[ip]= null;                      
        return true; 
      }
    } 
    public boolean update(String targetKey, StadiumTickets newStadiumTicket)
    {
        // the update direct hashed algorithm 

       if(delete(targetKey) == false)
           return false; 
       else 
        {
           insert(newStadiumTicket) 
             return true;
         }
     }

}
import java.util.Scanner; 

public class StadiumTickets
{

     int ticketNumber; // keyfield

     String purchaserName; 


  public void input()
  {

     Scanner input= new Scanner(System.in);

      // key values ranges between 2000 to 100,000 


      System.out.print("Please enter a ticket number between 2000 to 100,000: "); 

      // a variable to hold the answer

       ticketNumber= input.nextInt(); 


        // error checking to make sure the user doesn't enter a key outside of the lower or upper ranges

       if(ticketNumber < 2000 && ticketNumber > 100000) 
        System.out.println("This number is not a valid entry to input into the structure.");
     }

  public StadiumTickets(int ticketNumber, String purchaserName)
  {

       this.ticketNumber= ticketNumber; 
       this.purchaserName= purchaserName; 
   } 



   public StadiumTickets deepCopy()
   { 

      StadiumTickets clone= new StadiumTickets(ticketNumber, purchaserName); 
       return clone; 
   }  
}
ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
JBonea
  • 1
  • 1
  • What's your question specifically? – luckydog32 Nov 02 '17 at 01:07
  • @luckydog32 How to turn my methods into workable code instead of pseudocode? – JBonea Nov 02 '17 at 01:12
  • Well that is still very broad. You should try to implement these methods yourself and come back when you get stuck on something specific that you can't figure out. – luckydog32 Nov 02 '17 at 01:15
  • @luckydog32 What I meant is that the methods function such as when a person enters a key, I should be able to insert into the structure, fetch from the structure, update from the strucuture, or delete the key from the structure. I should be to insert a key entered by a user into a index and perform the other operations as well. – JBonea Nov 02 '17 at 01:23

0 Answers0