Results 1 to 4 of 4

Thread: Please Help

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2009
    Posts
    4

    Please Help

    HI All, I been working on this for days and cant seem to get my head around it. The sceanrio is to convert from a currency to british pounds working out commision rates etc.The examples of inputs I have been given are:

    Currency to convert from: CNY
    Rate of exchange to Sterling pence: 0.1377
    Commission rate: 2.5
    Amount to exchange: 11428.55
    Amount to exchange: 198.22


    This is the result I am getting is

    Currency to convert from: cny
    Rate of exchange to Sterling pence: 0.1377
    commision Rate: 2.5
    Amount to exchange: 11428.55
    11428.55 cny is 829.960058097313 pence
    Commission is 5 pounds 0 pence
    Actual sterling amount is 3 pounds 29 pence
    11428.55 cny is 829.960058097313; commission 500.0 GBP; payout329.960058097313


    when it should be

    11428.55 CNY is 829.96 GBP; commission 20.74 GBP; payout 809.22 GBP

    Hope someone one can help this is the code I have provided below

    public class ProcessCurrency {

    static final int min_comm = 500;

    public static void main(String[] argv) {


    double commRate, foreignAmount, exchangeRate, penceAmount,actPayOut, actPoundPence;
    String currencyToConverFrom;
    double comm = 0;
    double commPoundPence = 0;
    int trans=0;
    double totForeign=0, totSterling=0, totHandouts=0, totComission=0, avgHand=0,forSter=0;

    System.out.print("Currency to convert from: ");
    currencyToConverFrom = UserInput.readString();

    System.out.print("Rate of exchange to Sterling pence: ");
    exchangeRate = UserInput.readDouble();

    System.out.print("commision Rate: ");
    commRate = UserInput.readDouble();

    System.out.print("Amount to exchange: ");
    foreignAmount = UserInput.readDouble();




    while (foreignAmount != 0){
    penceAmount = foreignAmount / exchangeRate / 100;

    System.out.println(foreignAmount + " " + currencyToConverFrom + " is "+ penceAmount + " pence");



    if (penceAmount < min_comm)
    System.out.println("Amount too small");
    else {
    comm = penceAmount * (commRate/100);
    trans++;
    if (comm < min_comm){
    comm = 500;
    }// PAmt<min100);

    System.out.println("Commission is "+(int)(comm/100)+" pounds "+(int)(comm%100)+" pence ");

    actPayOut = penceAmount - comm;

    actPoundPence = actPayOut/100;

    System.out.println("Actual sterling amount is "+(int)actPoundPence+" pounds "+(int)(actPayOut%100)+" pence");

    totForeign+=foreignAmount;
    totSterling+=penceAmount;
    totHandouts+=actPayOut;
    totComission+=comm;
    avgHand = totHandouts/trans;
    forSter = totForeign/totHandouts;

    System.out.println(foreignAmount + " " + currencyToConverFrom +" is "+ penceAmount +"; commission "+comm+" GBP; payout" + actPayOut + " GBP");
    }//end else

    System.out.print("Amount to exchange: ");
    foreignAmount = UserInput.readDouble();
    }//end while


    System.out.println("Transactions " + trans);
    System.out.println("Total "+ currencyToConverFrom +" received " + totForeign);
    System.out.println("Total sterling value " + totSterling);
    System.out.println("Total handouts " + totHandouts);
    System.out.println("Total Commission " + totComission);
    System.out.println("Average handout " + avgHand);
    System.out.println(currencyToConverFrom +" per pound " + forSter);







    }

    }

  2. #2
    New Member
    Join Date
    Jan 2009
    Posts
    5

    Re: Please Help

    ojijkijl,l!!!!
    Last edited by soc86; Jan 15th, 2009 at 01:10 PM.

  3. #3
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: Please Help

    I guess it's a class mate of yours that posted the same homework on this forum
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  4. #4
    Addicted Member
    Join Date
    Feb 2002
    Posts
    159

    Re: Please Help

    i think its something to do with your calculations!

Posting Permissions

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



Click Here to Expand Forum to Full Width