0

I took care of exercise 105. I don't know what to do with 115 though. I've worked a little bit more and progressed a slight bit, but here's the exercise:

A team of biologists is conducting an experiment that involves collecting data on animals founds in a 1 km square area of woodland. As each animal is identified, a record is made of its name, the time of its discovery, and the initials of the scientist who found it. The data are to be recorded on a laptop. Design and implement a system for storing the data, and test your code thoroughly.

[Hint: Think in terms of creating an object for each discovery. What information should each object store, and in what will you store these objects?]

Here is my code:

// put class definitions here



public class Record{

    String name;

    String initials;

    String time;



    public Record{

        this.name = name;

        this.initials = initials;

        this.time = time;

    }

}

Here's another section for me to test my solution in:

public static void main( String[] args )

{

  // test your solution here



}

So I know I'm supposed to make a new Object out of the variables, but do I need to use getters and setters or something? If that was the case it would probably be a lot easier than I'm assuming.

Thx

1 Answers1

0

Getters and setters is a common pattern for getting internal member variables from Objects. They are not mandatory, but it is a good practice.

You need to read some Java and Object Oriented book to understand why we use it that way. You need to understand why encapsulation is encouraged too.

public class Record{

    protected String name;

    protected String initials;

    protected String time;



    public Record{

        this.name = name;

        this.initials = initials;

        this.time = time;

    }

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }
    //... etc.
}
Ethan Fang
  • 1,271
  • 10
  • 15
  • Thanks. I still don't have a perfect answer, but I'll show you some improved code. It still isn't perfect and I don't know where in my subclass to put my arraylist, getters, or setters... – user3079044 Jan 21 '14 at 04:39
  • http://stackoverflow.com/questions/21249342/getters-setters-arraylist-dont-know-where-to-place-in-subclass – user3079044 Jan 21 '14 at 04:42