interviu accesa

-
mail@pastecode.io avatar
unknown
java
a year ago
1.9 kB
1
Indexable
Never
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {
    private static Map<String, Double> PRICE_REPO = new HashMap<>();

    static {
        PRICE_REPO.put("USD_EUR", 0.9);
        PRICE_REPO.put("ETH_EUR", 2010.4);
        PRICE_REPO.put("ETH_BTC", 0.11);
        PRICE_REPO.put("ETH_USD", 2100.0);
        PRICE_REPO.put("BTC_USD", 42233.0);
    }

    class Liquidity {
        Double value;
        String currency;

        Liquidity(Double value, String currency) {
          
            this.value = value;
            this.currency = currency;
        }
    }

    class Wallet {
        List<Liquidity> liquidityList;
    }

    public Double getEstimatedPrice(String currencyIn, String currencyOut) {
      return PRICE_REPO.GET(currencyIn + "_" + currencyOut);
      
    	//your code here as well 
    }

    public Double computeWalletValue(Wallet wallet, String currencyOut) {
      foreach(Liquidity item : wallet.liquidityList){
      
      }
        /your code here as well 
    }

    /**
     * DO NOT CHANGE CODE BELOW THIS LINE
     */
    public static void main(String[] args) {
        Main app = new Main();
        Wallet w1 = app.new Wallet();
        Scanner keyboard = new Scanner(System.in);
        String input = keyboard.nextLine();
        String[] split = input.split(";");
        String[] parts = split[0].split(" ");
        w1.liquidityList = IntStream.range(0, parts.length / 2).map(i -> i * 2).mapToObj((i) -> app.new Liquidity(Double.parseDouble(parts[i]), parts[i + 1])).collect(Collectors.toList());
        Double output = app.computeWalletValue(w1, split[1]);
        System.out.printf("%.2f%n", output);
    }
}