Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How am I getting cannot find symbol error at line Hashes hashes = new Hashes(); Main.java package class; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import

How am I getting cannot find symbol error at line Hashes hashes = new Hashes();

Main.java

package class; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.security.NoSuchAlgorithmException; import java.util.HashMap; import java.util.Map;

public class Main { public static final int ARR_LENGTH = 20;

public static void main(String[] args) throws NoSuchAlgorithmException { // setup the hash map here String mainMan = "Mega Man"; String leadingLady = "Lucina"; Map hashedNamesHM = new HashMap<>();

Hashes hashes = new Hashes(); String filename = "names.txt";

String[] namesArr; namesArr = readNames(filename); //print out every element in the array for(int i = 0; i < namesArr.length; i++) { System.out.println(namesArr[i]); hashes.makeHash(namesArr[i]); hashedNamesHM.put(namesArr[i], hashes.getHashedStr()); } System.out.println(hashedNamesHM.toString());

// find your main man if (hashedNamesHM.containsKey(mainMan)) { System.out.println(mainMan+" = " + hashedNamesHM.get(mainMan)); } else { System.out.println("The HashMap does not contain "+mainMan); }

// find your leading lady if (hashedNamesHM.containsKey(leadingLady)) { System.out.println(leadingLady+" = " + hashedNamesHM.get(leadingLady)); } else { System.out.println("The HashMap does not contain "+leadingLady); } }

// read the names from names.txt and put them into an array public static String[] readNames(String filename) { String[] names = new String[ARR_LENGTH]; String currentLine = ""; int index = 0; try { BufferedReader br = new BufferedReader(new FileReader(filename)); String contentLine = br.readLine(); while (contentLine != null && index < ARR_LENGTH) { names[index++] = contentLine; contentLine = br.readLine(); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return names; } }

Hashes.java

package class; import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException;

public class Hashes { private String hashStr;

public void makeHash(String hashName) throws NoSuchAlgorithmException { MessageDigest md = MessageDigest.getInstance("MD5"); byte[] byteArr = md.digest(hashName.getBytes(StandardCharsets.UTF_8)); StringBuilder buildStr = new StringBuilder(); for (byte b : byteArr) { buildStr.append(String.format("%02x", b)); }

this.hashStr = buildStr.toString(); }

public String getHashedStr() { return this.hashStr; } }

Step by Step Solution

3.28 Rating (157 Votes )

There are 3 Steps involved in it

Step: 1

The error cannot find symbol typically means that the compiler cant find a declaration for the symbo... 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_2

Step: 3

blur-text-image_3

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

Cost management a strategic approach

Authors: Edward J. Blocher, David E. Stout, Gary Cokins

5th edition

73526940, 978-0073526942

More Books

Students also viewed these Programming questions

Question

What do you like to do in your spare time?

Answered: 1 week ago