Starting from:

$35

CENG443- Homework 1: Arms Race Solved

1           Introduction
In this assignment, you will implement a simulation about defence contractors selling arms to countries which buy/sell gold and import goods. When building the simulation, you will employ the object-oriented design principles you learn during the classes. To see the big picture, a video of the sample implementation is provided (link).

2           Simulation Entities
You will implement the simulation with the following classes. Do not add new classes or rename/remove the existing ones. You will complete the parts where TODO comments are.

SimulationRunner: Contains the main method. Already filled for you.
Display: Represents the display on which simulation entities, i.e. countries, orders, and corporations, are repeatedly drawn.
Common: Brings together simulation parameters, instances of entities, and other utility fields/methods that are required for running the application.
Entity: Represents a simulation entity. Already filled for you.
Position: Represents a position (x and y coordinates). Already filled for you.
LivePrice: Represents the live food/electronics/gold price that changes at random. Already filled for you.
Country: A country has a name, some gold, some cash, a dynamic worth [cash + gold x current gold price], and percentage of happiness (of its citizens). A country randomly generates gold orders at all times. However, when the happiness is less than 50%, it also generates import orders, i.e., food products orders and consumer electronics orders, to increase its citizens’ happiness.
Order: Base class for GoldOrder, FoodOrder, and ElectronicsOrder. An order has a random amount (between 1 and 5), a random speed, and a random path. An order is a filled circle labelled with the amount information and initials of the originating country. Gold orders are either green or red. While food orders are yellow, electronics orders are blue. When an order hits the horizontal line, just below the live prices, the order is executed for the gold price recorded at the hit time.
GoldOrder: Base class for BuyGoldOrder and SellGoldOrder.
BuyGoldOrder When a buy gold order is executed at the horizontal line, the originating country gains gold by [order amount] and loses cash by [order amount x current gold price]. The color of a buy gold order is green.
SellGoldOrder When a sell gold order is executed at the horizontal line, the originating country loses gold by [order amount] and gains cash by [order amount x current gold price]. The color of a sell gold order is red.
FoodOrder When a food order is executed at the horizontal line, the originating country loses cash by [order amount x current food price] and gains happiness by [order amount x 0.2].
ElectronicsOrder When an electronics order is executed at the horizontal line, the originating country loses cash by [order amount x current electronics price] and gains happiness by [order amount x 0.4].
Corporation: When a corporation comes in contact with a gold order, it sells arms to order’s originating country and gains cash by [order amount x current gold price]. If it is a buy gold order, the country loses cash by [order amount x current gold price]. If it is a sell gold order, the country loses [order amount] gold. Wasting tax money on arms creates some unrest among the citizens and as a result the country’s happiness decreases by [order amount x 0.1] as well (for both buy and sell gold orders). Successful corporations are awarded badges. If a corporation’s cash exceeds 2000$, it is awarded with a white (rectangular) badge. When the cash exceeds 4000$, it is also awarded a yellow badge. Exceeding 6000$, the corporation is rewarded with a red badge.
State: Base class for Rest, Shake, GotoXY, and ChaseClosest. A corporation has a state which it changes at random.
Rest: A state where the corporation stays still.
Shake: A state where the corporation makes random dispositions in horizontal and vertical directions.
GotoXY: A state where the corporation picks a random position as its destination and moves there with a random speed. When the destination is reached, the above process is repeated.
ChaseClosest: A state where the corporation picks the closest gold order as its destination and chases it with a random speed. If there are no gold orders roaming around, then the corporation stays still

More products