Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package finalExamPrep;
- import java.util.HashMap;
- import java.util.LinkedHashMap;
- import java.util.Map;
- import java.util.Scanner;
- public class VaparWinterSale {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- Map<String,Double>gamesPrice=new LinkedHashMap<>();
- Map<String,String>gameWithDlC=new LinkedHashMap<>();
- String[]input=scanner.nextLine().split(", ");
- for (String game:input) {
- if (game.contains("-")){
- String[]data=game.split("-");
- String gameName=data[0];
- double price=Double.parseDouble(data[1]);
- gamesPrice.put(gameName,price);
- }else if (game.contains(":")){
- String[]data=game.split(":");
- String gameName=data[0];
- String DLC=data[1];
- if (gamesPrice.containsKey(gameName)){
- gameWithDlC.put(gameName,DLC);
- gamesPrice.put(gameName,gamesPrice.get(gameName)*1.2);
- }
- }
- }
- for (Map.Entry<String, Double> entry : gamesPrice.entrySet()) {
- if (gameWithDlC.containsKey(entry.getKey())){
- gamesPrice.put(entry.getKey(),entry.getValue()*0.50);
- }else {
- gamesPrice.put(entry.getKey(),entry.getValue()*0.80);
- }
- }
- gamesPrice.entrySet().stream()
- .sorted((p1,p2)-> Double.compare(p1.getValue(),p2.getValue()))
- .forEach(e->{
- if (gameWithDlC.containsKey(e.getKey())){
- System.out.println(String
- .format("%s - %s - %.2f",e.getKey(),gameWithDlC.get(e.getKey()),e.getValue()));
- }
- });
- gamesPrice.entrySet().stream()
- .sorted((p1,p2)->Double.compare(p2.getValue(),p1.getValue()))
- .forEach(e->{
- if (!gameWithDlC.containsKey(e.getKey())){
- System.out.println(String.format("%s - %.2f",e.getKey(),e.getValue()));
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement