thiags

Greenhorn
+ Follow
since Jun 20, 2001
Merit badge: grant badges
For More
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 thiags

Hi all,
Is this constructor correct?
public class Person {
private String name, famName;
private Person mother, father;
private Date dateofBirth;
public Person(String name, String familyName, Person fa, Person mo, Date dob){
this.name = name;
this.famName = familyName;
this.father = fa;
this.mother = mo;
this.dateofBirth = dob;

}
}
22 years ago
Hi Mike
I found out that. I can not assign an array reference to
another array reference it should be actually
for (int i = 0 ; i < _marks.legth ; i++)
{
marks[i] = _marks[i]
}
Thi will ensure the copying of all elements to initialising array.
This is because arrays are pass by refernce in java.
thanks for your reply
22 years ago
Hi
I am trying to store a list of students with their marks into a
hash table. When i try to show the students list , my marks array is having only the last student data. Rest all lost.
Class Student{
private String name;
private int marks [];
public Student (String _name, String _matricNum, int _marks[])
{
name = _name;
matricNum = _matricNum;
marks = _marks;
}
public int[] getMarks(){
return marks;
}


}
Class clas{
private Hashtable studhash = new Hashtable();
public void registerStudent
(String name, String matricNum, int marks[]){

Student s = new Student (name, matricNum, marks);
studhash.put(s.getName(), s );
}
public void showStudents(){
Collection coll = studhash.values();
Iterator i = coll.iterator();
while (i.hasNext()){
Student s = (Student) i.next();
s.show();
int[] rmarks = s.getMarks();
for (int i = 0; i < rmarks.length; i++){
System.out.println("Mark" + i + " " + rmarks[i]);
}

}
}

}

Public class Main{
String name, matricNum;
Class clas = new Class();
int[] marks = new int[2];

while (cont = true) {
name = getLineFromConsole("Name:");
matricNum = getLineFromConsole("MatricNumber:");
marks[0] = Integer.parseInt(getLineFromConsole("Marks1"));
marks[1] = Integer.parseInt(getLineFromConsole("Marks2"));
clas.registerStudent(name,matricNum,marks);
}
clas.showStudents();

}
thanks in advance
22 years ago
Hi Mike,
Thank you very much.
I compiled successfuly.
Will try further.
regards
thiags
22 years ago
Hi
I like to know how to use arrays in constructors my code his here. this is error i know how what is the solution?
public Student (String name, String matricNum, int marks[]) {
this.name = name;
this.matricNum = matricNum;
this.marks [] = marks [];
}

------------------
22 years ago