Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String input = scanner.nextLine();
- double sum = 0;
- double coin = 0;
- while (!input.equals("Start")) {
- if (input.equals("0.1")) {
- coin = Double.parseDouble(input);
- sum += coin;
- } else if (input.equals("0.2")) {
- coin = Double.parseDouble(input);
- sum += coin;
- } else if (input.equals("0.5")) {
- coin = Double.parseDouble(input);
- sum += coin;
- } else if (input.equals("1")) {
- coin = Double.parseDouble(input);
- sum += coin;
- } else if (input.equals("2")) {
- coin = Double.parseDouble(input);
- sum += coin;
- } else {
- coin = Double.parseDouble(input);
- System.out.printf("Cannot accept %.2f%n", coin);
- }
- input = scanner.nextLine();
- }
- String product = scanner.nextLine();
- double price = 0;
- while (!product.equals("End")) {
- if (product.equals("Nuts")) {
- price = 2;
- } else if (product.equals("Water")) {
- price = 0.7;
- } else if (product.equals("Crisps")) {
- price = 1.5;
- } else if (product.equals("Soda")) {
- price = 0.8;
- } else if (product.equals("Coke")) {
- price = 1.0;
- } else {
- System.out.println("Invalid product");
- sum += price;
- }
- sum -= price;
- if (sum >= 0) {
- System.out.printf("Purchased %s%n", product);
- } else {
- System.out.println("Sorry, not enough money");
- sum += price;
- }
- product = scanner.nextLine();
- }
- System.out.printf("Change: %.2f", sum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment