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