Question: Please help I am writing a program in Java: I am reading a file from command line,which will have a name and an optional number

Please help

I am writing a program in Java:

I am reading a file from command line,which will have a name and an optional number on each line. Need to go through file line by line and hash each name to array.

tom 23

emily 232

sarah

I want to write a hash function that hashes the name to a specific index (maybe using ASCii values). If there is nothing in the array at that index, I want to add the name and associated number to that index in the array. If that name already exists report an error(name exists). If two different names hash to same index can use linear probing to find open index.

When reading the file, if the name has no number associated with it: hash to index using normal hash function. If that name already exists in iarray, report name and number associated with it already in that location. If it doesnt exist in index, report error(not found) .

import java.io.BufferedReader;

import java.io.File;

public class HashApp {

public static void main(String[] args) {

String file = args[0];

BufferedReader in = null;

String success = "no";

try {

in = new BufferedReader(new FileReader(file));

} catch (FileNotFoundException e1) {

e1.printStackTrace();

}

List fileStrings = new ArrayList();

String text = "";

try {

while ((text = in.readLine()) != null) {

fileStrings.add(text);

}

} catch (IOException e) {

e.printStackTrace();

}

try {

in.close();

} catch (IOException e) {

e.printStackTrace();

}

int p = fileSize(fileStrings.size());

System.out.println("");

String[] A = new String[p];

for (int z = 0; z < fileStrings.size(); z++) {

String str = fileStrings.get(z);

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!