Get your CodeRanch badge!*
The moose likes Beginning Java and the fly likes Hashing Storage Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Hashing Storage" Watch "Hashing Storage" New topic
Author

Hashing Storage

Iain Palmer
Ranch Hand

Joined: Jul 28, 2004
Posts: 56
I'm writing a program to get a user to enter their name, and course. I then change the users name to uppercase and get its hashvalue(done that bit).But I have to write another class to store the hashTotal, I've made everything public so far but evrytime I compile the test program it says
C:\Program Files\Xinox Software\JCreatorV3LE\MyProjects\CourseWork\src\Test.java:12: cannot resolve symbol
symbol : method studentHashList (int)
location: class Student
s.studentHashList(hashTotal);

Here are the Programs
The Student One First
package HashingProblem;
import javax.swing.JOptionPane;
public class Student
{
public String firstName;
public String surname;
public String name;
public String studentName;
public String studentName1;
public String course;

public int hashTotal;
public int hashValue;
public int asciiValue;

public char letter;

public Student(String name,String course)
{
this.name = name;
this.course = course;
}
public void calculateHash(int nameLength)
{
studentName = (name.toUpperCase());
System.out.println(studentName);
System.out.println(studentName);
if( studentName != null && studentName.length() > 0)
{
for (int i = 0 ;i<studentName.length();i++)
{
letter = studentName.charAt( i ); //get the character from String
asciiValue = letter; //get the ASCII value of the character
hashTotal = hashTotal + asciiValue;
hashValue = hashTotal % studentName.length();
}
System.out.print("The name ;"+ name);
System.out.println("has a hash total is :"+hashTotal);
System.out.println("The hasn value is :"+hashValue);
System.out.println("Student Name is :"+name+" the course they are on is :"+course);

}
}
public String returnName()
{
return name;
}
public String returnCourse()
{
return course;
}
}

the Storage One

package HashingProblem;
import java.util.*;
class Storage
{
int studentList;
int hashTotal;
String name;

Vector studentHashBin = new Vector();
//a constructor to accept the size of the Student object array
public Storage(int studentList)
{
this.studentList = studentList;
}

/* method to add a Student to the Student object array which uses
* the method from the Student object to get the hash index
*/
public void studentHashList(int hashTotal)
{
System.out.println(name+hashTotal);
}

//a method to return the size of the Student object array

//method to output contents of Student array to command line
}

And The Test Program

import javax.swing.JOptionPane;
class Test
{
public static void main(String [] args)
{
int hashTotal;
String name = JOptionPane.showInputDialog("Enter your first Name");
String course = JOptionPane.showInputDialog("Enter your course");
Student s = new Student(name,course);
int nameLength = name.length();
s.calculateHash(nameLength);
s.studentHashList(hashTotal);
System.exit(0);
}
}
Jonas Isberg
Ranch Hand

Joined: Mar 18, 2003
Posts: 118
Originally posted by Iain Palmer:
C:\Program Files\Xinox Software\JCreatorV3LE\MyProjects\CourseWork\src\Test.java:12: cannot resolve symbol
symbol : method studentHashList (int)
location: class Student
s.studentHashList(hashTotal);

package HashingProblem;
import javax.swing.JOptionPane;
public class Student
{
// No studentHashList here what I can see... <-------------------
}
package HashingProblem;
import java.util.*;
class Storage
public void studentHashList(int hashTotal) // <--- Here it is!?
{
System.out.println(name+hashTotal);
}
}

import javax.swing.JOptionPane;
class Test
{
public static void main(String [] args)
{
int hashTotal;
String name = JOptionPane.showInputDialog("Enter your first Name");
String course = JOptionPane.showInputDialog("Enter your course");
Student s = new Student(name,course);
int nameLength = name.length();
s.calculateHash(nameLength);
s.studentHashList(hashTotal); // <--- Error because method id defined in class Storage but called on a student object
System.exit(0);
}
}
Iain Palmer
Ranch Hand

Joined: Jul 28, 2004
Posts: 56
sorry i got the wrong information about the program and went off on a different route i actually need to set up an array of students in the storage class and pass each student to the student class for hashing.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hashing Storage
 
Similar Threads
Hashing Index
hashing problem
JOptionPane and ArraySize not known
Hashing Problem
calling a method