Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

# Thread: Beginner Java Assignment Help (Calculations/Conversions)

1. ## Beginner Java Assignment Help (Calculations/Conversions)

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.

2. ## Re: Beginner Java Assignment Help (Calculations/Conversions)

Try working out how to do this using your native currency first. Once you have that working then convert it to G S K!

(Shekel for an ex-leper?)

3. ## Re: Beginner Java Assignment Help (Calculations/Conversions)

I think the instructions are confusing. As Junky said, if you were to do this using the currency you're familiar with, you might create variables for nickel, dime, and quarter. It's useful to know that a dime represents 2 nickels or that a quarter represents 5 nickels or 2 dimes + 1 nickel, etc., but knowing that doesn't change how the variables are created.

Create variables to represent Galleon and Sickle and know that the conversion from Galleon to Sickle is

1 Galleon / 17 Sickles

and use that conversion to make change or as the program requires.