The class Person contains three instance variables: a String variable named “name”, a String variable named “gender”, and an int variable named “yearOfBirth”. The purpose of instance variables is to set values specific to individual objects. Two additional instance variables that are appropriate for the class Person are written as “private int heightMeters” and “private int weightGrams”.
−Phoenix
What would be the argument for not using integer data types in the two cases that you mention? Thank you.
ReplyDeleteFor my two instance variables, one can argue that “double” variables be used instead of “int” variables. This is because of the truncating effects of “int” values. For example, a height of 4.9 m would be reduced to 4 m because it’s measured as an integer. This does not occur with “double” values, which retain decimal points, thus giving a much more accurate measurement of these values.
ReplyDelete−Phoenix
Most excellent. Generally speaking:
ReplyDelete"how much?" - use a double
"how many?" - use an integer
40 XPs awarded for this completion.