Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a Visual Basic program to use counters and accumulators. Zip your files.

ID: 3889042 • Letter: C

Question

Create a Visual Basic program to use counters and accumulators. Zip your files. Submit the program before the 5:00 deadline Name your project using your initials and the number of the program Write a program to count spare change. Create a variable to keep track of the value of the coins. Create another variable to keep track of the number of coins. The Penny Button should add one to the number of coins and add one cent to the value. The Nickel Button should add one to the number of coins and add five cents to the value. The Dime Button should add one to the number of coins and add ten cents to the value. The Quarter Button should add one to the number of coins and add twenty-five cents to the value Display both values with each click. Format the output. Make sure your counter and accumulator are correct. Create a Reset Button to clear the counter and accumulator and the Labels. Create an Exit Button to end the program Use the proper naming conventions for all controls and variables Include a prologue and comment your code Be sure to: Scoring . include comments and a prologue . create and code all the Buttons include a working Exit Button . include a working Reset Button properly code all counters properly code all accumulators comment your code insert the icon in the Titlebar . include a prologue at the top of the code make the output neat .properly name all controls properly name all variables submit the all required files comments and prologue create and code all Buttons correctly displays counter and accumulator correctly calculates all values working Exit and Reset Buttons properly named controls properly named variables Total 10

Explanation / Answer

import javax.swing.JOptionPane; public class Project { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub double amountGiven = 0; double changeGiven = 0; double amountNeeded = 0; final double final double FIVE_CENT = 0.05; final double TEN_CENT = 0.10; final double TWENTYFIVE_CENT = 0.25; final int final int FIVE_DOLLAR = 5; final int TEN_DOLLAR = 10; final int TWENTY_DOLLAR = 20; amountNeeded = Double.parseDouble(JOptionPane.showInputDialog(null, "Please enter the cost for an item!")); JOptionPane.showMessageDialog(null, "The customer needs to pay: $" + amountNeeded); amountGiven = Double.parseDouble(JOptionPane.showInputDialog(null, "Please enter an amount a customer payed!")); final double tempDouble = amountGiven; changeGiven = Math.round(tempDouble - amountNeeded); int billBack20 = (int) (tempDouble / TWENTY_DOLLAR); int billBack10 = (int) (tempDouble / TEN_DOLLAR); int billBack5 = (int) (tempDouble / FIVE_DOLLAR); int billBack1 = (int) (tempDouble / ONE_DOLLAR); int coinBack25 = (int) (tempDouble / TWENTYFIVE_CENT); int coinBack10 = (int) (tempDouble / TEN_CENT); int coinBack5 = (int) (tempDouble / FIVE_CENT); int coinBack1 = (int) (tempDouble / ONE_CENT); if ( changeGiven < 0 == true ) { JOptionPane.showMessageDialog(null, "Stop being cheap, and pay up!"); if ( changeGiven < 0 == false ) JOptionPane.showMessageDialog(null, "The amount you will get back is: " + changeGiven);} JOptionPane.showMessageDialog(null, "You will be given back: " + "Twenty Dollar Bills:" + billBack20 + " Ten Dollar Bills:" + billBack10 + " Five Dollar Bills:" + billBack5 + " One Dollar Bills:" + billBack1 + " and" + " Twentyfive Cents:" + coinBack25 + " Ten Cents:" + coinBack10 + " Five Cents:" + coinBack5 + " One Cents:" + coinBack1); } }