Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions App.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.example;

/**
* Hello world!
*
*/
public class App {
public static void main( String[] args )
{
System.out.println( "Hello World!" );
}
}
38 changes: 38 additions & 0 deletions AppTest.java
Original file line number Diff line number Diff line change
@@ -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 );
}
}
44 changes: 44 additions & 0 deletions Bank.java
Original file line number Diff line number Diff line change
@@ -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<BankAccount> accounts = new ArrayList<BankAccount>();

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";
}
}
72 changes: 72 additions & 0 deletions BankAccount.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
4 changes: 4 additions & 0 deletions BankInterface.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package org.example.interfaces;

public interface BankInterface {
}
20 changes: 20 additions & 0 deletions BankTurnover.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
74 changes: 74 additions & 0 deletions Character.java
Original file line number Diff line number Diff line change
@@ -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<Property> properties;
private Property inPosition;

public Character(User userInfo, BankAccount account, Life life, Job job, ArrayList<Property> 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<Property> getProperties() {
return properties;
}

public void setProperties(ArrayList<Property> properties) {
this.properties = properties;
}

@Override
public void positionProcessing() {

}
}
6 changes: 6 additions & 0 deletions CharacterInterface.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.example.interfaces;

public interface CharacterInterface {
void positionProcessing();

}
66 changes: 66 additions & 0 deletions City.java
Original file line number Diff line number Diff line change
@@ -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<Character> 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 ,<b > DO NOT CHANGE THIS FUNCTION STRUCTURE</b> ,
*
* */
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();
}
}
9 changes: 9 additions & 0 deletions CityInterface.java
Original file line number Diff line number Diff line change
@@ -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();
}
Loading