diff --git a/App.java b/App.java new file mode 100644 index 0000000..0e05f09 --- /dev/null +++ b/App.java @@ -0,0 +1,12 @@ +package org.example; + +/** + * Hello world! + * + */ +public class App { + public static void main( String[] args ) + { + System.out.println( "Hello World!" ); + } +} diff --git a/AppTest.java b/AppTest.java new file mode 100644 index 0000000..cf35e75 --- /dev/null +++ b/AppTest.java @@ -0,0 +1,38 @@ +package org.example; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for simple App. + */ +public class AppTest + extends TestCase +{ + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + + /** + * Rigourous Test :-) + */ + public void testApp() + { + assertTrue( true ); + } +} \ No newline at end of file diff --git a/Bank.java b/Bank.java new file mode 100644 index 0000000..200f31f --- /dev/null +++ b/Bank.java @@ -0,0 +1,44 @@ +package org.example.defualtSystem; + +import org.example.interfaces.BankInterface; +import org.example.models.*; +import org.example.models.Character; + +import java.util.ArrayList; +import java.util.Date; + +public class Bank extends Industry implements BankInterface { + + private static final int MAX_EMPLOYEE_COUNT = 5; + private static final float BASE_EMP_SALARY = 0.5f; + private ArrayList accounts = new ArrayList(); + + private Manager manager = null; + + public static BankTurnover turnover; + + public Bank(Property property,Character root) { + super("Bank",property,root,100.0f); + turnover = new BankTurnover(); + } + + public BankAccount newAccount(String username,String password){ + BankAccount bankAccount = new BankAccount(username,password,0,new Date()); + accounts.add(bankAccount); + return bankAccount; + } + public boolean registerAsEmp(Character character){ + if(employees.size() >= MAX_EMPLOYEE_COUNT)return false; + Employee employee = new Employee(character.getUserInfo().getUsername(),this,BASE_EMP_SALARY,character.getAccount()); + employees.add(employee); + return true; + } + + + public String bankDetail(Character character){ + if(character.getUserInfo().getUsername().equals(manager.getUsername())){ + return ""; + } + return "Only Manager can see Bank detail"; + } +} diff --git a/BankAccount.java b/BankAccount.java new file mode 100644 index 0000000..fc42329 --- /dev/null +++ b/BankAccount.java @@ -0,0 +1,72 @@ +package org.example.models; + +import org.example.defualtSystem.Bank; + +import java.util.Date; + +public class BankAccount { + private String owner; + private String password; + private float money; + private Date lastChange; + + private String logs = ""; + + public BankAccount(String owner, String password, float money, Date lastChange) { + this.owner = owner; + this.password = password; + this.money = money; + this.lastChange = lastChange; + } + + public String getOwner() { + return owner; + } + + public void setOwner(String owner) { + this.owner = owner; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public float getMoney() { + return money; + } + + + public Date getLastChange() { + return lastChange; + } + + public void setLastChange(Date lastChange) { + this.lastChange = lastChange; + } + + public boolean withdraw(Character character,float amount){ + if(character.getUserInfo().getUsername().equals(owner)){ + if(amount <= money){ + Bank.turnover.transfer(amount,-1); + money-= amount; + return true; + }else + return false; + } + return false; + } + public boolean deposit(Character character,float amount){ + if(amount >0){ + String log = String.format("User : %s deposit %f \n",character.getUserInfo().getUsername(),amount); + logs+=log; + Bank.turnover.transfer(amount,1); + money += amount; + return true; + } + return false; + } +} diff --git a/BankInterface.java b/BankInterface.java new file mode 100644 index 0000000..3ff6269 --- /dev/null +++ b/BankInterface.java @@ -0,0 +1,4 @@ +package org.example.interfaces; + +public interface BankInterface { +} diff --git a/BankTurnover.java b/BankTurnover.java new file mode 100644 index 0000000..1865c10 --- /dev/null +++ b/BankTurnover.java @@ -0,0 +1,20 @@ +package org.example.defualtSystem; + +public class BankTurnover { + private double withdraw = 0; + private double deposit = 0; + + /** + * @param amount : Money amount + * @param type : -1 for withdraw , +1 for deposit + * */ + public void transfer(float amount,int type){ + if(type == 1) + deposit=amount; + else if (type==-1) + withdraw+=amount; + } + public double calcTurnover(){ + return deposit-withdraw; + } +} diff --git a/Character.java b/Character.java new file mode 100644 index 0000000..2f52af8 --- /dev/null +++ b/Character.java @@ -0,0 +1,74 @@ +package org.example.models; + +import org.example.defualtSystem.Life; +import org.example.interfaces.CharacterInterface; + +import java.util.ArrayList; + +public class Character implements CharacterInterface { + private User userInfo; + private BankAccount account; + private Life life; + private Job job; + private ArrayList properties; + private Property inPosition; + + public Character(User userInfo, BankAccount account, Life life, Job job, ArrayList properties, Property inPosition) { + this.userInfo = userInfo; + this.account = account; + this.life = life; + this.job = job; + this.properties = properties; + this.inPosition = inPosition; + } + + public User getUserInfo() { + return userInfo; + } + + public void setUserInfo(User userInfo) { + this.userInfo = userInfo; + } + + public BankAccount getAccount() { + return account; + } + + public void setAccount(BankAccount account) { + this.account = account; + } + + public Life getLife() { + return life; + } + + public void setLife(Life life) { + this.life = life; + } + + public Job getJob() { + return job; + } + + public void setJob(Job job) { + this.job = job; + } + + public void gotToLocation(Property destination){ + if(destination==null)return; + inPosition = destination; + } + + public ArrayList getProperties() { + return properties; + } + + public void setProperties(ArrayList properties) { + this.properties = properties; + } + + @Override + public void positionProcessing() { + + } +} diff --git a/CharacterInterface.java b/CharacterInterface.java new file mode 100644 index 0000000..f756469 --- /dev/null +++ b/CharacterInterface.java @@ -0,0 +1,6 @@ +package org.example.interfaces; + +public interface CharacterInterface { + void positionProcessing(); + +} diff --git a/City.java b/City.java new file mode 100644 index 0000000..7e92611 --- /dev/null +++ b/City.java @@ -0,0 +1,66 @@ +package org.example.models; + +import org.example.defualtSystem.Bank; +import org.example.defualtSystem.Life; +import org.example.defualtSystem.Municipality; +import org.example.defualtSystem.StockMarket; +import org.example.interfaces.CityInterface; + +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Scanner; + +public class City implements CityInterface { + private final ArrayList characters; + private final Bank bankSystem; + private final Municipality municipality; + + private final StockMarket stockMarket; + + private Character root; + + public City() { + characters = new ArrayList<>(); + municipality = new Municipality(); +// Get Bank Property from municipality + bankSystem = new Bank(new Property(new float[]{12, 32}, new float[]{42, 32}, root), root); + stockMarket = new StockMarket(); + stockMarket.startMarketSimulation(); + } + + @Override + public void joinCharacter(User userinfo) { + BankAccount newAccount = bankSystem.newAccount(userinfo.getUsername(), userinfo.getPassword()); + Character character = new Character(userinfo, newAccount, new Life(), null, null, null); + characters.add(character); + beginGame(character); + } + + @Override + public void getCityDetail() { + String players = Arrays.toString(characters.toArray()); + } + + + /** + * Begin Game function generate a new thread for each character , DO NOT CHANGE THIS FUNCTION STRUCTURE , + * + * */ + private void beginGame(Character character) { + Thread thread = new Thread(() -> { + try { + Scanner scanner = new Scanner(System.in); + while (true) { + System.out.println("Show Menu"); + switch (scanner.next()) { + case "2", "3" -> System.out.println("Do Something"); + } + } + } catch (Exception e) { + throw new RuntimeException(e); + } + }); + thread.start(); + } +} diff --git a/CityInterface.java b/CityInterface.java new file mode 100644 index 0000000..b912da2 --- /dev/null +++ b/CityInterface.java @@ -0,0 +1,9 @@ +package org.example.interfaces; + +import org.example.models.Character; +import org.example.models.User; + +public interface CityInterface { + void joinCharacter(User character); + void getCityDetail(); +} diff --git a/Database.java b/Database.java new file mode 100644 index 0000000..5cd3293 --- /dev/null +++ b/Database.java @@ -0,0 +1,387 @@ +package org.example; + +import org.example.models.User; + +import javax.xml.crypto.Data; +import java.security.spec.ECField; +import java.sql.*; +import java.util.Scanner; + +import java.security.*; + +public class Database { + + int id; + static final String JDBC_DRIVER = "com.mysql.jdbc.Driver"; + static final String DB_URL = "jdbc:mysql://localhost/lightcity"; + + // Database credentials + static final String USER = "root"; + static final String PASS = "2324LBJKB@pourya"; + + + private Connection conn; + + public Database() { + try { + Class.forName(JDBC_DRIVER); + conn = DriverManager.getConnection(DB_URL, USER, PASS); + System.out.println("\nConnecting to database..."); + } catch (Exception exp) { + System.out.println("Database Exception : \n" + exp.toString()); + System.exit(0); + } + } + // Tables + + /** + * Users + */ + + public void checkUserInfo(String username, String password) { + + try { + Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/lightcity", "root", "2324LBJKB@pourya"); + Statement statement = connection.createStatement(); + ResultSet resultSet = statement.executeQuery("SELECT * FROM user"); + + boolean check = false; + + password = encryptPassword(password); + + while (resultSet.next()){ + + if (username.equals(resultSet.getString("username")) && password.equals(resultSet.getString("password"))){ + check = true; + } + + } + + if (check){ + + System.out.println("\nWelcome!"); + System.out.println("\n1. Enter a city"); + System.out.println("2. Build a new city"); + + System.out.print("\nInput number: "); + + Scanner sc = new Scanner(System.in); + + int num; + num = sc.nextInt(); + + if (num == 1) { + cityList(username, password); + + } else if (num == 2) { + buildCity(username, password); + + } + + + } else { + + System.out.println("\nYou have not registered yet. Would you like to register now?"); + System.out.println("\n1. Yes"); + System.out.println("2. No"); + System.out.print("\nInput number: "); + + Scanner sc = new Scanner(System.in); + + int num; + num = sc.nextInt(); + + if (num == 1) { + + Scanner str = new Scanner(System.in); + + String userName; + String passWord; + + System.out.print("\nUsername: "); + userName = str.nextLine(); + + System.out.print("Password: "); + passWord = str.nextLine(); + + passWord = encryptPassword(passWord); + + User user = new User(userName, passWord); + + registerGame(user); + + System.out.println("\nYou have successfully registered.\n"); + + } else if (num == 2) { + Menu.showMenu(); + } + } + + }catch (Exception e){ + System.out.println(e); + } + + } + + public void loginGame(User user) { + try { + Statement stmt = conn.createStatement(); + String query = ""; + ResultSet res = stmt.executeQuery(query); + while (res.next()) { +// Check + } + } catch (Exception exception) { + } + + } + + public void registerGame(User user) { + + try { + Connection connection = DriverManager.getConnection("jdbc:mysql://localhost/lightcity", "root", "2324LBJKB@pourya"); + String sql = "INSERT INTO user (id, username, password) VALUES (?, ?, ?)"; + + PreparedStatement preparedStatement = connection.prepareStatement(sql); + preparedStatement.setInt(1, id); + preparedStatement.setString(2, user.getUsername()); + preparedStatement.setString(3, user.getPassword()); + + preparedStatement.executeUpdate(); + + } catch (Exception e) { + System.out.println(e); + } + } + + public String encryptPassword(String password){ + + String encryptedPassword = null; + + try { + + MessageDigest m = MessageDigest.getInstance("MD5"); + + m.update(password.getBytes()); + + byte[] bytes = m.digest(); + + StringBuilder s = new StringBuilder(); + + for (int i = 0; i < bytes.length; i++) { + s.append(Integer.toString((bytes[i] & 0xff) + 0x100, 16).substring(1)); + } + + encryptedPassword = s.toString(); + + } catch (NoSuchAlgorithmException e){ + e.printStackTrace(); + } + + return encryptedPassword; + + } + + public void cityList(String username, String password){ + + try { + + Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/lightcity", "root", "2324LBJKB@pourya"); + Statement statement = connection.createStatement(); + ResultSet resultSet = statement.executeQuery("SELECT * FROM city"); + + + + System.out.println("\nList of available cities:"); + + while (resultSet.next()){ + + int cityID; + String manager; + String cityName; + + + cityID = resultSet.getInt("id"); + manager = resultSet.getString("manager"); + cityName = resultSet.getString("name"); + + System.out.println("\nCity name: " + cityName); + System.out.println("Manager: " + manager); + System.out.println("City ID: " + cityID); + + System.out.println("\n------------------------------------------"); + + } + + Scanner sc = new Scanner(System.in); + + System.out.print("\nEnter the ID of the city you want to enter: "); + + int cityID; + cityID = sc.nextInt(); + + cityLogin(cityID); + + } catch (Exception e){ + + System.out.println("\nNo city has been created yet!"); + System.out.println("Do you want to build a new city?"); + + System.out.println("\n1. Yes"); + System.out.println("2. No"); + + System.out.print("\nInput number: "); + + Scanner numSC = new Scanner(System.in); + + int num2; + num2 = numSC.nextInt(); + + if (num2 == 1) { + + buildCity(username, password); + + } else if (num2 == 2) { + Menu.showMenu(); + } + + } + + } + + public void buildCity(String username, String password){ + + Scanner sc = new Scanner(System.in); + + System.out.print("\nEnter the name of the city: "); + + String cityName; + cityName = sc.nextLine(); + + + + try { + Connection connection = DriverManager.getConnection("jdbc:mysql://localhost/lightcity", "root", "2324LBJKB@pourya"); + String sql = "INSERT INTO city (id, manager, name, password, industry, income, product) VALUES (?, ?, ?, ?, ?, ?, ?)"; + + PreparedStatement preparedStatement = connection.prepareStatement(sql); + + preparedStatement.setLong(1, id); + preparedStatement.setString(2, username); + preparedStatement.setString(3, cityName); + preparedStatement.setString(4, password); + preparedStatement.setString(5, null); + preparedStatement.setString(6, null); + preparedStatement.setString(7, null); + + preparedStatement.executeUpdate(); + } catch (Exception e) { + System.out.println(e); + } + + System.out.println("\nCity has been built successfully!"); + + } + + public void cityLogin(int cityID){ + + try { + Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/lightcity", "root", "2324LBJKB@pourya"); + Statement statement = connection.createStatement(); + ResultSet resultSet = statement.executeQuery("SELECT * FROM city"); + + while (resultSet.next()){ + + if (cityID == resultSet.getInt("id")){ + cityMenu(resultSet.getString("name"), cityID); + } + } + + } catch (Exception e){ + System.out.println(e); + } + + } + + public void cityMenu(String cityName, int cityID){ + + System.out.println("\nCity name: " + cityName); + + System.out.println("\n1. Go to"); + System.out.println("2. Process Location"); + System.out.println("3. Dashboard"); + System.out.println("4. Build a new industry"); + System.out.println("5. Life"); + System.out.println("6. Exit"); + + System.out.print("Input number: "); + + Scanner sc = new Scanner(System.in); + + int num; + num = sc.nextInt(); + + switch (num){ + + case 1: + break; + + case 2: + break; + + case 3: + break; + + case 4: + buildIndustry(cityName, cityID); + break; + + case 5: + break; + + case 6: + System.exit(0); + break; + + } + } + + public void buildIndustry(String cityName, int cityID){ + + Scanner sc = new Scanner(System.in); + + String title; + String income; + String product; + + System.out.print("\nEnter the title of the industry: "); + title = sc.nextLine(); + + System.out.print("Product: "); + product = sc.nextLine(); + + System.out.print("Income: "); + income = sc.nextLine(); + + try { + Connection connection = DriverManager.getConnection("jdbc:mysql://localhost/lightcity", "root", "2324LBJKB@pourya"); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE city set industry = ?, income = ?, product = ? WHERE id = ?"); + + preparedStatement.setString(1, title); + preparedStatement.setString(2, income); + preparedStatement.setString(3, product); + preparedStatement.setInt(4, cityID); + + preparedStatement.executeUpdate(); + + }catch (Exception e){ + System.out.println(e); + } + + System.out.println("\nIndustry has been created successfully!"); + + cityMenu(cityName, cityID); + + } + +} diff --git a/Employee.java b/Employee.java new file mode 100644 index 0000000..a8d76df --- /dev/null +++ b/Employee.java @@ -0,0 +1,47 @@ +package org.example.models; + +public class Employee { + private String username; + private float baseSalary ; + private int level; + + private BankAccount bankAccount; + + private Industry industry; + + public Employee(String username,Industry industry, float baseSalary,BankAccount bankAccount) { + this.username = username; + this.baseSalary = baseSalary; + this.industry = industry; + this.level = 1; + this.bankAccount = bankAccount; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public float getBaseSalary() { + return baseSalary; + } + + public void setBaseSalary(float baseSalary) { + this.baseSalary = baseSalary; + } + + public int getLevel() { + return level; + } + + public void setLevel(int level) { + this.level = level; + } + + public void paySalary(){ + bankAccount.deposit(industry.getOwner(),level*baseSalary); + } +} diff --git a/FastFoodShop.java b/FastFoodShop.java new file mode 100644 index 0000000..092ef60 --- /dev/null +++ b/FastFoodShop.java @@ -0,0 +1,17 @@ +package org.example.defualtSystem; + +import org.example.models.Character; +import org.example.models.Industry; +import org.example.models.Property; + +public class FastFoodShop extends Industry { + + /** + * Industry type example (Business) + * */ + private static final float INCOME = 0.3f; + private static final float EMPLOYEE_INCOME = 0.02f; + public FastFoodShop(String title, Property property, Character character) { + super(title, property, character,EMPLOYEE_INCOME); + } +} diff --git a/Food.java b/Food.java new file mode 100644 index 0000000..137ec2f --- /dev/null +++ b/Food.java @@ -0,0 +1,32 @@ +package org.example.models; + +public class Food { + + private String title; + private final float water; + private final float food; + + public boolean available = true; + + public Food(String title,float food,float water) { + this.food = food; + this.water = water; + this.title = title; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public float getWater() { + return water; + } + + public float getFood() { + return food; + } +} diff --git a/Game.java b/Game.java new file mode 100644 index 0000000..df7b098 --- /dev/null +++ b/Game.java @@ -0,0 +1,59 @@ +package org.example; + +import org.example.interfaces.GameInterface; +import org.example.models.Character; +import org.example.models.City; +import org.example.models.User; + +import java.util.ArrayList; +import java.util.Scanner; + +public class Game implements GameInterface { + + // Check Data from Database or file to see There is city or not + private City city; + @Override + public void continueGame(User user) { + + Scanner sc = new Scanner(System.in); + + String username; + String pass; + + System.out.print("\nEnter your username: "); + username = sc.nextLine(); + + System.out.print("Enter your password: "); + pass = sc.nextLine(); + + Database database = new Database(); + + database.checkUserInfo(username, pass); + } + + /** Create new city and Generate new Character + * @param user : User information contain username, password + * */ + @Override + public void startGame(User user) { + + generateNewCity(); + city.joinCharacter(user); + + } + + /** + * @param ip Server ip address / example : 127.0.0.1 + * @param port Server open port for specific ip address + * */ + @Override + public void joinServer(String ip, int port) { + + } + + @Override + public void generateNewCity() { + city = new City(); + } + +} diff --git a/GameInterface.java b/GameInterface.java new file mode 100644 index 0000000..86e9086 --- /dev/null +++ b/GameInterface.java @@ -0,0 +1,15 @@ +package org.example.interfaces; + +import org.example.models.Character; +import org.example.models.User; + +public interface GameInterface { + void continueGame(User user); + void startGame(User user); + + void joinServer(String ip ,int port); + + void generateNewCity(); + + +} diff --git a/Gender.java b/Gender.java new file mode 100644 index 0000000..a8f0c9b --- /dev/null +++ b/Gender.java @@ -0,0 +1,5 @@ +package org.example.enumerations; + +public enum Gender { + Male,Female +} diff --git a/Industry.java b/Industry.java new file mode 100644 index 0000000..eaa658d --- /dev/null +++ b/Industry.java @@ -0,0 +1,65 @@ +package org.example.models; + +import java.util.ArrayList; +import java.util.List; + +public class Industry extends Property{ + private String title; + private float income; + + protected ArrayList employees = new ArrayList<>(); + + /** + * @param title : A Title for generate Industry @example : Bank extends Industry then title = "Bank" + * @param property : Industry owner should have a Property to create this industry on it + * @param character : Industry owner + * @param income : Each Business has a class like Bank and extends Industry , in super method Enter the desired monthly income amount + * */ + public Industry(String title,Property property,Character character,float income) { + super(property.getScales(),property.getCoordinate(),character); + this.title = title; + this.income = income; + startPaySalary(); + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public float getIncome() { + return income; + } + + public void setIncome(float income) { + this.income = income; + } + + + public ArrayList getEmployee() { + return employees; + } + + public void setEmployee(ArrayList employee) { + this.employees = employee; + } + + public void startPaySalary(){ + Thread thread = new Thread(()->{ + while (true){ + employees.stream().forEach((employee)->{ + employee.paySalary(); + }); + try { + Thread.sleep(10800000); // wait for 1 minute + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + }); + thread.start(); + } +} diff --git a/Job.java b/Job.java new file mode 100644 index 0000000..039d8bf --- /dev/null +++ b/Job.java @@ -0,0 +1,42 @@ +package org.example.models; + +public class Job { + private String title; + private float income; + private String industryId; + + /** + * @param title : Industry title + * @param income : industry The monthly income of its employees + * @param industryId : industry id + * */ + public Job(String title, float income, String industryId) { + this.title = title; + this.income = income; + this.industryId = industryId; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public float getIncome() { + return income; + } + + public void setIncome(float income) { + this.income = income; + } + + public String getIndustryId() { + return industryId; + } + + public void setIndustryId(String industryId) { + this.industryId = industryId; + } +} diff --git a/Life.java b/Life.java new file mode 100644 index 0000000..5f87547 --- /dev/null +++ b/Life.java @@ -0,0 +1,92 @@ +package org.example.defualtSystem; + +import org.example.models.Food; +import org.example.models.Liquid; + +public class Life { + private float food; + private float water; + private float sleep; + + public Life(){ + food = 100.0f; + water=100.0f; + sleep=100.0f; + } + + public Life(float food, float water, float sleep) { + this.food = food; + this.water = water; + this.sleep = sleep; + startConsuming(); + } + + public float getFood() { + return food; + } + + public float getWater() { + return water; + } + + public float getSleep() { + return sleep; + } + + + public void foodConsumption(Food product){ + if(product.available){ + water+=product.getWater(); + food +=product.getFood(); + } + } + + public void liquidConsumption(Liquid product){ + if(product.available){ + water+=product.getLiquid(); + } + } + + + public void startConsuming() { + Thread thread = new Thread(() -> { + while (true) { + consumeFood(0.4f); + consumeWater(0.8f); + consumeSleep(0.7f); + + try { + Thread.sleep(60000); // wait for 1 minute + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + }); + + thread.start(); + } + + private synchronized void consumeFood(float amount) { + if (food >= amount) { + food -= amount; + } else { + System.out.println("Not enough food!"); + } + } + + private synchronized void consumeWater(float amount) { + if (water >= amount) { + water -= amount; + } else { + System.out.println("Not enough water!"); + } + } + + private synchronized void consumeSleep(float amount) { + if (sleep >= amount) { + sleep -= amount; + } else { + System.out.println("Not enough sleep!"); + } + } +} diff --git a/Liquid.java b/Liquid.java new file mode 100644 index 0000000..0d3735f --- /dev/null +++ b/Liquid.java @@ -0,0 +1,16 @@ +package org.example.models; + +public class Liquid { + private final float liquid; + + public boolean available =true; + + public Liquid(float liquid) { + this.liquid = liquid; + } + + public float getLiquid() { + return liquid; + } + +} diff --git a/Manager.java b/Manager.java new file mode 100644 index 0000000..46e4064 --- /dev/null +++ b/Manager.java @@ -0,0 +1,8 @@ +package org.example.models; + +public class Manager extends Employee{ + + public Manager(String username, Industry industry, float baseSalary, BankAccount bankAccount) { + super(username, industry, baseSalary, bankAccount); + } +} diff --git a/Menu.java b/Menu.java new file mode 100644 index 0000000..e8a8ef3 --- /dev/null +++ b/Menu.java @@ -0,0 +1,54 @@ +package org.example; + +import org.example.models.User; + +import java.util.Scanner; + +public class Menu { + + + private static Game game = new Game(); + private static Database database = new Database(); + private static Scanner scanner = new Scanner(System.in); + public static void showMenu() { + + mainMenu(); + + System.out.print("Input number: "); + + String next = scanner.next(); + if (next.equals("1")) { + game.continueGame(loginMenu()); + }else if(next.equals("2")){ + game.startGame(loginMenu()); + }else if (next.equals("3")){ + joinServer(); + }else if (next.equals("4")) + System.exit(0); + } + public static void mainMenu(){ + System.out.println("\nPlease choose one of the options below:\n"); + System.out.println("1. Continue"); + System.out.println("2. Start New Game"); + System.out.println("3. Join Server"); + System.out.println("4. Exit\n"); + } + + public static User loginMenu(){ + + + + return null; + } + + private static void joinServer(){ + System.out.print("\nEnter Server IP Address: "); + String ip = scanner.next(); + System.out.print("Enter Server Port: "); + int port = scanner.nextInt(); + game.joinServer(ip,port); + } + public static void main(String[] args) { + showMenu(); + } +} \ No newline at end of file diff --git a/Municipality.java b/Municipality.java new file mode 100644 index 0000000..851c600 --- /dev/null +++ b/Municipality.java @@ -0,0 +1,33 @@ +package org.example.defualtSystem; + +import org.example.interfaces.MunicipalityInterface; +import org.example.models.Property; + +import java.util.ArrayList; + +public class Municipality implements MunicipalityInterface { + private ArrayList properties; + + public Municipality(){ + generateProperties(); + } + + private void generateProperties() { +// Create an algorithm for generating properties for city + } + + @Override + public Property buyProperty() { + return null; + } + + @Override + public void sellProperty(Property property) { + + } + + @Override + public void showProperties() { + + } +} diff --git a/MunicipalityInterface.java b/MunicipalityInterface.java new file mode 100644 index 0000000..5d8bb97 --- /dev/null +++ b/MunicipalityInterface.java @@ -0,0 +1,11 @@ +package org.example.interfaces; + +import org.example.models.Property; + +public interface MunicipalityInterface { + + // Buy and sell property + Property buyProperty(); + void sellProperty(Property property); + void showProperties(); +} diff --git a/Property.java b/Property.java new file mode 100644 index 0000000..6b18828 --- /dev/null +++ b/Property.java @@ -0,0 +1,37 @@ +package org.example.models; + +public class Property { + private float[] scales; + private float[] coordinate; + private Character owner ; + + public Property(float[] scales, float[] coordinate, Character owner) { + this.scales = scales; + this.coordinate = coordinate; + this.owner = owner; + } + + public float[] getScales() { + return scales; + } + + public void setScales(float[] scales) { + this.scales = scales; + } + + public Character getOwner() { + return owner; + } + + public void setOwner(Character owner) { + this.owner = owner; + } + + public float[] getCoordinate() { + return coordinate; + } + + public void setCoordinate(float[] coordinate) { + this.coordinate = coordinate; + } +} diff --git a/StockMarket.java b/StockMarket.java new file mode 100644 index 0000000..2aff358 --- /dev/null +++ b/StockMarket.java @@ -0,0 +1,63 @@ +package org.example.defualtSystem; + +import java.util.HashMap; +import java.util.Map; +import java.util.Random; + +public class StockMarket{ + private Map users; + + public StockMarket() { + users = new HashMap<>(); + } + + public synchronized void depositCapital(String userName, double amount) { + if (users.containsKey(userName)) { + double currentCapital = users.get(userName); + users.put(userName, currentCapital + amount); + } else { + users.put(userName, amount); + } + } + + public synchronized double getDetail(String userName) { + if (users.containsKey(userName)) { + return users.get(userName); + } else { + return 0.0; + } + } + + public synchronized double withdrawCapital(String userName) { + if (users.containsKey(userName)) { + double amount = users.get(userName); + users.put(userName, 0.0); + return amount; + } else { + return 0.0; + } + } + + public void startMarketSimulation() { + Thread marketThread = new Thread(() -> { + Random random = new Random(); + while (true) { + double change = random.nextDouble() * 0.06 - 0.03; + for (String userName : users.keySet()) { + double capital = users.get(userName); + double newCapital = capital + capital * change; + if (newCapital < 0) { + newCapital = 0; + } + users.put(userName, newCapital); + } + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + }); + marketThread.start(); + } +} diff --git a/User.java b/User.java new file mode 100644 index 0000000..3fc5ef0 --- /dev/null +++ b/User.java @@ -0,0 +1,33 @@ +package org.example.models; + +public class User { + private String username; + private String password; + + public User(String username, String password) { + this.username = username; + this.password = password; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public void sign(String username,String password) + { + setPassword(password); + setUsername(username); + } +}