RU beehive logo ITEC dept promo banner
ITEC 120
2012fall
dbraffitt
ibarland

homeinfolectslabsexamshws
tutor/PIsbreeze (snow day)
Object120 + its docsjava.lang docsjava.util docs

hw05
Modifying objects
Student gpas

due in class Oct.16 (Tue)

For this homework, modify the exercises for class Student (started in labs 6a, 6b, and 7a), so that it stores not the gpa (derived info), but rather a student's total number of (weighted) grade-points. (We discussed this in lab07b—Mutation, continued: considering data representation; hw05 time.)

(Start with whatever work you completed with your partner in lab, but if you weren't finished you must add to it yourself. If you don't have access to their work, you can just re-write it — once the concepts are understood, the mechanics of writing the class should be straightforward.)

Each function beside the constructor must include test cases, and also javadoc documentation (@param and @return tags as appropriate). Of course, the start of your file should include acknowledgements of everybody who contributed code.

In particular, your code must have:

You don't need to include other methods mentioned in the lab pages — e.g. onDeansRoll etc., but if you already have them, sure keep them there!

Your test cases can all be in one function, so that you can have a few local variables to store some Students, and re-use them for multiple tests.
Be careful, now that we are changing (mutating) objects over time: you can no longer swap the order of your test cases, w/o changing the expected (“desired”) results!

You can use assertEquals (from previous hw) for your test cases. To test that your void methods work, you have first call that mutating function, and then afterwards assert that the updated field really does have the desired value.

    // Note: this is what some of my examples/test cases looked like; yours
    // might be slightly different depending on how you declared your fields/constructor.

    Student stu1 = new Student( "Troy Ilium", "MATH", 30, 90 );

    setMajor( stu1, "ANTH" );
    assertEquals( stu1.major, "ANTH" );
  
Alternately, you could also assert that all the fields of stu1 look the way you expect them to (testing/checking that your method didn't change fields that should have stayed the same!): assertEquals( stu1, new Student("Troy Ilium", "ANTH", 30, 90) );. Note that if you want two students with entirely-equal-fields to be counted as equal, you need to be sure to extend Object120.


1

It's okay if your gpa prints with many decimal places.

If you really want to convert the double into a String obeying a certain format, You can use the static method format that lives inside class String. For example, in code pad try evaluating “String.format( "hello: %8.3f bye", 123.456789 )”. (The "3" means “3 places after the decimal”, the "8" means “8 characters wide total (padded with leading spaces)”, and the "f" means “floating-point or double”. See the docs (clicking the link on 'format string' for more info on that).

     

homeinfolectslabsexamshws
tutor/PIsbreeze (snow day)
Object120 + its docsjava.lang docsjava.util docs


©2012, Ian Barland, Radford University
Last modified 2012.Oct.11 (Thu)
Please mail any suggestions
(incl. typos, broken links)
to ibarlandradford.edu
Powered by PLT Scheme