Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2012
    Posts
    1
    Rep Power
    0

    Default Dont know where to srart!

    Hi just wondering if someone could point me in the right direction. This isnt h/w im on summer break and tryin to get ahead befour next year but dont even know how to approach this question! The thing is i can do all the question up to the chapter befour this but am just gettin stuck. Many thanks sam

    The question is: Modify the Student class as follows. Each student object should also contain the scores for three tests. Provide a constructor that sets all instance values based on parameter values. Overload the constructor such that each test score is assumed to be initially zero. Provide a method called setTestScore that accepts two parameters: the test number (1 through 3) and the score. Also provide a method called getTestScore that accepts the test number and returns the appropriate score. Provide a method called average that computes and returns the average test score for this student. Modify the toString method such that the test scores and averages are included in the description of the student. Modify the driver class main method to exercise the new Student methods.

    1. I can see i need to first include the 3 test scores, but how do i do this so i can later identify them by test 1,2,3?
    2. Provide a constructor that sets all instance values based on parameter values. - i dont understand what this means?

    public class Student
    {
    private String firstName, lastName;
    private Address homeAddress, schoolAddress;

    //-----------------------------------------------------------------
    // Constructor: Sets up this student with the specified values.
    //-----------------------------------------------------------------
    public Student (String first, String last, Address home,
    Address school)
    {
    firstName = first;
    lastName = last;
    homeAddress = home;
    schoolAddress = school;
    }

    //-----------------------------------------------------------------
    // Returns a string description of this Student object.
    //-----------------------------------------------------------------
    public String toString()
    {
    String result;

    result = firstName + " " + lastName + "\n";
    result += "Home Address:\n" + homeAddress + "\n";
    result += "School Address:\n" + schoolAddress;

    return result;
    }
    }



    public class Address
    {
    private String streetAddress, city, state;
    private long zipCode;

    //-----------------------------------------------------------------
    // Constructor: Sets up this address with the specified data.
    //-----------------------------------------------------------------
    public Address (String street, String town, String st, long zip)
    {
    streetAddress = street;
    city = town;
    state = st;
    zipCode = zip;
    }

    //-----------------------------------------------------------------
    // Returns a description of this Address object.
    //-----------------------------------------------------------------
    public String toString()
    {
    String result;

    result = streetAddress + "\n";
    result += city + ", " + state + " " + zipCode;

    return result;
    }
    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,234
    Rep Power
    19

    Default Re: Dont know where to srart!

    Please go through the Forum Rules -- particularly the third paragraph.

    Also Guide For New Members and BB Code List - Java Programming Forum

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    awinston is offline Student
    Join Date
    Jul 2012
    Location
    United States
    Posts
    328
    Rep Power
    3

    Default Re: Dont know where to srart!

    For handling the test scores, you will probably want to use an array. If you don't know about arrays, learn here: Arrays (The Java™ Tutorials > Learning the Java Language > Language Basics)

    An array is basically a collection of data. Each piece of data resides within a certain index, and one simply has to request the index in order to retrieve the data that resides in the index.
    "Success is not final, failure is not fatal: it is the courage to continue that counts." - Winston Churchill

Similar Threads

  1. Dont know how to use .lastIndexOf
    By reddevilggg in forum New To Java
    Replies: 2
    Last Post: 09-28-2011, 04:23 PM
  2. Dont know what im doing wrong here
    By prendergast36 in forum New To Java
    Replies: 4
    Last Post: 09-09-2011, 09:57 PM
  3. Hello! and I need help. I dont know were to start
    By Fall0ut in forum New To Java
    Replies: 10
    Last Post: 05-19-2010, 06:26 PM
  4. Using libraries that others dont have(j3d)
    By scorpion9 in forum Advanced Java
    Replies: 7
    Last Post: 02-19-2010, 11:24 AM

Posting Permissions

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