Any1 wanna help me with some java?

Discussion in 'OT Technology' started by Auspicious one, Nov 19, 2006.

  1. Auspicious one

    Auspicious one New Member

    Joined:
    Aug 14, 2005
    Messages:
    15,271
    Likes Received:
    1
    Location:
    Denver
    For this assignment you will write one main class, Grader.java,
    and two subsidiary classes, Student.java and Address.java.

    In a sense the Address class is subsidiary to both of the other classes,
    so the hierarchy could be diagrammed as

    Grader class
    Student class
    Address class



    The Address class
    -----------------

    For the Address class, the instance variables are

    private int number;
    private String street;

    These represent the house number and street name of a street address.

    This class must have
    a constructor,

    a .equals method for Address objects, which could begin
    public boolean equals(Address addr)

    and a .toString method that returns a String of the form
    "123 Maple" if the number is 123 (an int)
    and the street name is "Maple" (a String).
    This method, like all toString methods, must _not_ print anything!



    The Student class
    -----------------

    This class has instance variables

    private String lastName; // Student's last name
    private String firstName; // Student's first name
    private int academicYear; // Academic year (1 to 4)
    private double totalPoints; // Total points the student earned
    // (0 to 100)
    private Address homeAddress; // Home address of the student
    private Address schoolAddress; // School address

    private char letterGrade; // The student's current letter grade


    This class will also need a DecimalFormat object
    to format the totalPoints with one decimal point in the toString method.
    This DecimalFormat object should, as explained in lecture,
    be declared at class level, just after the instance variables,
    and should be both private and static:
    private static DecimalFormat oneDecPl = new DecimalFormat( ...

    It will be necessary to import java.text.* for this class.


    This class will of course need a constructor,
    which could begin

    public Student(String lastName, String firstName,
    int academicYear, double totalPoints,
    Address homeAddress, Address schoolAddress)
    {
    // Copy the values of the formal parameters into the instance variables.
    ...
    // Invoke calcGrade to compute the letter grade from totalPoints,
    // and store the result into letterGrade.
    ...
    }


    Note that the letterGrade is _not_
    a formal parameter of the constructor.
    It will be computed from the value of totalPoints
    by a private static method that could begin

    // Private "helper" method to compute the letter grade
    // given the value of the totalPoints
    private static char calcGrade(double totalPoints)
    {
    ... ["if" structure]
    }


    The grade is
    'A' if totalPoints is >= 90.0,
    'B' if totalPoints is >= 80.0,
    'C' if totalPoints is >= 70.0,
    'D' if totalPoints is >= 60.0, and
    'F' if totalPoints is < 60.0.

    If totalPoints is <0.0 or >100.0,
    calcGrade should print an error message
    and then invoke System.exit(0) to terminate the program.

    The constructor will call (invoke) method calcGrade
    to compute the letter grade, which the constructor
    will then store into the instance variable letterGrade.


    Additional methods that are required include

    // Accessor method for letterGrade
    public char getLetterGrade()
    {
    ...
    }


    // Mutator method for totalPoints
    // (and, therefore, for letterGrade)
    public void setTotalPoints(double totalPoints)
    {
    // Copy the value of the formal parameter
    // into the instance variable.
    ...
    // Recompute the letter grade by invoking calcGrade,
    // sending it the new value of totalPoints.
    ...
    }


    // .equals method for Student objects
    // For two Student objects to be equal, their values of
    // lastName, firstName, academicYear, totalPoints,
    // homeAddress, schoolAddress, and letterGrade must all be the same.
    // This method must invoke the .equals method in the Address class
    // in order to compare the two home addresses,
    // and to compare the two school addresses.
    public boolean equals(Student stu)
    {
    ...
    }


    // A method to reset the school address of the invoking object
    // to the school address of the formal parameter.
    public void movesInWith(Student stu)
    {
    ...
    }


    // toString method for Student objects
    // This method must invoke the toString method in the Address class
    // for each of the two Address objects,
    // homeAddress and schoolAddress.
    // This method must use a DecimalFormat object
    // with one decimal place to format the value of totalPoints.
    // This method must _not_ print anything!
    public String toString()
    {
    ...
    }



    The Grader class
    ----------------

    This main class should

    1) Declare all primitive variables and objects.

    Objects will include at least

    String lastName; // Student's last name
    String firstName; // Student's first name
    String homeStreet; // Street name of home address
    String schoolStreet; // Street name of school address

    Address
    homeAddress, // The home address of the student
    schoolAddress; // The school address of the student

    Student
    student1, // Student #1
    student2; // Student #2

    Scanner scan = new Scanner(System.in);


    Primitive variables will include at least

    int academicYear; // Academic year (1 to 4)
    int homeNumber; // House number of home address
    int schoolNumber; // House number of school address
    double totalPoints; // Total points the student earned (100 max)
    char letterGrade; // Student's letter grade


    2) Read in the
    last name (using scan.next()),
    first name,
    academic year (using scan.nextInt()),
    total points (using ...),
    home address house number,
    home address street name,
    school address house number, and
    school address street name
    for the student1 object.

    Instantiate the homeAddress object as a "new Address" object.
    Instantiate the schoolAddress object.

    Instantiate the student1 object as a "new Student" object.

    Print out the student1 object.


    3) Read, instantiate, and print the student2 object similarly.


    4) Test whether or not student1 and student2 are equal objects
    by invoking the .equals method in the Student class.
    Print an appropriate message, as shown in the Sample Output below.


    5) Read in a new value of the total points for student1.
    Invoke the method setTotalPoints
    to reset the value of totalPoints for student1,
    and simultaneously to recompute the letter grade.
    Print an appropriate message, as shown below.
    Use a DecimalFormat object with one decimal place
    to print the value of totalPoints.


    6) Invoke the movesInWith method to reset the school address
    for student1 so that it will now be equal to the school address
    for student2.
    Print an appropriate message, as shown below.


    7) Print out the student1 and student2 objects again.


    Hint:
    As discussed in class, it is probably a good idea
    to compile the Address class first and get rid of
    all of the syntax errors for that class.
    Then compile the Student class and get rid of
    all of its syntax errors.
    Then compile the Grader class and debug it.
    This way you will only have to worry about
    compilation error messages for one class at a time.

    The names of the instance variables and formal parameters
    that are used above are only suggestions;
    you may use any meaningful names.
    The names of the methods, however,
    must be exactly the same as above!

    You may declare and use any local variables
    that you find convenient.

    This program does not use a debug print switch.
    We anticipate that all remaining programs
    _will_ use a debug switch.



    Sample Input:
    Smith Don 2 86.5 234 Maple 802 Duck
    Wheeler Ron 3 97.2 123 Elm 522 McElroy
    90.4

    Sample output :
    Grade report for Smith, Don
    Academic Year : 2
    Total Points : 86.5
    Home Address : 234 Maple
    School address: 802 Duck
    Letter grade : B

    Grade report for Wheeler, Ron
    Academic Year : 3
    Total Points : 97.2
    Home Address : 123 Elm
    School address: 522 McElroy
    Letter grade : A


    student1 is not equal to student2.


    totalPoints for student1 has been reset to 90.4 .
    This has caused the letter grade to be recomputed as: A


    student 1 has moved in with student2.

    Grade report for Smith, Don
    Academic Year : 2
    Total Points : 90.4
    Home Address : 234 Maple
    School address: 522 McElroy
    Letter grade : A

    Grade report for Wheeler, Ron
    Academic Year : 3
    Total Points : 97.2
    Home Address : 123 Elm
    School address: 522 McElroy
    Letter grade : A


     
  2. RubiconSahara

    RubiconSahara OT Supporter

    Joined:
    Mar 30, 2000
    Messages:
    7,672
    Likes Received:
    0
    Location:
    Edmond, OK
  3. Auspicious one

    Auspicious one New Member

    Joined:
    Aug 14, 2005
    Messages:
    15,271
    Likes Received:
    1
    Location:
    Denver
  4. Auspicious one

    Auspicious one New Member

    Joined:
    Aug 14, 2005
    Messages:
    15,271
    Likes Received:
    1
    Location:
    Denver
    any1 wanna point me in the right direction
     
  5. Penguin Man

    Penguin Man Protect Your Digital Liberties

    Joined:
    Apr 27, 2002
    Messages:
    21,696
    Likes Received:
    0
    Location:
    Edmonton, AB
    It would help if you said what you're having trouble with. No one's going to do it for you.
     
  6. Auspicious one

    Auspicious one New Member

    Joined:
    Aug 14, 2005
    Messages:
    15,271
    Likes Received:
    1
    Location:
    Denver
    if you could get me started wtih the student class they would help tremendously
     
  7. StevesVR4

    StevesVR4 Get Arrested

    Joined:
    Jul 1, 2003
    Messages:
    7,328
    Likes Received:
    0
    Have you finished the Address class? You will need that before you start on the Student class. Plus, the assignment already has hints in it to help you with the Student class. What are you having problems with?
     
  8. RyanL

    RyanL OT Supporter

    Joined:
    Nov 30, 2004
    Messages:
    4,584
    Likes Received:
    0
    Location:
    St. Paul, MN
    all you did was copy and paste the assignment, the font is the same even.

    no one is going to do your homework
     
  9. Auspicious one

    Auspicious one New Member

    Joined:
    Aug 14, 2005
    Messages:
    15,271
    Likes Received:
    1
    Location:
    Denver
    wasnt expecting it to get done
     
  10. Auspicious one

    Auspicious one New Member

    Joined:
    Aug 14, 2005
    Messages:
    15,271
    Likes Received:
    1
    Location:
    Denver
    this helps thanks! :)
     
  11. Auspicious one

    Auspicious one New Member

    Joined:
    Aug 14, 2005
    Messages:
    15,271
    Likes Received:
    1
    Location:
    Denver
    what does the boolean statement in the address class compare?
     
  12. GOGZILLA

    GOGZILLA Double-Uranium Member

    Joined:
    Jan 16, 2003
    Messages:
    10,760
    Likes Received:
    3
    Location:
    Plantation, FL
    drop the class, like the actual school course, withdraw
     
  13. Auspicious one

    Auspicious one New Member

    Joined:
    Aug 14, 2005
    Messages:
    15,271
    Likes Received:
    1
    Location:
    Denver
    yes i know that :ugh2:
     
  14. StevesVR4

    StevesVR4 Get Arrested

    Joined:
    Jul 1, 2003
    Messages:
    7,328
    Likes Received:
    0
    You really need to talk to your professor about this assignment and the class in particular. You are asking a very simple question and you apparently haven't learned anything in class.
     

Share This Page