|
-
Jan 9th, 2009, 08:27 PM
#1
Thread Starter
New Member
trying from 8 hours eyes killing me Please need some helo
.6 Currency (Weight: 4%)
Problem Specification
The problem concerns the conversion of currency from different countries and the commission the bank will charge for this. When converting currency, banks always charge a commission of a few percent or a fixed minimum commission – whichever is greater.
Write a program to input data required to convert from another currency to Pounds. Also charge commission according to the method below.
NOTE: 3 points are awarded for the program, an additional one for presenting a correct flow chart of the program to your tutor.
Method
1. Prompt and read 4 input parameters in this order:
Commission rate (e.g. 1.4 for 1.4 percent)
Currency to convert from (this is a 3-letter code, e.g. JPY for Japanese Yen, EUR for Euros, USD for US Dollars, etc)
Rate of exchange to Pence (e.g.: 0.014 for Euros 2.80 Euros / 0.014 = 100 Pence)
Amount of foreign currency to exchange (e.g. 327.55)
2. Convert the foreign currency into Pence.
3. If the Pence sum arising from this conversion is less than or equal to the minimum commission (5 Pounds in this exercise), print the message "Amount too small!"
4. Now calculate the percentage commission. If this calculated percentage commission is less than the minimum commission, the payout will be the sterling amount (split into pounds and pence) minus the minimum commission.
5. If the calculated percentage commission is greater than or equal to the minimum commission, the payout is the sterling amount (split into pounds and pence) minus the calculated commission.
Hints
The above Method can be written in Pseudo Code as shown below. This should help you to develop the flow chart:
Code:
START OF PROGRAM
Set constant MIN_COMM to 500 (minimum commission is 500 pence)
PROMPT and READ the 4 input parameters (in the correct order!)
Calculate the amount in pence (penceAmount = foreignAmount / exRate;)
IF penceAmount < MIN_COMM
PRINT "Amount too small"
ELSE
Calculate perc. commission (comm = penceAmount * commRate /100;)
IF commision less than MIN_COMM
commission=MIN_COMM
END IF
Split commission into Pounds and Pence
PRINT commission Pounds and Pence
actPayOut = penceAmount – commission
Split actPayOut into Pounds and Pence
PRINT actPayOut Pounds and Pence
END IF
END OF PROGRAM
---------------------------CODE-----------------------------------------
Code:
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;
////////////////// //////////////////////////////////:wave: :wave: :wave:
if (exchangePounds <= commission){
COM = 5;
System.out.println ("Amount too small.");
System.exit (0);
}/////////////////////////////////////////////// :) :)
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
--------------------------------CODE--------------------------------
QUESTION IS COMMISSION IS NOT WORKING WITH IF STATMENT
ANY HELP PLZZZZZZZZZZZZZZZZZ
Last edited by mendhak; Jan 10th, 2009 at 05:14 AM.
-
Jan 10th, 2009, 01:18 AM
#2
Re: trying from 8 hours eyes killing me Please need some helo
This is the wrong forum. Flagged
My usual boring signature: Something
-
Jan 10th, 2009, 05:14 AM
#3
Re: trying from 8 hours eyes killing me Please need some helo
Moved to the Java forum and formatted with code blocks.
-
Jan 10th, 2009, 08:17 AM
#4
Re: trying from 8 hours eyes killing me Please need some helo
Code:
import java.util.Scanner;
public class CheckCurrency
{
public static void main(final String[] argv)
{
// START OF PROGRAM
// Set constant MIN_COMM to 500 (minimum commission is 500 pence)
final int MIN_COMM = 500;
// PROMPT and READ the 4 input parameters (in the correct order!)
final Scanner scanner = new Scanner(System.in);
System.out.println("Commission rate (percentage)");
final double commission = scanner.nextDouble();
// WARNING: THE FOLLOWING VARIABLE IS NEVER USED
System.out.println("Currency to convert from");
String currencyToConvert = scanner.next();
System.out.println("Rate of exchange to Sterling pence");
final double rateOfExchange = scanner.nextDouble();
System.out.println("Amount to exchange");
final double amountToExchange = scanner.nextDouble();
// Calculate the amount in pence (penceAmount = foreignAmount / exRate;)
final double penceAmount = amountToExchange / rateOfExchange;
if (penceAmount < MIN_COMM)
System.out.println("Amount too small");
else
{
// Calculate perc. commission
double comm = penceAmount * commission / 100;
if (comm < MIN_COMM)
comm = MIN_COMM;
// Split commission into Pounds and Pence
final String[] commissionString = Double.toString(comm).split("\\.");
// PRINT commission Pounds and Pence
System.out.println("Commission is " + commissionString[0] + " pounds " + commissionString[1]
+ " pence");
final double actPayOut = penceAmount - commission;
// Split actPayOut into Pounds and Pence
final String[] actPayOutString = Double.toString(actPayOut).split("\\.");
// PRINT actPayOut Pounds and Pence
System.out.println("Actual sterling amount is " + actPayOutString[0] + " pounds "
+ actPayOutString[1] + " pence");
}
}
}
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|