CS 222 Spring 2016

School Festival Simulation

Due: May 20, Friday, 23:55 pm.

Language: Java

Submission:

  • Check your file encoding. It should be UTF-8
  • Checkout the folder SchoolFestivalSimulation from your SVN folder
  • Commit your code to this folder
  • Do NOT use package names

Assignment Explanation

In this assignment, you will simulate a school festival. You are already familiar with the School and Stand classes. You will use these.This time, we have 5 schools and 23 stands in total. They are listed below. Please add item prices and feel free to alter items sold as you wish. You can even add more schools and/or stands if you like.

Schools, stands and items they sell or services they offer are listed below:

  1. Seirin High School:
    • Cloudy Candy: Sells cotton Candy
    • Harmony Karaoke: Do karaoke with Mitobe
    • Caffeine Charger: Sells coffee
    • Virtual Guitar: Play virtual guitar
    • InterStreet: Play street basketball with Seirin Basketball Team
  2. Honnouji Academy:
    • Capypa Fireworks: Sells fireworks
    • Ground Cherry Lanterns: Sells lanterns
    • Ramen Ichiraku: Sells ramen
    • Lambo’s Takoyaki: Sells takoyaki
    • Ultima Wars: Challenge Satsuki or Ryoko with an ultima uniform
  3. UltiHackers Academy:
    • Engineer’s pizza: Sells pizza
    • Ice Breaker Hunt: Dive in the matrix to hack a company
    • MCP’s Light Cycle: Virtual Death Match on the grid with light cycles
    • Dragon Hunters: Sells dragon horn
    • Umbrella Corporation: Sells umbrella
  4. Jedi Praxeum:
    • Jedi’s place: Receive Jedi training from Yoda
    • Dark Cookies: Sells Darth Vader’s homemade cookies
    • Ring Throwing at Yoda’s Place: Ring throwing training with Yoda
    • Skywalker Waffles: Sells Luke’s homemade waffles
  5. Festival’s Local Committee:
    • Bookworm’s Place: Sells books
    • Rainbow Pots: Sells flowers in pots
    • Killua’s Deadly Dart: Play dart
    • Coyote Starrk’s Pistol Game: Shoot to earn souvenirs

Your simulation will be driven by students that shop from stands. After the festival is finished, you will announce the winner stand and the school that the stand belongs to. Students are entities that act by themselves. Therefore, you need to define a Student class that extends the Thread class of Java.

Your understanding of a simulation should be as follows: Think of the simulation as a discrete system made of states. And each state defined as an iteration. Here, at each iteration (1 cycle of the loop), state of the system changes. Thus, the pseudocode of the simulation is:

while(ITERCOUNT < MAX_ITERCOUNT){
  make changes to the objects
  ITERCOUNT++
}

As the system itself, each object has its own state. Thus, your whole system’s state is defined by the composition of all of your objects’ current states. your understanding of an object’s (or the system’s) state should be the values of all of the object’s fields (or in the case of the system, objects it has). A basic explanation of an object’s state

Making changes to the objects means that objects interact with each other: Students visit stands, buy things, stands earn money, number of items of a stand changes, a student leaves the festival, a student joins the festival…etc. Hence states of the objects change reflacting a change in the state of the whole system. Your objects are simply your schools, stands and students.

Making changes to the objects is defined by rules of the simulation: The interaction between the objects are subject to these rules. MAX_ITERCOUNT should be set to 100. However, you can change it according to your needs (testing your code, finding bugs, observing the behavior of threads..etc).

At each iteration, for each object, you should check the rules and change objects’ states accordingly. Changes are made to states of all objects that interacted with another object.

Your start state is defined below:

  1. There are 10 items at each stand (23*10 = 230 items in total)
  2. There are 50 students at the festival

Rules:

  1. 10 items are added to each stand per iteration. But, if there are more than 40 items in a stand, no new item is added to it. For stands offering a service think of the item as a ticket. So the stand is selling tickets for the service that it provides.
  2. 5 students join the festival per iteration.
  3. A student visits 3 random stands per iteration and buys [2-5] items from each stand. (For this, get a random item count between 2 and 5 (inclusive) for the number of items to buy from a stand).
  4. If a student bought at least 8 items in total then he/she leaves the festival, else invites a friend to the festival. Also, if all 3 stands that the student visited are empty then he/she leaves and doesn’t invite anyone to the festival.
  5. Each iteration, set number of items bought by a student to zero. The reason for this is rule 4: If, a student didn’t buy at least 8 items, he/she will be in the festival at least for the next iteration too. But he/she already has items bought at hand. Hence newly bought items will be added on top of items from previous iteration. To prevent this, set number off items bought to zero at each iteration.

GENERAL SETUP:

  1. 100 iterations
  2. Report after each iteration by printing these on the screen:
    • Stands that hit zero items
    • Stands that hit full (40) items
    • Number of items sold in total
    • Current number of students in the festival
    • Total revenue (money earnt by stands in total)

AT THE END print these on the screen:

  1. Number of items sold in total
  2. Current number of students in the festival
  3. Total revenue (money earnt by stands in total)
  4. Winner stand (along with its details like the name of the stand, what item they sell, the price of the item they sell, how many items they sold and their total revenue) and the school that the stand belongs to.

GENERAL TIPS:

  1. There’s no interaction with the user in this simulation. Therefore, you will create all of the schools and stands and students at the beginning of your program.
  2. Make necessary changes to School and Stand classes.
  3. A stand can sell only 1 type of item or can offer 1 type of service only.
  4. My advice to you for object creation: Write a class that is responsible for object creation. Use this to create all your objects (Students, Stands, Schools). Factory method is a suitable design pattern for this purpose. We have also discussed this in the class.
  5. You can think of the relationship between Stand and Student objects as a Producer-Consumer relationship. This is a classical concurrency problem from the literature. However there’s no need to make a stand object a thread. Simply increase number of items according to the rules when it hits zero (remember the race condition we have discussed in the class).
  6. Leaving the festival:
  7. Inviting a friend to the festival:
    • When a new Student has to be created, delegate this request to your class responsible for object creation.
  8. Student class should have at least these methods:
    • chooseRandomStand
    • visitStand
  9. Stand class should have at least these methods:
    • sellItem
    • loadItemPack (for adding 10 items per iteration)

Refactoring

Refactor your code. In addition to appropriate naming, clean and short and well-defined functions, apply what you have learnt from formatting lecture. Make sure that you don’t have any code smells in your code.

Grading

TBD