Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class HelloFrance {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String[] items = scanner.nextLine().split("[|]");
- double budget = Double.parseDouble(scanner.nextLine());
- double clothesMaxPrice = 50;
- double shoesMaxPrice = 35;
- double accessoriesMaxPrice = 20.50;
- double neededMoney = 150;
- double newPrice = 0;
- double sumOfPrices = 0;
- double sumOfNewPrices = 0;
- double profit = 0;
- boolean isBought = true;
- for (int i = 0; i < items.length ; i++) {
- String[] itemType = items[i].split("->");
- String type = itemType[0];
- double price = Double.parseDouble(itemType[1]);
- if ("Clothes".equals(type)){
- if (price <= clothesMaxPrice && price <= budget){
- sumOfPrices += price;
- budget -= price;
- newPrice = price * 1.40;
- sumOfNewPrices += newPrice;
- isBought = true;
- } else {
- isBought = false;
- //break;
- }
- } else if ("Shoes".equals(type)){
- if (price <= shoesMaxPrice && price <= budget){
- sumOfPrices += price;
- budget -= price;
- newPrice = price * 1.40;
- sumOfNewPrices += newPrice;
- isBought = true;
- } else {
- isBought = false;
- //break;
- }
- } else if ("Accessories".equals(type)){
- if (price <= accessoriesMaxPrice && price <= budget){
- sumOfPrices += price;
- budget -= price;
- newPrice = price * 1.40;
- sumOfNewPrices += newPrice;
- isBought = true;
- } else {
- isBought = false;
- // break;
- }
- }
- if (isBought) {
- System.out.printf("%.2f ", newPrice);
- }
- }
- profit = sumOfNewPrices - sumOfPrices;
- System.out.println();
- System.out.printf("Profit: %.2f%n", profit);
- if ((sumOfNewPrices + budget) >= neededMoney){
- System.out.println("Hello, France!");
- } else {
- System.out.println("Time to go.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment