Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.56 KB | None | 0 0
  1. import java.io.*;
  2. import java.math.*;
  3. import java.security.*;
  4. import java.text.*;
  5. import java.util.*;
  6. import java.util.concurrent.*;
  7. import java.util.function.*;
  8. import java.util.regex.*;
  9. import java.util.stream.*;
  10. import static java.util.stream.Collectors.joining;
  11. import static java.util.stream.Collectors.toList;
  12.  
  13.  
  14. class ETF {
  15.  
  16. List<EtfComponent> components;
  17. Map<String, Float> componentWeight;
  18. String name;
  19. double bid;
  20. double ask;
  21. double theoAsk;
  22. double theoBid;
  23. String currency;
  24.  
  25. public double getBid() {
  26. return bid;
  27. }
  28.  
  29. public double getAsk() {
  30. return ask;
  31. }
  32.  
  33. public double getTheoAsk() {
  34. return theoAsk;
  35. }
  36.  
  37. public double getTheoBid() {
  38. return theoBid;
  39. }
  40.  
  41. public ETF(List<EtfComponent> components, String name, String currency){
  42. this.components = components;
  43. this.name = name;
  44. this.currency = currency;
  45. }
  46.  
  47. public double calculateBid(){
  48. // implement theo
  49. return 0;
  50. }
  51.  
  52. public double calculateAsk(){
  53. // implement theo
  54. return 0;
  55. }
  56.  
  57. }
  58.  
  59. class EtfComponent {
  60.  
  61. double bid;
  62. double ask;
  63. String name;
  64. String currency;
  65.  
  66.  
  67. public double getBid() {
  68. return bid;
  69. }
  70.  
  71. public void setBid(double bid) {
  72. this.bid = bid;
  73. }
  74.  
  75. public double getAsk() {
  76. return ask;
  77. }
  78.  
  79. public void setAsk(double ask) {
  80. this.ask = ask;
  81. }
  82.  
  83.  
  84. public EtfComponent(String name, String currency) {
  85. this.name = name;
  86. this.currency = currency;
  87. }
  88.  
  89.  
  90.  
  91.  
  92. }
  93.  
  94. class Market{
  95.  
  96. private static Market market_instance = null;
  97. List<ETF> etfs;
  98. List<EtfComponent> components;
  99. Map<String, Double> exchangeRatesCurrencies;
  100.  
  101. private Market(){
  102. etfs = new ArrayList<>();
  103. components = new ArrayList<>();
  104. exchangeRatesCurrencies = new HashMap<>();
  105. }
  106.  
  107. public static Market getMarket(){
  108. if (market_instance == null){
  109. market_instance = new Market();
  110. }
  111. return market_instance;
  112. }
  113.  
  114. public static void addEtf(ETF etf){
  115. market_instance.etfs.add(etf);
  116. }
  117.  
  118. public static void addEtfComponent(EtfComponent component){
  119. market_instance.components.add(component);
  120. }
  121.  
  122. public void updateComponent(String name, double price){
  123. }
  124.  
  125. public void updateCurrencyExchange(String name, double price){
  126.  
  127. }
  128.  
  129. public void updateEtf(String name, double price){
  130.  
  131. }
  132.  
  133. }
  134.  
  135.  
  136. class Result {
  137.  
  138.  
  139. /*
  140. * Complete the 'addEtf' function below.
  141. *
  142. * The function accepts following parameters:
  143. * 1. STRING name
  144. * 2. STRING currency
  145. * 3. 2D_STRING_ARRAY components
  146. */
  147.  
  148. public static Market market = Market.getMarket();
  149.  
  150.  
  151. public static void addEtf(String name, String currency, List<List<String>> components) {
  152. List<EtfComponent> etfComponents = new ArrayList<>();
  153. for (List<String> component: components) {
  154.  
  155. String componentName = component.get(0);
  156. float componentWeight = Float.parseFloat(component.get(1));
  157. String componentCurrency = component.get(2);
  158. etfComponents.add(new EtfComponent(componentName, componentCurrency););
  159.  
  160. }
  161.  
  162. ETF etf = new ETF(etfComponents, name, currency);
  163. market.addEtf(etf);
  164.  
  165. }
  166.  
  167. /*
  168. * Complete the 'playback' function below.
  169. *
  170. * The function accepts 2D_STRING_ARRAY messages as parameter.
  171. */
  172.  
  173. public static void playback(List<List<String>> messages) {
  174.  
  175. }
  176.  
  177. }
  178.  
  179. public class Solution {
  180. public static void main(String[] args) throws IOException {
  181. BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
  182.  
  183. int NumberOfETF = Integer.parseInt(bufferedReader.readLine().trim());
  184.  
  185. IntStream.range(0, NumberOfETF).forEach(NumberOfETFItr -> {
  186. try {
  187. String ETFSymbol = bufferedReader.readLine();
  188.  
  189. String ETFCurrency = bufferedReader.readLine();
  190.  
  191. int NumberOfListingInETF = Integer.parseInt(bufferedReader.readLine().trim());
  192.  
  193. List<List<String>> listings = new ArrayList<>();
  194.  
  195. IntStream.range(0, NumberOfListingInETF).forEach(i -> {
  196. try {
  197. listings.add(
  198. Stream.of(bufferedReader.readLine().replaceAll("\\s+$", "").split(" "))
  199. .collect(toList())
  200. );
  201. } catch (IOException ex) {
  202. throw new RuntimeException(ex);
  203. }
  204. });
  205.  
  206. Result.addEtf(ETFSymbol, ETFCurrency, listings);
  207. } catch (IOException ex) {
  208. throw new RuntimeException(ex);
  209. }
  210. });
  211.  
  212. int NumberOfMessages = Integer.parseInt(bufferedReader.readLine().trim());
  213.  
  214. List<List<String>> messages = new ArrayList<>();
  215.  
  216. IntStream.range(0, NumberOfMessages).forEach(i -> {
  217. try {
  218. messages.add(
  219. Stream.of(bufferedReader.readLine().replaceAll("\\s+$", "").split(" "))
  220. .collect(toList())
  221. );
  222. } catch (IOException ex) {
  223. throw new RuntimeException(ex);
  224. }
  225. });
  226.  
  227. Result.playback(messages);
  228.  
  229. bufferedReader.close();
  230. }
  231. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement