Jump to content
Rtrix

[Problem] Java

Recommended Posts

1. Change the implementation of the Population class so that it uses an ArrayList

instead of an array for the population as follows. N.B. You should only have to change

Population.java – the rest of the program should continue to work exactly the same.

(a) Change the declaration of the field and add code to the constructor to create the

ArrayList.

(B) Change any methods which use the population so they work with the ArrayList rather

than an array.

2. (a) Add a new field deathRate to the Population class that gives the probability of

dying from the infection. Assign this a value of 0.0 in the constructor. Now add a

second constructor which initialises deathRate as a parameter as well as all the other

fields. Document using the javadoc format.

(B) Write “get” and “set” methods for deathRate. Document using the javadoc format.

3. Change the update method in Population so that infected people die with

probability given by deathRate. Remove them from the population when this happens.

HINT: this is tricky to get right – I suggest creating an ArrayList to record which people

die in one iteration. Then go through that ArrayList removing them from the population.

(am facut ceva, da' imi da eroare nu inteleg de ce, si vreau sa vad cum e exact)

Fisierele: https://www.dropbox.com/sh/ybxy4hpxegrtix1/AABLKJZE7Deur-Bxv2_AzbG7a?dl=0

Edited by Rtrix
Link to comment
Share on other sites

URL-ul nu este valid. Te rog posteaza codul folosind etichetele code.

Un exemplu de ArrayList este urmatorul:


List<String> lista = new ArrayList<String>();
list.add("RST");
list.add("forums");

Practic poti sa faci ArrayList-ul de orice tip. Gasesti aici mai multe detalii:

Trail: Collections (The Java™ Tutorials)

ArrayList (Java Platform SE 6)

List (Java Platform SE 6)

Link to comment
Share on other sites

3. Change the update method in Population so that infected people die with

probability given by deathRate. Remove them from the population when this happens.

HINT: this is tricky to get right – I suggest creating an ArrayList to record which people

die in one iteration. Then go through that ArrayList removing them from the population.

https://www.dropbox.com/sh/ybxy4hpxegrtix1/AABLKJZE7Deur-Bxv2_AzbG7a?dl=0

Mai am asta.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...