Ok - I am really stuck on this. I have managed to create a Hashmap
that holds student names and will hold scores of coursework, and it
will finally give them a grade.
I now have to:
/**
* Asks the user to enter the marks for all the students for the given
tma.
* It should check that the tma number provided as the argument is
valid
* but it can assume that the marks entered by the user are valid.
*/
I am getting no where - error messages all the time. Can anybody
point me in the right direction.
Firstly my two classes are Student and TutorGroup. When I create a
new TutorGroup (using blueJ) - I can see attribute - students.
click
on students - it shows key (students name) - type java.util.map -
click on the student and I can see their respective details :
attribute (name) with its value"Billy"(type string) and attribute
(tma) with is value 0(int).
How do I use this line:
public void enterMarksForTMA(int tma)
to complete the above.
I have received no end of error messages. I have tried a keySet but
have only managed to get it to display Name[0,0]X instead of just
their name.
Any help is greatly appreciated.
Thanks.
Paul
On Feb 25, 12:14 pm, psm...@mcwy.com wrote:
> I am getting no where - error messages all the time. Can anybody
> point me in the right direction.
[quoted text clipped - 5 lines]
> attribute (name) with its value"Billy"(type string) and attribute
> (tma) with is value 0(int).
It's very difficult to tell exactly what you're trying to do here--
what do you mean by "click on the student"? Perhaps if you could
provide some source code of your methods I might be able to figure out
what you're doing wrong.
> I have received no end of error messages. I have tried a keySet but
> have only managed to get it to display Name[0,0]X instead of just
> their name.
Just a shot in the dark, are you using something to the effect of
"System.out.println(MyHashMap.keySet)"? The "keySet" field of the
HashMap is itself a set of keys, using this code will print out the
result of the "toString()" method of the HashMap's keySet field. To
print out each of the keys you'll need to something like the
following:
for (String s : MyHashMap.keySet) {
System.out.println(s);
}
Again, if you can provide some source code, I may be able to help a
bit more.
--
Daniel Cannon
psmith@mcwy.com - 26 Feb 2007 10:11 GMT
> On Feb 25, 12:14 pm, psm...@mcwy.com wrote:
>
[quoted text clipped - 34 lines]
> --
> Daniel Cannon
Hi,
Sorry what I meant by 'clicking on student etc...' - was when I was
inspecting the variables via BlueJ.
My method and code at the moment is:
/**
* Asks the user to enter the marks for all the students for the
given tma.
* It should check that the tma number provided as the argument is
valid
* but it can assume that the marks entered by the user are valid.
*/
public void enterMarksForTMA(int tma)
{
int tmaMark = tma;
if (tma <1 || tma > Student.NUMBER_OF_TMAS)
{
OUDialog.alert("Sorry that is not the correct TMA number");
}
else
{
//Set<String> name = students.keySet();
//for (String eachStudent: name)
//{
tmaMark = Integer.parseInt(OUDialog.request("Enter TMA " + tma
+ " mark for "));// + Student.getName());
OUDialog.alert("You scored " + tmaMark + " in your last
paper");
//tmaMark = Student.setMark(tma, tmaMark);
//}
}
When I used the keySet I was given the full details of the Student
instead of just their name. I have // where I need the students name
- I get error messages stating that it is a non-static method.
I also need to be able to record the tmaMark against the student,
again within the map, and again I am getting non-static method errors.
Any help, code/pushing in the right direction greatly appreciated.
Paul
psmith@mcwy.com - 26 Feb 2007 10:37 GMT
> On Feb 25, 12:14 pm, psm...@mcwy.com wrote:
>
[quoted text clipped - 34 lines]
> --
> Daniel Cannon
Hi,
Sorry what I meant by 'clicking on student etc...' - was when I was
inspecting the variables via BlueJ.
My method and code at the moment is:
/**
* Asks the user to enter the marks for all the students for the given
tma.
* It should check that the tma number provided as the argument is
valid
* but it can assume that the marks entered by the user are valid.
*/
public void enterMarksForTMA(int tma)
{
int tmaMark = tma;
if (tma <1 || tma > Student.NUMBER_OF_TMAS)
{
OUDialog.alert("Sorry that is not the correct TMA number");
}
else
{
for (String eachStudent: students.keySet()) - //GOT THIS
FROM YOUR MESSAGE ABOVE
//{
tmaMark = Integer.parseInt(OUDialog.request("Enter TMA " +
tma + " mark for " + eachStudent));
//tmaMark = Student.setMark(tma, tmaMark); //NOW STUCK HERE
//}
}
With your message above I was able to correctly generate the name for
each student. THANK YOU
So now how do I get it to register the entered tmaMark against the
student within the map? I am getting non-static method error
messages.
Any help, code/pushing in the right direction greatly appreciated.
Paul
Lew - 26 Feb 2007 12:45 GMT
> My method and code at the moment is:
>
[quoted text clipped - 26 lines]
>
> Any help, code/pushing in the right direction greatly appreciated.
<http://www.physci.org/codes/sscce.html>
- Lew
psmith@mcwy.com - 26 Feb 2007 15:47 GMT
> psm...@mcwy.com wrote:
> > My method and code at the moment is:
[quoted text clipped - 33 lines]
>
> - Show quoted text -
Ok,
Hooefully this will make it easier.
I have two classes: TutorGroup and Student.
In Student I have a method - public void setMark(int tma, int mark).
In TutorGroup I have another method - public void enterMarksForTMA(int
tma)
In the TutorGroup method I have a dialog box which requests you enter
the mark for the tma(argument).
Once entered this method needs to update the Student method - public
void setMark(int tma, int mark), which is within a Map set called
students, with the two numbers entered from the TutorGroup method.
I have put:
Student.setMark(int tma, int mark) = new setMark(tma,
tmaMark);
but get a class error message. Any ideas?
Lew - 26 Feb 2007 22:07 GMT
Lew wrote:
>> <http://www.physci.org/codes/sscce.html>
> Hooefully this will make it easier.
Nope. Still not an SSCCE.
> I have two classes: TutorGroup and Student.
>
[quoted text clipped - 8 lines]
> void setMark(int tma, int mark), which is within a Map set called
> students, with the two numbers entered from the TutorGroup method.
setMark() is "within" in what way? Is it a Map or a Set? What is the type of
'students'?
> I have put:
>
> Student.setMark(int tma, int mark) = new setMark(tma,
> tmaMark);
new setMark( blah, blah) is constructor syntax for a class called 'setMark'.
Do you have such a class?
> but get a class error message. Any ideas?
"a class error message" is rather vague. /Copy and paste/ the /exact/ message
so we can know /exactly/ what you are talking about.
You will get a compiler error if 'setMark' is not a class in your classpath.
Please read
<http://www.physci.org/codes/sscce.html>
- Lew
AmiDaniel - 26 Feb 2007 22:00 GMT
On Feb 26, 3:37 am, psm...@mcwy.com wrote:
> So now how do I get it to register the entered tmaMark against the
> student within the map? I am getting non-static method error
> messages.
Firstly, Student is, I presume, a class--not an individual instance of
the class. "setMark(int, int)" is a non-static method of this class,
meaning that the method is associated with instances of Student as
opposed to the class itself. The instances of your Student class are
likely stored as values in your HashMap. Following should, I believe,
do what you want:
for (String eachStudent : students.keySet()) {
try {
int tmaMark = Integer.parseInt(OUDialog.request("Enter TMA " +
tma +
" mark for " + eachStudent));
tmaMark = students.get(eachStudent).setMark(tma, tmaMark);
} catch (NumberFormatException e)
{ OUDialog.alert(e.toString()); }
}
This is presuming that "students" is a HashMap<String, Student>, and
that the Student class has a method "public int setMark(int, int)".
--
Daniel Cannon
psmith@mcwy.com - 27 Feb 2007 08:49 GMT
> On Feb 26, 3:37 am, psm...@mcwy.com wrote:
>
[quoted text clipped - 26 lines]
> --
> Daniel Cannon
Thanks Daniel - it's working as it should be - very much appreciated.
AmiDaniel - 28 Feb 2007 04:01 GMT
On Feb 27, 1:49 am, psm...@mcwy.com wrote:
> Thanks Daniel - it's working as it should be - very much appreciated.
Not a problem--glad I could help.
--
Daniel Cannon
On Feb 26, 12:14 am, psm...@mcwy.com wrote:
> Ok - I am really stuck on this. I have managed to create a Hashmap
> that holds student names and will hold scores of coursework, and it
[quoted text clipped - 35 lines]
>
> Paul
hi,
my sincere advice to you is to clear your fundamentals in Data
Structure in java ,especially in the Hash Map , there u will find the
complete comprehensive approach to use hash maps
u know this time we people gonna help you ..but to be a sole
programmer its your battle , your choice of tools and weapons (in
java).
thanks