Results 1 to 9 of 9
  1. #1
    Jack199191 is offline Member
    Join Date
    Nov 2013
    Posts
    4
    Rep Power
    0

    Default Help me with this bank teller please!

    HI, I can not get the fifty pence or any other coins working on this program. Will someone please help me, I know it will be pretty straight forward but it is seriously bugging me now. Thank you

    Java Code:
    public class BankTeller {
      public static void main(String args[]) {
        float Sterling = 289.90f;
        float Total = Sterling;
        String indent = " ";
        int Hunderds, Fifties , Twenties, Tens, Fives, Ones;
        float Fiftyp, Tenp;
        //all of the notes are working fine as shown in the output.
        Hunderds =  (int) Sterling / 100;
        Sterling = (int) Sterling % 100;
        Fifties = (int) Sterling / 50;
        Sterling = Sterling % 50;
        Twenties = (int) Sterling / 20;
        Sterling = Sterling % 20;
        Tens = (int) Sterling / 10;
        Sterling = Sterling % 10;
        Fives = (int) Sterling / 5;
        Sterling = Sterling % 5;
        Ones = (int) Sterling / 1;
        Sterling = (int) Sterling % 1;
        // In the code below it should be working out how many Fifty pence coins are required, the same goes for ten pence coins. 
        //I might be on the wrong wave length completely 
        Sterling = Sterling * 100;
        Fiftyp = (float) (Sterling / 0.5);// noting shows in the output.
        Sterling = Sterling % 50;
        Tenp = (float) (Sterling / 0.1);
        Sterling = Sterling % 100;
        // I do not know if i am approaching this is the right way
        System.out.println("The notes and coins required are :");
        System.out.println();
        System.out.println(indent + "Hunderds : " + Hunderds);
        System.out.println(indent + "Fifties : " + Fifties);
        System.out.println(indent + "Twenties : " + Twenties);
        System.out.println(indent + "Tens : " + Tens);
        System.out.println(indent + "Fives : " + Fives);
        System.out.println(indent + "One pound coin :" + Ones);
        System.out.println(indent + "Fifty Pence :" + Fiftyp);
        System.out.println(indent + "Ten Pence :" + Tenp);
        System.out.println();
        System.out.println("Total: " + Total + " pounds");
      }
    }
    The output is:
    The notes and coins required are :

    Hunderds : 2
    Fifties : 1
    Twenties : 1
    Tens : 1
    Fives : 1
    One pound coin :4
    Fifty Pence :0.0
    Ten Pence :0.0

    Total: 289.9 pounds
    Last edited by Jack199191; 11-27-2013 at 06:01 PM.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,581
    Rep Power
    25

    Default Re: Help me with this bank teller please!

    can not get the fifty pence or any other coins working
    Please explain. Post the program's output and add some comments saying what is wrong with it and show what it should be.

    Please edit your post and wrap your code with code tags:
    [code]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Jack199191 is offline Member
    Join Date
    Nov 2013
    Posts
    4
    Rep Power
    0

    Default Re: Help me with this bank teller please!

    Hi, thanks for helping me, I have done what you asked me to.

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,581
    Rep Power
    25

    Default Re: Help me with this bank teller please!

    Your left off this part:
    add some comments saying what is wrong with it and show what it should be.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,663
    Blog Entries
    7
    Rep Power
    21

    Default Re: Help me with this bank teller please!

    floats (nor doubles) are suitable to represent decimal fractions (as in monetary units); better do all your calculations with ints (or longs) where you represent your amount of money in cents (pence); here the numer would be 28990 and one pound Sterling would equal 100.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    Jack199191 is offline Member
    Join Date
    Nov 2013
    Posts
    4
    Rep Power
    0

    Default Re: Help me with this bank teller please!

    Java Code:
    public class BankTeller {
      public static void main(String args[]) {
        float Sterling = 289.90f;
        float Total = Sterling;
        String indent = " ";
        int Hunderds, Fifties , Twenties, Tens, Fives, Ones;
        float Fiftyp, Tenp;
        //all of the notes are working fine as shown in the output.
        Hunderds =  (int) Sterling / 100;
        Sterling = (int) Sterling % 100;
        Fifties = (int) Sterling / 50;
        Sterling = Sterling % 50;
        Twenties = (int) Sterling / 20;
        Sterling = Sterling % 20;
        Tens = (int) Sterling / 10;
        Sterling = Sterling % 10;
        Fives = (int) Sterling / 5;
        Sterling = Sterling % 5;
        Ones = (int) Sterling / 1;
        Sterling = (int) Sterling % 1;
        // In the code below it should be working out how many Fifty pence coins are required, the same goes for ten pence coins. 
        //I might be on the wrong wave length completely 
        Sterling = Sterling * 100;
        Fiftyp = (float) (Sterling / 0.5);// noting shows in the output.
        Sterling = Sterling % 50;
        Tenp = (float) (Sterling / 0.1);
        Sterling = Sterling % 100;
        // I do not know if i am approaching this is the right way
        System.out.println("The notes and coins required are :");
        System.out.println();
        System.out.println(indent + "Hunderds : " + Hunderds);
        System.out.println(indent + "Fifties : " + Fifties);
        System.out.println(indent + "Twenties : " + Twenties);
        System.out.println(indent + "Tens : " + Tens);
        System.out.println(indent + "Fives : " + Fives);
        System.out.println(indent + "One pound coin :" + Ones);
        System.out.println(indent + "Fifty Pence :" + Fiftyp);
        System.out.println(indent + "Ten Pence :" + Tenp);
        System.out.println();
        System.out.println("Total: " + Total + " pounds");
      }
    }

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,663
    Blog Entries
    7
    Rep Power
    21

    Default Re: Help me with this bank teller please!

    If one pence == 1, then fify pence == 50, not 0.5

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  8. #8
    Jack199191 is offline Member
    Join Date
    Nov 2013
    Posts
    4
    Rep Power
    0

    Default Re: Help me with this bank teller please!

    The ones are 1 pound coins, sorry I should of commented that into the code, I am struggling with the use of float of the decimal

  9. #9
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,663
    Blog Entries
    7
    Rep Power
    21

    Default Re: Help me with this bank teller please!

    Have you read my first reply? Don't use floats (nor doubles) at all and represent the total amount of money in pence, e.g. 28990

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Need help with my bank class
    By rpark712 in forum New To Java
    Replies: 2
    Last Post: 11-21-2011, 03:39 PM
  2. help java bank....
    By natsuki in forum Introductions
    Replies: 2
    Last Post: 07-25-2011, 03:36 AM
  3. Bank Account
    By HPcompaq256 in forum New To Java
    Replies: 11
    Last Post: 02-26-2010, 09:05 PM
  4. Code bank
    By Eranga in forum Suggestions & Feedback
    Replies: 2
    Last Post: 01-01-2008, 05:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •