Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

C++ Database Development

Authors: Al Stevens

1st Edition

1558283579, 978-1558283572

More Books

Students also viewed these Databases questions

Question

1. Design an effective socialization program for employees.

Answered: 1 week ago