Results 1 to 5 of 5
  1. #1
    pruton is offline Member
    Join Date
    Jun 2010
    Posts
    2
    Rep Power
    0

    Default how provide the method ?

    hi i have programming project were i need to - "design and implement class called Course That represent a course taken at a school. A course object should keep track of up to five student, as represented by the modifid Student class from the previous programming project in the book. The constructor of the Course class should accept only the name of the course. Provide a method called addstudent that accepts Student object parameter (the course object should keep track of many vaild students have been added to the course). provide a method calles test score average. Provide a method called roll that prints all students in the course. Create a driver class with a main method that creates a course, adds several students, prints a roll, and prints the overall course test average." now the question is about the method roll. 1) what they meen "print all students in the course" ? if i need to prin the names of the student so i do not have method in the student class that give me the name of the student. i can provide this method in the student class but i do not think that this what they meen.

  2. #2
    m00nchile is offline Senior Member
    Join Date
    Feb 2010
    Location
    Ljubljana, Slovenia
    Posts
    470
    Rep Power
    5

    Default

    This is exactely what they mean, it's good programming practice for all your classes to override certain methods, mainly the .equals() and .toString() methods. If you override the toString() method in your Student class, the roll call method in Course should be exceptionally easy to implement.
    Ever seen a dog chase its tail? Now that's an infinite loop.

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,544
    Rep Power
    23

    Default

    Another approach would be to add a method to get the name.
    I use the toString() method to output everything about a class that is useful for debugging.

  4. #4
    pruton is offline Member
    Join Date
    Jun 2010
    Posts
    2
    Rep Power
    0

    Default

    ok maybe you right so i already add in the Student class method "name" that return me the name of the student. but you also said that ""If you override the toString() method in your Student class, the roll call method in Course should be exceptionally easy to implement. and i already have toString method but that method return all the about the student like homeAddress, schoolAddress, average, test1, test2, test3, firstName, lastName. and i need only firstName and lastName because of this i decide to write new method name. can i use somehow the toString of the student class to get only the name of the student ?

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,544
    Rep Power
    23

    Default

    Why not have another method (they're cheap) that returns the information in the format that you want.

Similar Threads

  1. Replies: 8
    Last Post: 08-11-2009, 03:57 PM
  2. Replies: 3
    Last Post: 07-11-2009, 01:36 PM
  3. Please provide some help
    By saurabh_87 in forum New To Java
    Replies: 3
    Last Post: 04-23-2009, 08:38 AM
  4. can anybody please provide me the java tutorials
    By vislawath.jawaharlal in forum Threads and Synchronization
    Replies: 1
    Last Post: 04-07-2009, 03:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •