-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from danieskj/dev
Dev
- Loading branch information
Showing
27 changed files
with
567 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| @echo off | ||
| REM delete-storage.bat | ||
| REM Deletes the Millions JSON storage for resetting app state | ||
| REM The storage file location is chosen by StorageFile.java | ||
|
|
||
| SET "STORAGE_FOLDER_NAME=Millions" | ||
| SET "STORAGE_FILE=storage.json" | ||
|
|
||
| REM Use %APPDATA% if set, otherwise fallback to %USERPROFILE% | ||
| IF DEFINED APPDATA ( | ||
| SET "STORAGE_DIR=%APPDATA%\%STORAGE_FOLDER_NAME%" | ||
| ) ELSE ( | ||
| SET "STORAGE_DIR=%USERPROFILE%\%STORAGE_FOLDER_NAME%" | ||
| ) | ||
|
|
||
| SET "STORAGE_PATH=%STORAGE_DIR%\%STORAGE_FILE%" | ||
|
|
||
| IF EXIST "%STORAGE_PATH%" ( | ||
| ECHO Deleting storage at %STORAGE_PATH% ... | ||
| DEL /F "%STORAGE_PATH%" | ||
| ECHO Storage deleted. | ||
| ) ELSE ( | ||
| ECHO Storage not found at %STORAGE_PATH%. | ||
| ) | ||
|
|
||
| PAUSE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| #!/usr/bin/env bash | ||
| # delete-storage.sh | ||
| # Deletes the Millions JSON storage for resetting app state | ||
| # The storage file location is chosen by StorageFile.java | ||
|
|
||
| set -e | ||
|
|
||
| STORAGE_FOLDER_NAME="Millions" | ||
| STORAGE_FILE="storage.json" | ||
|
|
||
| OS=$(uname | tr '[:upper:]' '[:lower:]') | ||
| HOME_DIR="$HOME" | ||
|
|
||
| # Determine database folder path based on OS | ||
| if [[ "$OS" == *"darwin"* ]]; then | ||
| # macOS | ||
| STORAGE_DIR="$HOME_DIR/Library/Application Support/$STORAGE_FOLDER_NAME" | ||
| elif [[ "$OS" == *"linux"* ]]; then | ||
| # Linux / Unix | ||
| STORAGE_DIR="$HOME_DIR/.local/share/$STORAGE_FOLDER_NAME" | ||
| elif [[ "$OS" == *"mingw"* || "$OS" == *"cygwin"* || "$OS" == *"msys"* ]]; then | ||
| # Windows (Git Bash, Cygwin, MSYS) | ||
| if [[ -n "$APPDATA" ]]; then | ||
| STORAGE_DIR="$APPDATA/$STORAGE_FOLDER_NAME" | ||
| else | ||
| STORAGE_DIR="$HOME_DIR/$STORAGE_FOLDER_NAME" | ||
| fi | ||
| else | ||
| echo "Unsupported OS: $OS" | ||
| exit 1 | ||
| fi | ||
|
|
||
| STORAGE_PATH="$STORAGE_DIR/$STORAGE_FILE" | ||
|
|
||
| if [[ -f "$STORAGE_PATH" ]]; then | ||
| echo "Deleting storage at $STORAGE_PATH ..." | ||
| rm "$STORAGE_PATH" | ||
| echo "Storage deleted." | ||
| else | ||
| echo "Storage not found at $STORAGE_PATH" | ||
| fi | ||
|
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| package edu.ntnu.idi.idatt.model; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Random; | ||
|
|
||
| import edu.ntnu.idi.idatt.model.enums.NewspaperEnum; | ||
|
|
||
| public class Newspaper { | ||
|
|
||
| ArrayList<NewspaperEnum> news = new ArrayList<>(List.of(NewspaperEnum.NONE_EVENT)); | ||
| private static double chance = 0.05; // In percent | ||
|
|
||
| public NewspaperEnum makeNews() { | ||
| Random r = new Random(); | ||
| double roll = r.nextDouble(); | ||
|
|
||
| if (roll >= chance) { | ||
| news.add(NewspaperEnum.NONE_EVENT); | ||
| return NewspaperEnum.NONE_EVENT; | ||
| } | ||
|
|
||
| int message = r.nextInt(NewspaperEnum.values().length - 1); // Do not include last | ||
| NewspaperEnum event = NewspaperEnum.values()[message]; | ||
|
|
||
| news.add(event); | ||
| return event; | ||
| } | ||
|
|
||
| public boolean hasNewNews() { | ||
| return news.getLast().equals(NewspaperEnum.NONE_EVENT) ? false : true; | ||
| } | ||
|
|
||
| public ArrayList<NewspaperEnum> getNews() { | ||
| return news; | ||
| } | ||
|
|
||
| public List<String> getNewsStrings() { | ||
|
|
||
| ArrayList<String> strings = new ArrayList<>(); | ||
|
|
||
| int i = 1; // First possible new happens at week 1 | ||
| for (NewspaperEnum newsEnum : news) { | ||
|
|
||
| if (newsEnum == NewspaperEnum.NONE_EVENT) { | ||
| i++; | ||
| continue; | ||
| } | ||
|
|
||
| strings.add(String.format("Week: %d - %s [%s]", | ||
| i, | ||
| newsEnum.getTitle(), | ||
| newsEnum.getDescription())); | ||
| i++; | ||
|
|
||
| } | ||
| return strings; | ||
|
|
||
| } | ||
|
|
||
| } |
109 changes: 109 additions & 0 deletions
109
src/main/java/edu/ntnu/idi/idatt/model/enums/NewspaperEnum.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| package edu.ntnu.idi.idatt.model.enums; | ||
|
|
||
| public enum NewspaperEnum { | ||
| NEW_PRODUCT( | ||
| "New product announced!", | ||
| "The company revealed plans for a major new product launch next week!", | ||
| 0.08, | ||
| 0.02), | ||
|
|
||
| QUARTER( | ||
| "Quarterly earnings released!", | ||
| "The company's quarterly earnings report exceeded analyst expectations!", | ||
| 0.05, | ||
| 0.03), | ||
|
|
||
| DISASTER( | ||
| "Natural disaster struck!", | ||
| "A natural disaster disrupted several of the company's factories!", | ||
| -0.08, | ||
| 0.08), | ||
|
|
||
| RESEARCH_FUNDS( | ||
| "Government research funding!", | ||
| "The government approved additional funding for the company's research division!", | ||
| 0.04, | ||
| 0.04), | ||
|
|
||
| FRAUD( | ||
| "Fraud investigation!", | ||
| "The company's CEO is under investigation for potential fraud!", | ||
| -0.05, | ||
| 0.12), | ||
|
|
||
| NEW_PARTNERSHIP( | ||
| "Major partnership formed!", | ||
| "The company announced a strategic partnership with another corporation!", | ||
| 0.07, | ||
| 0.03), | ||
|
|
||
| PRODUCT_RECALL( | ||
| "Product recall issued!", | ||
| "The company recalled one of its products over safety concerns!", | ||
| -0.08, | ||
| 0.07), | ||
|
|
||
| SUPPLY_SHORTAGE( | ||
| "Supply shortage reported!", | ||
| "Global supply shortages are slowing the company's production!", | ||
| -0.06, | ||
| 0.05), | ||
|
|
||
| FACTORY_EXPANSION( | ||
| "Factory expansion planned!", | ||
| "The company announced plans to expand manufacturing capacity!", | ||
| 0.06, | ||
| 0.02), | ||
|
|
||
| PATENT_APPROVED( | ||
| "Patent approved!", | ||
| "The company secured a major technology patent approval!", | ||
| 0.09, | ||
| 0.03), | ||
|
|
||
| PATENT_DENIED( | ||
| "Patent denied!", | ||
| "Regulators denied one of the company's patent applications!", | ||
| -0.08, | ||
| 0.05), | ||
|
|
||
| MARKET_MANIPULATION_INVESTIGATION( | ||
| "Market investigation launched!", | ||
| "Regulators opened a market manipulation investigation into the company!", | ||
| -0.03, | ||
| 0.15), | ||
| NONE_EVENT( | ||
| "", | ||
| "", | ||
| 0, | ||
| 0); | ||
|
|
||
| private final String title; | ||
| private final String description; | ||
| private final double trend; | ||
| private final double volatility; // How violently the price moves factor | ||
|
|
||
| NewspaperEnum(String title, String description, double trend, double volatility) { | ||
| this.title = title; | ||
| this.description = description; | ||
| this.trend = trend; | ||
| this.volatility = volatility; | ||
| } | ||
|
|
||
| public String getTitle() { | ||
| return title; | ||
| } | ||
|
|
||
| public String getDescription() { | ||
| return description; | ||
| } | ||
|
|
||
| public double getTrend() { | ||
| return trend; | ||
| } | ||
|
|
||
| public double getVolatility() { | ||
| return volatility; | ||
| } | ||
|
|
||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.