0
//import java scanner, random, text
import java.util.Random;
import java.util.Scanner;
import java.util.*;
import java.text.DecimalFormat;


class Main {
  public static void change()
  {   
    Scanner scan = new Scanner(System.in);
    Random generator = new Random();
    DecimalFormat currency = new DecimalFormat("$0.00");
    String name;
    double price,salePrice,tax,saleWTax,percent;
    int price2, provided, change, newPrice;
    
    System.out.println("What is the item you plan to buy?");
    name = scan.nextLine();
    System.out.println("What is the original price for "+name);
    price = scan.nextDouble();
    scan.nextLine();
    percent = (generator.nextInt(5)+7)*5;
        
    System.out.println("You will recieve "+ percent + "% off "+name+"!");
    salePrice = price-(price*(percent/100));
        
    System.out.println("The sale price for "+name+" is "+currency.format(salePrice));
    tax = price*.07;
    System.out.println("The tax on "+name+" is "+currency.format(tax));
    saleWTax= salePrice+tax;
    System.out.println("The total price you owe is "+currency.format(saleWTax));
    newPrice = scan.nextInt();
     
    saleWTax = (int) Math.round(saleWTax*100);
    System.out.println("Enter the amount given by the customer:");
    provided = (int) Math.round(scan.nextDouble()*100);
        
      if (provided > newPrice) {
        System.out.println("The change is: " + ((provided-newPrice)/100.00));
        System.out.println("The customer should be given the change as follows:");
        change = provided-newPrice;
            
        int dollars = change / 100;
        if (dollars > 0) {
          change = change % 100;
          System.out.println(dollars + " $1 bill(s)");
        }
            
        int quarters = change / 25;
        if (quarters > 0) {
          change = change % 25;
          System.out.println(quarters + " quarter(s)");
        }
            
        int dimes = change / 10;
        if (dimes > 0) {
          change = change % 10;
          System.out.println(dimes + " dime(s)");
        }
            
        int nickels = change / 5;
        if (nickels > 0) {
          change = change % 5;
          System.out.println(nickels + " nickel(s)");
        }
        int pennies = change;
        System.out.println(pennies + " penny coin(s)");
        }
      if (provided < price) { 
        System.out.print("Not enough money!");
      }   
      else if (provided == price) { 
        System.out.print("No change is necessary");
      }
    }
  public static void main(String[] args) {
    Main prog = new Main();
    //prog.calcPrice();
    Main.change();
    
  }
}

It stops printing after it tells the user how much they owe. Does anyone know what to do? And it also stops working with the amount of change it is suppose to give back. I guess it isn't finding the variables, but I'm very confused on how to fix this. I think I might need to do something with the variables in the beginning to make them more clear but I'm not sure.

kcash
  • 1
  • @HovercraftFullOfEels I don't see how that duplicate applies to this question. – Tom May 17 '21 at 12:01
  • *"It stops printing after it tells the user how much they owe"* ... it does because it expects input from you. – Tom May 17 '21 at 12:02

0 Answers0