Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.HashMap;
- import java.util.ArrayList;
- import java.util.Iterator;
- /**
- * Requires a name and then generates a week with random events for each day of the week.
- * Every event affects the mood in a specific way.
- * The mood starts at the value of 200.
- *
- * @author Erik Blomqvist
- * @version 2011-11-07
- */
- public class Person
- {
- private String mName;
- private int mMood;
- private HashMap<String, Event> mWeekEvent;
- private EventGenerator mGenEvent;
- private ArrayList<String> mWeekday;
- /**
- * Constructor for objects of class. Automatically fills the list with random events.
- * Requires the name of a person.
- *
- * @param name Name of the person
- */
- public Person(String name)
- {
- mName = name;
- mMood = 200;
- mWeekEvent = new HashMap<String, Event>();
- mGenEvent = new EventGenerator();
- ArrayList<String> mWeekday = new ArrayList<String>();
- mWeekday.add(new String("Måndag"));
- mWeekday.add(new String("Tisdag"));
- mWeekday.add(new String("Onsdag"));
- mWeekday.add(new String("Torsdag"));
- mWeekday.add(new String("Fredag"));
- mWeekday.add(new String("Lördag"));
- mWeekday.add(new String("Söndag"));
- }
- /**
- * The only public method which prints out the randomized week events and how the person's
- * mood is affected.
- */
- public void listWeek()
- {
- System.out.println("Hej, " + mName);
- System.out.println(" Du startar med gott humör på nivå: " + mMood);
- System.out.println(" Din vecka slumpar sig såhär...");
- for(String thisDay : mWeekday) {
- // Vänta en sekund...
- wait(1000);
- System.out.println(thisDay);
- generateDayEvent();
- Event thisEvent = (Event)mWeekEvent.get(thisDay);
- System.out.println(thisEvent);
- affectMood(thisDay);
- System.out.println(" Ditt humör är nu på: " + mMood);
- }
- }
- /**
- * The method to affect the total mood value based on the day of the week parameter.
- *
- * @param day Day of the week
- */
- private void affectMood(String day)
- {
- Event thisEvent = (Event)mWeekEvent.get(day);
- int newMood = thisEvent.getAffectMood();
- mMood += newMood;
- }
- /**
- * Generates seven different events and puts them in the mWeekEvent HashMap.
- */
- private void generateDayEvent()
- {
- for(String thisDay : mWeekday) {
- mWeekEvent.put(thisDay, mGenEvent.generateEvent());
- }
- }
- /**
- * Wait for a specified number of milliseconds before finishing.
- * This provides an easy way to specify a small delay which can be
- * used when producing animations.
- * @param milliseconds the number
- */
- private void wait(int milliseconds)
- {
- try
- {
- Thread.sleep(milliseconds);
- }
- catch (Exception e)
- {
- // ignoring exception at the moment
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement