NOTSOSURE
Nov 23rd, 2002, 10:00 AM
i am trying 2 write a program using BlueJ Terminal Window to input data and convert from another currency to British Pounds Sterling
and charge commission according to the method below.
Method
===========================================
1. If the sterling sum arising from direct conversion is less than or equal to the minimum
commission, print the message
"Amount too small!"
2. If the calculated commission is less than the minimum commission, the payout will be
the sterling amount minus the minimum commission.
3. If the calculated commission is greater than or equal to the minimum commission, the
payout is the sterling amount minus the calculated commission.
In practice, the conversion rate and percentage commission and minimum commission
would be read in as input values rather than defined as constants.
=============================================
im having troble displaying the commission in ponds and pence
INPUT / OUTPUT
=============================================
These are the INput and outputs
Typical input :
Commission rate (percentage): 2
Currency to convert from: CNY
Rate of exchange to Sterling pence: 0.1377
Amount to exchange: 327.55
Corresponding output :
327.55 CNY goes directly to 23 pounds 78 pence
Commission is 5 pounds 0 pence
Actual sterling amount is 18 pounds 78 pence
below is the code i have done so far please tell me where i am going wrong!!!! thanx
public class CheckCurrency{
public static void main(String[] argv) {
// put your local declarations here
String currencyToConvert;
float amountToExchange, rateOfExchange, commission, amountExchanged;
int exchangePounds, exchangePence, commissionPounds, commissionPence;
// Prompt and read the commision rate
System.out.println ("Commission rate (percentage)");
commission = UserInput.readFloat();
// Prompt and read the three-letter currency code used by the industry
System.out.println ("Currency to convert from");
currencyToConvert = UserInput.readString();
// Prompt and enter the conversion rate here
System.out.println ("Rate of exchange to Sterling pence");
rateOfExchange = UserInput.readFloat();
// Prompt and read the amount of money to be converted here
System.out.println ("Amount to exchange");
amountToExchange = UserInput.readFloat();
// Compute and print
amountExchanged = amountToExchange / rateOfExchange;
commission = commission / amountToExchange * 100;
// Compute and print Exchange pounds and pence
exchangePounds = (int)(amountExchanged / 100);
exchangePence = (int) amountExchanged - exchangePounds * 100;
System.out.println (amountToExchange + " " + currencyToConvert + " goes directly to " + exchangePounds + " pounds " + exchangePence + " pence");
// Compute and print commission pounds and pence
commissionPounds = (int) (commission / 100);
commissionPence = (int) commission - commissionPounds * 100;
System.out.println ("Commission is " + commissionPounds + " pounds " + commissionPence + " pence");
// Compute and print actual pound and pence
System.out.println ("Actual sterling amount is " + exchangePounds + " pounds " + exchangePence + " pence");
} // end of main
} // end class
and charge commission according to the method below.
Method
===========================================
1. If the sterling sum arising from direct conversion is less than or equal to the minimum
commission, print the message
"Amount too small!"
2. If the calculated commission is less than the minimum commission, the payout will be
the sterling amount minus the minimum commission.
3. If the calculated commission is greater than or equal to the minimum commission, the
payout is the sterling amount minus the calculated commission.
In practice, the conversion rate and percentage commission and minimum commission
would be read in as input values rather than defined as constants.
=============================================
im having troble displaying the commission in ponds and pence
INPUT / OUTPUT
=============================================
These are the INput and outputs
Typical input :
Commission rate (percentage): 2
Currency to convert from: CNY
Rate of exchange to Sterling pence: 0.1377
Amount to exchange: 327.55
Corresponding output :
327.55 CNY goes directly to 23 pounds 78 pence
Commission is 5 pounds 0 pence
Actual sterling amount is 18 pounds 78 pence
below is the code i have done so far please tell me where i am going wrong!!!! thanx
public class CheckCurrency{
public static void main(String[] argv) {
// put your local declarations here
String currencyToConvert;
float amountToExchange, rateOfExchange, commission, amountExchanged;
int exchangePounds, exchangePence, commissionPounds, commissionPence;
// Prompt and read the commision rate
System.out.println ("Commission rate (percentage)");
commission = UserInput.readFloat();
// Prompt and read the three-letter currency code used by the industry
System.out.println ("Currency to convert from");
currencyToConvert = UserInput.readString();
// Prompt and enter the conversion rate here
System.out.println ("Rate of exchange to Sterling pence");
rateOfExchange = UserInput.readFloat();
// Prompt and read the amount of money to be converted here
System.out.println ("Amount to exchange");
amountToExchange = UserInput.readFloat();
// Compute and print
amountExchanged = amountToExchange / rateOfExchange;
commission = commission / amountToExchange * 100;
// Compute and print Exchange pounds and pence
exchangePounds = (int)(amountExchanged / 100);
exchangePence = (int) amountExchanged - exchangePounds * 100;
System.out.println (amountToExchange + " " + currencyToConvert + " goes directly to " + exchangePounds + " pounds " + exchangePence + " pence");
// Compute and print commission pounds and pence
commissionPounds = (int) (commission / 100);
commissionPence = (int) commission - commissionPounds * 100;
System.out.println ("Commission is " + commissionPounds + " pounds " + commissionPence + " pence");
// Compute and print actual pound and pence
System.out.println ("Actual sterling amount is " + exchangePounds + " pounds " + exchangePence + " pence");
} // end of main
} // end class