- Name: Iordache Matei Cezar
- Series: CA
- Group: 325CA
- Time spent on the project: ~1 week
- Project description
- How to run the program
- Project Structure
- Simulation step by step guide
- OOP DESIGN
- Java 8 features
- Feedback
- The project simulates an energetic system in which there are different entities like consumers, distributors and producers
- All the entities will try to accomplish their tasks and not go bankrupt
- Consumers will buy power from the distributors
- Distributors will take power from the producers and distribute it to consumers
- Producers will manufacture power
Step1. Open the project in IntelliJ
Step2.
- Run the Test.java class for multiple tests
- Run the Main.java class for only one test
-
SRC Folder - main folder of the project.
-
actions folder - contains the Commands and Updates classes.
- Commands - contains all commands for the entities.
- Updates - contains all update methods for the entities
-
checker folder - checker files
-
entities folder - contains an enum with all the energyTypes of a producer
- EnergyType - enum with all the energyTypes of a producer
-
fileio folder - contains classes that will store all the data extracted from the JSON files, as well as classes with methods that extract data from a JSON file and write the data back as a JSON file
-
ConsumerData - stores all the data regarding a consumer
-
DistributorChanges - stores all the data from a distributor monthly change
-
DistributorData - stores all the data regarding a distributor.
-
Input - store all the data extracted from the json file
-
InputLoader - parses all the information from the Json file into an Input object
-
InputOutput - interface for a factory design pattern
-
InputOutputFactory - starting point for the factory design pattern
-
MonthlyStats - stores all the data regarding the MonthlyStats of a producer
-
MonthlyUpdatesInputData - stores all the data regarding the MonthlyUpdates
-
ProducerChanges - stores all the data from a producer monthly change
-
ProducerData - stores all the data regarding a producer
-
Writer - Writes an output JSON file containing the desired information
-
-
strategies folder - Contains strategy classes needed for the strategy pattern
-
Context - Context class for the strategy design pattern
-
GreenStrategy - Choose producers which have renewable energy
-
PriceStrategy - Choose producers which have the cheapest energy
-
QuantityStrategy - Choose producers which have the better energy output
-
Strategy - Interface for the Stragegy Design Pattern
-
-
utils folder - Constants
- Constants - Different constants used throughout the program
-
-
Game Class - Class which contains the method that performs the simulation
-
Main Class - Starting point of the program
-
Test Class - Runs the tests from the checker.
If it is the first month of the simulation, the flow is like this:
- Determine which producers have renewable energy.
- Distributors choose to which producers to subscribe
- Distributors calculate their production cost, their profit, and set a price for their contracts
- Consumers choose their distributors and calculate their new budget
- Distributors calculate their new budget at the end of the month
- Consumers update their contract time.
If it is not the first month of the simulation, the flow is like this:
- Add new consumers and update distributor infrastructure cost, based on the monthly changes.
- Distributors calculate their profit, the contract cost and will delete bankrupt consumers from their contract list.
- Consumers choose their distributors and calculate their new budget
- Distributors calculate their new budget at the end of the month
- Consumers update their contract time.
- Update the energyPerDistributor of a producer based on monthly changes and notify the subscribed distributors.
- Distributors choose their producers again if they are affected.
- Distributors calculate their new production cost.
- Set the monthly stats of producers at the end of the month.
Throughout the project I have used different oop concepts and design patterns
- Patterns used:
- Factory
- Singleton
- Observer
- Strategy
I have used the Factory design pattern in the reading/writing of the entities. (InputOutputFactory)
I have made the InputOutputFactory class a singleton.
For the observer design pattern:
- the ProducerData class extends the Observable Class.
- the DistributorData class extends the Observer Class.
Everytime a producer undergoes a monthly change, every distributor that takes power from him will be announced to rechoose his producers
I have used the Strategy Design Pattern in creating different strategies based on the preference of a distributor.
All the strategy classes will implement the StrategyInterface.
I used streams in the implementation of the different strategies
Very hard to understand Task, could have been explained better.
But overall it was a very good exercise, forcing me to use the different concepts I learned in this course.