Thursday, October 27, 2011

Challenge 025

An instance variable is defined in a class in which each object has their own separate copy. All instances are within a constructor function and can be assigned a unique value without modifying the values of other copies of the instance variable.

In this class, there are three instance variables. These three specific instance variables are name, gender, and yearOfBirth. Each of these instance variables contain a copy value.

Two addition instance variables for this code could be weight and shoe size.
The code for these are as follows:

public class Person
{

private String name;
private String gender;
private int yearOfBirth;
private int weight;
private int shoeSize;


public Person()
{
name = "unknown";
gender = "other";
yearOfBirth =0;
weight = 0;
shoeSize = 0;
}

public Person(String n, String g, int year, int weight, int shoeSize)
{
name = n;
gender = g;
yearOfBirth = year;
weight = pounds;
shoeSize = inches;

}


//BOOM!

3 comments:

  1. Hi Ryan, solid work being done here. Very close.

    I would like you to consider, "All instances are within a constructor function and can be assigned a unique value without modifying the values of other copies of the instance variable."

    The terminology being thrown around is this statement is a bit awkward from a technical aspect. Instances are not "within" constructors, for instance. Precision in terminology will come, though, as we look into these concepts more and more. No need for revising that for now. I get what you're saying and you are correct to the appropriate degree for now.

    The two instance variables you proposed are utterly suitable. Let's go one step further. What would be the argument for why we might want shoe size to be a double data type, rather than an integer?

    Thank You.

    ReplyDelete
  2. we should make the shoe size double because there are half sizes that require decimals. Like 8.5 for an example so the code should be changed to.

    private double shoeSize;

    and then in the public person, it should be shoeSize = 0.0

    ReplyDelete
  3. You've clearly related your rationale, very good. 40 XPs awarded for this completion.

    ReplyDelete