Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fundamentalsExam;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Scanner;
- public class helloFrance {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- List<Double> boughtItems = new ArrayList<>();
- String line = scanner.nextLine();
- double budget = Double.parseDouble(scanner.nextLine());
- String[] tokens = line.split("\\|");
- for (int i = 0; i < tokens.length ; i++) {
- int borderIndex = tokens[i].indexOf("->");
- String item = tokens[i].substring(0,borderIndex);
- double price = Double.parseDouble(tokens[i].substring(borderIndex + 2));
- switch (item) {
- case "Clothes":
- double maxPrice = 50;
- if (price <= maxPrice) {
- double purchase = budget - price;
- if (purchase >= 0) {
- boughtItems.add(price);
- budget -= price;
- }
- }
- break;
- case "Shoes":
- maxPrice = 35;
- if (price <= maxPrice) {
- double purchase = budget - price;
- if (purchase >= 0) {
- boughtItems.add(price);
- budget -= price;
- }
- }
- break;
- case "Accessories":
- maxPrice = 20.50;
- if (price <= maxPrice) {
- double purchase = budget - price;
- if (purchase >= 0) {
- boughtItems.add(price);
- budget -= price;
- }
- }
- break;
- }
- }
- double profit = 0;
- int index = 0;
- double sumNewPrices = 0d;
- for(double item : boughtItems){
- if(boughtItems.get(index) == 0){
- profit += 0.4;
- boughtItems.set(index,0.4);
- sumNewPrices += boughtItems.get(index);
- index++;
- }else {
- profit += boughtItems.get(index) * 0.40;
- boughtItems.set(index, boughtItems.get(index) * 1.40);
- sumNewPrices += boughtItems.get(index);
- index++;
- }
- }
- boughtItems.forEach(e -> System.out.printf("%.2f ",e));
- System.out.println();
- System.out.printf("Profit: %.2f%n",profit);
- if(profit + sumNewPrices >= 150){
- System.out.println("Hello, France!");
- }else{
- System.out.println("Time to go.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement