Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.math.*;
- import java.security.*;
- import java.text.*;
- import java.util.*;
- import java.util.concurrent.*;
- import java.util.function.*;
- import java.util.regex.*;
- import java.util.stream.*;
- import static java.util.stream.Collectors.joining;
- import static java.util.stream.Collectors.toList;
- class ETF {
- List<EtfComponent> components;
- Map<String, Float> componentWeight;
- String name;
- double bid;
- double ask;
- double theoAsk;
- double theoBid;
- String currency;
- public double getBid() {
- return bid;
- }
- public double getAsk() {
- return ask;
- }
- public double getTheoAsk() {
- return theoAsk;
- }
- public double getTheoBid() {
- return theoBid;
- }
- public ETF(List<EtfComponent> components, String name, String currency){
- this.components = components;
- this.name = name;
- this.currency = currency;
- }
- public double calculateBid(){
- // implement theo
- return 0;
- }
- public double calculateAsk(){
- // implement theo
- return 0;
- }
- }
- class EtfComponent {
- double bid;
- double ask;
- String name;
- String currency;
- public double getBid() {
- return bid;
- }
- public void setBid(double bid) {
- this.bid = bid;
- }
- public double getAsk() {
- return ask;
- }
- public void setAsk(double ask) {
- this.ask = ask;
- }
- public EtfComponent(String name, String currency) {
- this.name = name;
- this.currency = currency;
- }
- }
- class Market{
- private static Market market_instance = null;
- List<ETF> etfs;
- List<EtfComponent> components;
- Map<String, Double> exchangeRatesCurrencies;
- private Market(){
- etfs = new ArrayList<>();
- components = new ArrayList<>();
- exchangeRatesCurrencies = new HashMap<>();
- }
- public static Market getMarket(){
- if (market_instance == null){
- market_instance = new Market();
- }
- return market_instance;
- }
- public static void addEtf(ETF etf){
- market_instance.etfs.add(etf);
- }
- public static void addEtfComponent(EtfComponent component){
- market_instance.components.add(component);
- }
- public void updateComponent(String name, double price){
- }
- public void updateCurrencyExchange(String name, double price){
- }
- public void updateEtf(String name, double price){
- }
- }
- class Result {
- /*
- * Complete the 'addEtf' function below.
- *
- * The function accepts following parameters:
- * 1. STRING name
- * 2. STRING currency
- * 3. 2D_STRING_ARRAY components
- */
- public static Market market = Market.getMarket();
- public static void addEtf(String name, String currency, List<List<String>> components) {
- List<EtfComponent> etfComponents = new ArrayList<>();
- for (List<String> component: components) {
- String componentName = component.get(0);
- float componentWeight = Float.parseFloat(component.get(1));
- String componentCurrency = component.get(2);
- etfComponents.add(new EtfComponent(componentName, componentCurrency););
- }
- ETF etf = new ETF(etfComponents, name, currency);
- market.addEtf(etf);
- }
- /*
- * Complete the 'playback' function below.
- *
- * The function accepts 2D_STRING_ARRAY messages as parameter.
- */
- public static void playback(List<List<String>> messages) {
- }
- }
- public class Solution {
- public static void main(String[] args) throws IOException {
- BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
- int NumberOfETF = Integer.parseInt(bufferedReader.readLine().trim());
- IntStream.range(0, NumberOfETF).forEach(NumberOfETFItr -> {
- try {
- String ETFSymbol = bufferedReader.readLine();
- String ETFCurrency = bufferedReader.readLine();
- int NumberOfListingInETF = Integer.parseInt(bufferedReader.readLine().trim());
- List<List<String>> listings = new ArrayList<>();
- IntStream.range(0, NumberOfListingInETF).forEach(i -> {
- try {
- listings.add(
- Stream.of(bufferedReader.readLine().replaceAll("\\s+$", "").split(" "))
- .collect(toList())
- );
- } catch (IOException ex) {
- throw new RuntimeException(ex);
- }
- });
- Result.addEtf(ETFSymbol, ETFCurrency, listings);
- } catch (IOException ex) {
- throw new RuntimeException(ex);
- }
- });
- int NumberOfMessages = Integer.parseInt(bufferedReader.readLine().trim());
- List<List<String>> messages = new ArrayList<>();
- IntStream.range(0, NumberOfMessages).forEach(i -> {
- try {
- messages.add(
- Stream.of(bufferedReader.readLine().replaceAll("\\s+$", "").split(" "))
- .collect(toList())
- );
- } catch (IOException ex) {
- throw new RuntimeException(ex);
- }
- });
- Result.playback(messages);
- bufferedReader.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement