Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package O1ExamMid10MArch;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.ArrayList;
- import java.util.List;
- public class Problem02 {
- public static void main(String[] args) throws IOException {
- BufferedReader reader =
- new BufferedReader(
- new InputStreamReader(
- System.in
- )
- );
- String input = reader.readLine();
- double budget = Double.parseDouble(reader.readLine());
- String[] itemsString = input.split("\\|");
- double addThis = 0;
- double profit = 0.0;
- List<String> items = new ArrayList<>();
- for (int i = 0; i < itemsString.length; i++) {
- String[] token = itemsString[i].split("->") ;
- String item = token[0].toLowerCase();
- double priceItem = Double.parseDouble(token[1]);
- switch (item) {
- case "clothes" :
- if (priceItem<=50.00 && priceItem <= budget) {
- budget -= priceItem;
- profit += priceItem*1.4 - priceItem;
- addThis += priceItem*1.4;
- items.add(String.format("%.2f",priceItem*1.4 ));
- }
- break;
- case "shoes" :
- if (priceItem<=35.00 && priceItem <= budget) {
- budget -= priceItem;
- profit += priceItem*1.4- priceItem;
- addThis += priceItem*1.4;
- items.add(String.format("%.2f",priceItem*1.4 ));
- }
- break;
- case "accessories" :
- if (priceItem<=20.50 && priceItem <= budget) {
- budget -= priceItem;
- profit += priceItem*1.4- priceItem;
- addThis += priceItem*1.4;
- items.add(String.format("%.2f",priceItem*1.4 ));
- }
- break;
- default:
- break;
- }
- }
- System.out.println(items
- .toString()
- .replaceAll("[\\[|,\\]]", "")
- .trim());
- System.out.println(String.format("Profit: %.2f", profit));
- if (budget + addThis>= 150) {
- System.out.println("Hello, France!");
- } else {
- System.out.println("Time to go.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment