CONVERT TO PYTHON LANGUAGE ONLY import java.util.InputMismatchException; import java.util.Scanner;   public class CandyMachine {    public static void main(String[] args) {        System.out.println("*** Welcome to Shelly's Candy Shop ***");               // Creating dispenser objects:        ProductDispenser Candy = new ProductDispenser(0.50, 12);        ProductDispenser Chips = new ProductDispenser(0.65, 12);        ProductDispenser Gum = new ProductDispenser(0.45, 12);        ProductDispenser Cookies = new ProductDispenser(0.85, 12);               // Creating cash register object:        CashRegister CR = new CashRegister();    // For selection of item        int select = 0;        do {                      select = getIntInput("\n To select an item, enter \n" + "1 for Candy\n"                    + "2 for Chips\n" + "3 for Gum\n" + "4 for Cookies\n"                    + "9 to exit \n");            switch (select) {            case 1:                purchase(Candy, CR);                break;            case 2:                purchase(Chips, CR);                break;            case 3:                purchase(Gum, CR);                break;            case 4:                purchase(Cookies, CR);                break;            case 9:                break;            default:                System.out.println("Invalid Selection");            }        } while (select != 9);    }      // Method to execute a purchase:    public static void purchase(ProductDispenser product, CashRegister cashreg) {        Scanner input = new Scanner(System.in);        if (product.getProdQty() > 0) {            double pmt = 0;            // Collection of coin to purchase product.            do {                System.out.print("Please deposit "                        + (product.getProdCost() * 100 - pmt) + " cents.");                pmt += input.nextDouble();            } while (pmt < product.getProdCost() * 100);            product.setProdQty(1);            cashreg.setCashOnHand(product.getProdCost());            System.out.println("Collect your item at the bottom and enjoy.");        }    }      // Method for Input Selection    public static int getIntInput(String prompt) {        Scanner input = new Scanner(System.in);        System.out.print(prompt);        int intValue = 0;        try {                      intValue = input.nextInt();        } catch (InputMismatchException e) {            System.out.println("*** That is not a number. ***");        }              return intValue;    } }   // CashRegister method class CashRegister {       private double cashOnHand;         CashRegister() {                               cashOnHand = 0;    }    double getCashOnHand() {        return cashOnHand;    }    void setCashOnHand(double purchase) {        cashOnHand += purchase;    } }     class ProductDispenser {      private double prodCost;    private int prodQty;         ProductDispenser(double cost, int qty) {        prodCost = cost;        prodQty = qty;    }    double getProdCost() {        return prodCost;    }    int getProdQty() {        return prodQty;    }    void setProdQty(int qty) {        prodQty -= qty;    } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

CONVERT TO PYTHON LANGUAGE ONLY

import java.util.InputMismatchException;

import java.util.Scanner;

 

public class CandyMachine {

   public static void main(String[] args) {

       System.out.println("*** Welcome to Shelly's Candy Shop ***");

      

       // Creating dispenser objects:

       ProductDispenser Candy = new ProductDispenser(0.50, 12);

       ProductDispenser Chips = new ProductDispenser(0.65, 12);

       ProductDispenser Gum = new ProductDispenser(0.45, 12);

       ProductDispenser Cookies = new ProductDispenser(0.85, 12);

      

       // Creating cash register object:

       CashRegister CR = new CashRegister();

  

// For selection of item

       int select = 0;

       do {          

           select = getIntInput("\n To select an item, enter \n" + "1 for Candy\n"

                   + "2 for Chips\n" + "3 for Gum\n" + "4 for Cookies\n"

                   + "9 to exit \n");

           switch (select) {

           case 1:

               purchase(Candy, CR);

               break;

           case 2:

               purchase(Chips, CR);

               break;

           case 3:

               purchase(Gum, CR);

               break;

           case 4:

               purchase(Cookies, CR);

               break;

           case 9:

               break;

           default:

               System.out.println("Invalid Selection");

           }

       } while (select != 9);

   }

 

   // Method to execute a purchase:

   public static void purchase(ProductDispenser product, CashRegister cashreg) {

       Scanner input = new Scanner(System.in);

       if (product.getProdQty() > 0) {

           double pmt = 0;

           // Collection of coin to purchase product.

           do {

               System.out.print("Please deposit "

                       + (product.getProdCost() * 100 - pmt) + " cents.");

               pmt += input.nextDouble();

           } while (pmt < product.getProdCost() * 100);

           product.setProdQty(1);

           cashreg.setCashOnHand(product.getProdCost());

           System.out.println("Collect your item at the bottom and enjoy.");

       }

   }

 

   // Method for Input Selection

   public static int getIntInput(String prompt) {

       Scanner input = new Scanner(System.in);

       System.out.print(prompt);

       int intValue = 0;

       try {          

           intValue = input.nextInt();

       } catch (InputMismatchException e) {

           System.out.println("*** That is not a number. ***");

       }      

       return intValue;

   }

}

 

// CashRegister method

class CashRegister {

  

   private double cashOnHand;

 

  

   CashRegister() {                       

       cashOnHand = 0;

   }

   double getCashOnHand() {

       return cashOnHand;

   }

   void setCashOnHand(double purchase) {

       cashOnHand += purchase;

   }

}

 

 

class ProductDispenser {

 

   private double prodCost;

   private int prodQty;

 

  

   ProductDispenser(double cost, int qty) {

       prodCost = cost;

       prodQty = qty;

   }

   double getProdCost() {

       return prodCost;

   }

   int getProdQty() {

       return prodQty;

   }

   void setProdQty(int qty) {

       prodQty -= qty;

   }

}

Expert Solution
steps

Step by step

Solved in 2 steps with 4 images

Blurred answer
Knowledge Booster
Adjacency Matrix
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education