manutd wrote: » Need help, am trying to understand constructors in java. Create a class called MyClass; students this should also be private. The class should have a constructor that initializes the variable students; it should also have methods to access and reset the value of the students variable, and a method to print the entire class/the array of students. It should also have a method that allows you to find a student by name.
Anesthetize wrote: » Is it that time of the year again?
public class MyClass { private int nostudents; private Student [] students; public MyClass (Student [] ss){ students = ss; nostudents = ss.length; } public void printMe (){ System.out.println("Enter student name: "+ nostudents); for(int i=0; i<students.length;i++) { System.out.print(students[i].getAge() + "\t"); System.out.println(students[i].getName()); } } public void searchMe(){ ??????????????? } }
Anesthetize wrote: » For the search method you will be passing in a students name. You will need to figure out how to check if a Student with that name exists in the students array, and how to return that Student.
manutd wrote: » Do i need to get a user input for a student name to search for or input name into the code. I have the search function working and returning if a student exists or not. Also to access and reset the value of the students variable is this using getters and setters
henryporter wrote: » Amazing how these lecturers persist in asking students to do assignments without giving them any grounding in the basics. I guess they are of the opinion that the student will go off and research it themselves (which in a way asking on boards is :-) Check out the new boston on YouTube - he'll explain it all to you OP
BrokenArrows wrote: » Im sure the basics are explained but the students either were not in the class, missed it, or didnt understand it. Lecturers/Tutors cant be expected to hand feed pupils and explain it multiple times to everyone in the class. Students need to learn this stuff on their own time to fill in the gaps and reinforce their knowledge. Just like if someone was studying Law the student is not expected to learn everything about law just from the lecturers, they need to study in their own time.
henryporter wrote: » I would have thought explaining what a constructor is falls within the realm of basics that should be conveyed to the students by the lecturer. It's not like a point of law buried deep in some historic case that students should rightly have to investigate by themselves. What you're suggesting is that lecturers should tell the students to find a book on Java, figure it all out by themselves and then come back next May to do an exam on it, without making a nuisance of themselves by asking the lecturers to do their jobs properly.
manutd wrote: » How do you access and reset the value of the students variable, is it by using getters and setters.
class testClass{ private noOfStudents; public void resetNoOfStudents(){ noOfStudents = 0; } public int getNoOfStudents(){ return noOfStudents; } }
BrokenArrows wrote: » No, im suggesting that the lecturer should explain this to the students. But if the student just isnt grasping the concept then they need to learn it on their own time. The lecturer cannot become a 1 to 1 tutor for each student. 3rd level education assumes the person is mature enough to grasp concepts quickly or spend further time learning what they didnt understand in classes.
3rd level education assumes the person is mature enough to grasp concepts quickly or spend further time learning what they didnt understand in classes.
Buford T Justice wrote: » If I might interject here........ Currently in Y2 for programming and the amount of spoon feeding that is going on is ridiculous. We're nearly 6 weeks into Semester 3 and a lot of the kids are still struggling with basic concepts that were covered in Semester 2, or even 1!!!! Instead of moving forward with the course we still do revision on a lot of stuff...... Mainly because there no one bothers to do any work outside of class - at all. Its no surprise they haven't a clue really. They don't bother. they just sit there like mutes saying nothing generally - if they turn up for class
Buford T Justice wrote: » Sort of.....class testClass{ private noOfStudents; public void resetNoOfStudents(){ noOfStudents = 0; } public int getNoOfStudents(){ return noOfStudents; } }
Anesthetize wrote: » I highly doubt that's what he means by reset. It doesn't make sense why you would just reset the number of students back to 0. I'm sure it's just a simple setter method to set noOfStudents to a new value.
Buford T Justice wrote: » what does reset mean to you?
public class MyClass { private Student[] students; public MyClass(Student [] ss){ students = ss; } public Student[] getStudents() { return students; } public void setStudents(Student[] ss) { students = ss; } public int getNumberOfStudents() { return students.length; } public void printMe(){ System.out.println("Enterent name: " + nostudents); for (int i = 0; i < students.length; i++) { System.out.print(students[i].getAge() + "\t"); System.out.println(students[i].getName()); } } public void searchMe(){ // search code } ... }
manutd wrote: » I have got the following codepublic class MyClass { private int nostudents; private Student [] students; public MyClass (Student [] ss){ students = ss; nostudents = ss.length; } public void printMe (){ System.out.println("Enter student name: "+ nostudents); for(int i=0; i<students.length;i++) { System.out.print(students[i].getAge() + "\t"); System.out.println(students[i].getName()); } } public void searchMe(){ ??????????????? } } How do i go about the method that allows you to find a student by name. I also have the tester class working to test the above functions. Not looking for people to post the code, but pointers.