please help me I am a newbie...
how would i go about creating an applet or application that converts from one currency to another. for example (us dollars to euros and vice versa)
A good idea to put into mind is the use of an xml file for the currency ratios.
But anyway...for a simple one.
set up constants for the currency ratios:
then you have to implement inputs, either with a keyboard class, io class, swing or awt.
private final double US_TO_CAN = 0.8;
Then it's just simple algebra from there on in.
Here ya go.
public class Currency
public static void main(String args)
NumberFormat fmt = NumberFormat.getCurrencyInstance();
final double US_TO_CAN = 1.3333333;
//read from user input
System.out.print("Enter $ USD: ");
inputUSD = Keyboard.readDouble();
//perform calculation conversion
output = inputUSD*US_TO_CAN;
System.out.println("Canadian Dollar Amount: "
Last edited by BuezaWebDev; 11-19-2004 at 01:44 AM.
well i guess that gets me going in the right direction, but i don't understand what you mean by cs1.keyboard and textpad doesn't recognize it either.
cs1.Keyboard; is a jar file that allows you to take in user inputs.
You can download it here.
ok another question
how can i make it so that the application asks the user whether he would like to convert from us to can, or us to euros or something like that?
some sort of menu? i guess that is what you could call it.
You could make a method and a public static variable like, "mode"
Enclose it with public class NameOfClass blah blah :P
private static double conversionRate;
private static int setMode(int numberCurrency)
if (numberCurrency == 1)
conversionRate = 1.33;
if (numberCurrency == 2)
conversionRate = 0.88;
public static void main(final String args)
System.out.println("1 = US to Can");
System.out.println("2 = Can to US");
inputMode = Keyboard.readInt();
System.out.println("How much in $: ");
inputDollars = Keyboard.readDouble();
double output = inputDOllars*conversionRate;
Hopefully this leads you in the right direction. There's probably a more efficient way of doing this, and maybe someone else will submit a better version.
Sorry for the late reply.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)