Alan Arkwell

Greenhorn
+ Follow
since Apr 21, 2005
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Alan Arkwell

Thanks Hentay.Sorry If I'm repeating myself,and I can't deny I'm having some problems with this,but please remember that maybe even you were a novice once.
14 years ago
I'm trying to call the calcHash method to get a hash index but I am getting the cannot resolve symbol error message(not recognising calcHash).I am a bit stumped.


class Student
{
String name;
String course;
int hashIndex;
public Student(String name,String course)
{

this.name =name;
this.course =course;

}

public String getName()

{

return name;
}

public String getCourse()

{
return course;

}

public int calcHash(int maxNum)

{
int hashTotal = 0;
int hashIndex = 0;
for(int i = 0; i<name.length();i++)
{

char letter = name.charAt(i);
int asciiValue = letter;
hashTotal = hashTotal + asciiValue;
hashIndex = hashTotal % maxNum;
}

return hashIndex;
}
}
class Storage
{

int maxNum = 4;
Storage StArray[] = new Storage[4];
public void add(int hashIndex,String name)
{
for(hashIndex=0;hashIndex<maxNum;hashIndex++)
StArray[hashIndex]=calcHash(maxNum);
}
}
14 years ago
I'll sort the tabs out eventually by the way
Alan
14 years ago
Tried using a Student object instead.Doesn't seem to work
Error is:
Student(java.lang.String.jav.lang.String)in Student cannot be applied to()
Student stud = new Student();
^
class Storage
{

int maxNum = 4;
Student stud = new Student();
Storage StArray[] = new Storage[4];
public void getHash(String name[])
{

for(int hashIndex=0;hashIndex<maxNum;hashIndex++)
StArray[hashIndex]=stud.calcHash(maxNum);

}
}
14 years ago
Yes I see that now....sorry about the tags!!
14 years ago
Sorry here is the main method.

import javax.swing.JOptionPane;
public class MainProg
{
public static void main(String[] args)
{

String[] name = new String[4];
String[] course = new String[4];
int lp = 0;
int maxNum = 4;
System.out.println("Name\t\t\tCourse");

for(lp=0;lp<name.length;lp++)
{

name[lp] = JOptionPane.showInputDialog("Enter name");
}

for(lp=0;lp<course.length;lp++)
{

course[lp] = JOptionPane.showInputDialog("Enter course");

}
for(lp=0;lp<4;lp++)
{
System.out.println(name[lp]+"\t\t"+course[lp]);

}

System.exit(0);
}


}
14 years ago
Hi
I am trying to call a method from a Student class that calculates a hash code for a Storage class.I am getting a cannot resolve symbol error in the Storage class and can see nothing wrong with the line.It's probably something minor but I need another set of eyes.
Cheers.
The code:

public class Student
{
String name;
String course;
int hashIndex;
public Student(String name,String course)
{

this.name = name;
this.course = course;

}

public String getName()

{

return name;
}

public String getCourse()

{
return course;

}

public int calcHash(int maxNum)

{
int hashTotal = 0;
int hashIndex = 0;
for(int i = 0; i<name.length();i++)
{

char letter = name.charAt(i);
int asciiValue = letter;
hashTotal = hashTotal + asciiValue;
hashIndex = hashTotal % maxNum;
}

return hashIndex;
}
}
public class Storage
{

int maxNum = 4;
Storage Store = new Storage();
Storage StArray[] = new Storage[4];
public void getHash(String name[])
{
for(int hashIndex=0;hashIndex<maxNum;hashIndex++)
StArray[hashIndex]=Store.calcHash(maxNum);

}
}
I am getting the error;:
Storage.java:10:cannot resolve symbol
symbol :method calcHash (int)
location:class Storage
StArray[hashIndex]=Store.calcHash(maxNum);
14 years ago
I am new to multi-dimensional arrays and I am trying to create one that accepts a user input (name and home town).I am thinking that a MD array would store the two inputs alongside each other.Here is my code:
import javax.swing.JOptionPane;
public class AlansProg
{
public static void main(String[]args)
{

String Info[][] = new String[4][2];
for(int row=0;row<4;row++)
{

Info[row] = JOptionPane.showInputDialog("enter name");

}

for(int col=0;col<2;col++)

{

Info[col] = JOptionPane.showInputDialog("enter Home Town");

}

}
}
I am getting this error message :
incompatible types
found:java.lang.string
required:java.lang.String[]
Info[row] = JOptionPane.showInputDialog("enter name");
^
Am I right to think this can be done,or do I need to create seperate arrays?
Cheers...Alan.
14 years ago
Jeff,you say if you need to use an array.Is there a better way of storing the info?
14 years ago
In an assignment I have been asked to accept a user input for student name and student course using JOptionPane.showInputDialog("enter name");
JOptionPane.showInputDialog("enter course");
I need 24 names and courses....My question is can I store both name and course in the same array? If so how do I do it?

Alan.
14 years ago