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


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Beginner Java Assignment Help (Calculations/Conversions)

  1. #1
    Junior Member
    Join Date
    Sep 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.
    Last edited by jlcarrillo; September 18th, 2014 at 12:39 AM.


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default 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?)
    Improving the world one idiot at a time!

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default 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.

Similar Threads

  1. [SOLVED] Beginner Java Course, Stuck on my First Assignment. Help Needed.
    By jlcarrillo in forum Object Oriented Programming
    Replies: 5
    Last Post: February 18th, 2018, 07:37 PM
  2. Beginner Java Assignment..Help!
    By nessabenz in forum What's Wrong With My Code?
    Replies: 0
    Last Post: February 12th, 2014, 07:47 PM
  3. Beginner,first java program assignment
    By geezlouise in forum What's Wrong With My Code?
    Replies: 7
    Last Post: January 31st, 2013, 08:36 PM
  4. Help with a beginner's java assignment: Survey results
    By lavloki in forum Java Theory & Questions
    Replies: 17
    Last Post: October 14th, 2010, 09:08 AM
  5. Beginner needs help with simple java assignment.
    By joachim89 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 6th, 2010, 07:53 PM