Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7771573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:41:07+00:00 2026-06-01T16:41:07+00:00

another question to put out there. I was working on an assignment to create

  • 0

another question to put out there. I was working on an assignment to create hash functions and all that jazz, and i have stumbled across a small problem.

Line 35:21, where it reads arrpos += prearrpo & ______,

in my head works… What im trying to do is access arr.length from the HashTable() method. I’ve read around, suggestions with needing to creat an object of size arr.length; however in my mind, this seems overly complicated-

Is there another way i can access the variable in the HashTable method, but inside the insert method?

Another not so important question involves the giant block of if() statements in the letter(char c) class; im certain there must be a shorter way of doing this… I would have initially used the ascii values; but the specifications were quite particular about using the values 1-26 for lower/upper case letters-

Thanks

import java.io.*;

public class HashTable {

    public HashTable() {
        //Create an array of size 101
        String arr[] = new String[101];
        //System.out.println("Size1: ");
    }

    public HashTable(int tsize) {
        int size = 2 * tsize;
        //System.out.println("Size: " + size);
        boolean isPrime = checkPrime(size);
        //System.out.println("IsPrime: " + isPrime);
        while (isPrime == false) {
            //System.out.println("Size: " + size);
            size++;
            isPrime = checkPrime(size);
        }
        //System.out.println("Size: " + size);
        String arr[] = new String[size];
    }

    public boolean insert(String line) {

        String str = line;
        char[] ch = str.toCharArray();
        int slen = str.length();
        int arrpos = 0;
        int hash = slen;
        for (int i = 0; i < slen; i++) {
            double prearrpo = letter(ch[i]) * Math.pow(32, (hash - 1));
            arrpos += prearrpo % arr.length();
            hash--;

        }
        System.out.println(arrpos);
        System.out.println("array size:");
        System.out.println();
        return false;

    }

    private int letter(char c) {
        char ch = c;
        if (ch == 'A' || ch == 'a') {
            return 1;
        }
        if (ch == 'B' || ch == 'b') {
            return 2;
        }
        if (ch == 'C' || ch == 'c') {
            return 3;
        }
        if (ch == 'D' || ch == 'd') {
            return 4;
        }
        if (ch == 'E' || ch == 'e') {
            return 5;
        }
        if (ch == 'F' || ch == 'f') {
            return 6;
        }
        if (ch == 'G' || ch == 'g') {
            return 7;
        }
        if (ch == 'H' || ch == 'h') {
            return 8;
        }
        if (ch == 'I' || ch == 'i') {
            return 9;
        }
        if (ch == 'J' || ch == 'j') {
            return 10;
        }
        if (ch == 'K' || ch == 'k') {
            return 11;
        }
        if (ch == 'L' || ch == 'l') {
            return 12;
        }
        if (ch == 'M' || ch == 'm') {
            return 13;
        }
        if (ch == 'N' || ch == 'n') {
            return 14;
        }
        if (ch == 'O' || ch == 'o') {
            return 15;
        }
        if (ch == 'P' || ch == 'p') {
            return 16;
        }
        if (ch == 'Q' || ch == 'q') {
            return 17;
        }
        if (ch == 'R' || ch == 'r') {
            return 18;
        }
        if (ch == 'S' || ch == 's') {
            return 19;
        }
        if (ch == 'T' || ch == 't') {
            return 20;
        }
        if (ch == 'U' || ch == 'u') {
            return 21;
        }
        if (ch == 'V' || ch == 'v') {
            return 22;
        }
        if (ch == 'W' || ch == 'w') {
            return 23;
        }
        if (ch == 'X' || ch == 'x') {
            return 24;
        }
        if (ch == 'Y' || ch == 'y') {
            return 25;
        }
        if (ch == 'Z' || ch == 'z') {
            return 26;
        }
        return 0;
    }

    public boolean lookUp(String string) {
        // 
        return false;
    }

    public String getNum() {
        // 
        return null;
    }

    public int length() {

        return 0;
    }

    private static boolean checkPrime(int size) {

        if (size % 2 == 0) {
            return false;
        }
        double c = Math.sqrt(size);
        for (int i = 3; i < c; i += 2) {
            if (size % i == 0) {
                return false;
            }
        }



        return true;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T16:41:08+00:00Added an answer on June 1, 2026 at 4:41 pm

    public HashTable() is a constructor. Your arr[] should actually be a private member of your class and you should initialize it in all constructors or make sure you never access without intializing it.

    public class HashTable {
    
        private String[] arr;
    
        public HashTable() 
        {
            //Create an array of size 101
            arr[] = new String[101];
            System.out.println("Size1: ");
        }
    etc...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have read through all the threads out there that looked as if they
Another question related to this one . I have a List<SortableObjects> that is the
In another question , a user pointed out that the new keyword was dangerous
I am working on an assignment with polymorphism and have followed online tutorials that
I have another question that's connected with my class: public class Parent { public
I have asked another question related to this in this thread Where to put
Another clipboard question: When text is put onto the clipboard, it frequently goes in
I asked this question in another post - How do I put a <div>
I feel my question is pretty dumb, or another way to put it is
Sorry to post another question that is similar to the question that I posted

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.