• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Hashing Storage

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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);
}
}
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Enjoy the full beauty of the english language. Embedded in this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic