Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import javax.print.DocFlavor;
- import java.text.DecimalFormat;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.List;
- import java.util.Scanner;
- import java.util.stream.Collectors;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- List<String> secondList = new ArrayList<>();
- List<String> list = Arrays.stream(scanner.nextLine().split("[\\|\\-\\>]"))
- .collect(Collectors.toList());
- for (int i = 0; i <list.size() ; i++) {
- if (list.get(i).equals("")){
- list.remove(list.get(i));
- }
- }
- Double budget = Double.parseDouble(scanner.nextLine());
- Double clothesMax = 50.00;
- Double shoesMax = 35.00;
- Double accessoriesMax = 20.50;
- Double profit = 0.00;
- DecimalFormat df= new DecimalFormat("#.00");
- String price2 = "";
- Double totalProfit = 0.00;
- Double totalBudget = 0.00;
- System.out.println();
- for (int i = 1; i <list.size() ; i+=2) {
- String priceItem = list.get(i);
- Double price = Double.parseDouble(priceItem);
- if (list.get(i-1).equals("Clothes")){
- if (price <= clothesMax && budget>=price){
- budget -= price;
- profit = price + 0.40*price;
- price2 = String.valueOf(df.format(profit));
- secondList.add(price2);
- totalProfit +=(profit-price);
- totalBudget += profit;
- }
- }
- if (list.get(i-1).equals("Shoes")){
- if (price <= shoesMax && budget>=price){
- budget -= price;
- profit = price + 0.40*price;
- price2 = String.valueOf(df.format(profit));
- secondList.add(price2);
- totalProfit +=(profit-price);
- totalBudget += profit;
- }
- }
- if (list.get(i-1).equals("Accessories")){
- if (price <= accessoriesMax && budget>=price){
- budget -= price;
- profit = price + 0.40*price;
- price2 = String.valueOf(df.format(profit));
- secondList.add(price2);
- totalProfit +=(profit-price);
- totalBudget += profit;
- }
- }
- }
- totalBudget +=budget;
- System.out.println(secondList.toString()
- .replace(",", "")
- .replace("[", "")
- .replace("]", "")
- .trim());
- System.out.printf("Profit: %.2f\n",totalProfit);
- if (totalBudget <150){
- System.out.println("Time to go.");
- }else {
- System.out.println("Hello, France!");
- }
- }
- }
Advertisement
RAW Paste Data
Copied
Advertisement