Here are the instructions to my assignment:
A shopkeeper in Diagon Alley needs you to write a program that will calculate the
correct amount of change due to a customer. (In Diagon Alley they use three coins with
different values, given below).
1. Prompt the user to input the amount of sale in Galleons, Sickles, and Knuts.
2. Prompt the user to input the amount of money given by the customer in Galleons,
Sickles, and Knuts.
3. Create constants that represent:
a. 1 Galleon = 17 Sickles
b. 1 Sickle = 29 Knuts
4. Perform the necessary calculations and conversions to compute the correct change
in the least number of coins.
Here are what is steps 1 and 2 but i need help with are 3 and 4. I need to create the constants and use proper conversions to give the right amount of change back.
import java.util.Scanner; public class OperatorFormatting { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Welcome to Flourish and Blotts"); System.out.print("Enter amount of sale (G S K): "); int saleGalleon = input.nextInt(); int saleSickle = input.nextInt(); int saleKnut = input.nextInt(); System.out.print("Enter amount tendered (G S K): "); int tendGalleon = input.nextInt(); int tendSickle = input.nextInt(); int tendKnut = input.nextInt(); System.out.println(); System.out.println("*************************************************"); System.out.println("* Flourish & Blotts *"); System.out.println("* *"); System.out.println("* Amt of Sale ....... " + saleGalleon + " G " + saleSickle + " S " + saleKnut + " K *"); System.out.println("* Amt Received ...... " + tendGalleon + " G " + tendSickle + " S " + tendKnut + " K *"); System.out.println("* Change Due ........ " + galleonChange + " G " + sickleChange + " S " + knutChange + " K *"); System.out.println("* *"); System.out.println("* Thank You For Shopping at Flourish and Blotts *"); System.out.println("*************************************************"); } }
Basically, I need Help on steps 3 and 4 which are creating the constants and using the to make the proper conversions to give the customer the proper amount of change Due. Any help would be appreciated thank you.