Forum Moderators: open

Message Too Old, No Replies

SOS Java help

         

Angela2005

10:44 pm on Sep 21, 2004 (gmt 0)

10+ Year Member



I have this assignment that I have to do, and I'm doing miserably. Can anyone help?

I have to convert euros to U.S. dollars. I have to start by prompting the user to enter the number of euros to be converted. The program has to multiply this value by 1.24, which will give the number of U.S. dollars equivalent to the number of euros. Then the program should print out the number of euros and the conversion to the number of dollars. Here's an example.

Enter the number of euros: 4.60
4.60 euros is $5.704 US

Rambo Tribble

2:41 am on Sep 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You need to be aware that JavaScript is not Java, so if your assignment is in Java, this isn't the answer. Here is a simple document and script to do what you ask. I'll leave it to you to format your answers and take it beyond this simple (primitive) demonstration. (It is, after all, your assignment.)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Untitled</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function currConv(){
var curr_in=prompt("Enter your Euro amount: ", 1);
alert(curr_in+" Euros converts to $"+(curr_in*1.24)+" U.S.");
}
</script>
</head>
<body onload="currConv();">

</body>
</html>

Angela2005

2:49 am on Sep 22, 2004 (gmt 0)

10+ Year Member



Thanks for your help, I'm aware that it is my project, I was going to post what I have done, but I was I did not want to embarass myself.

Rambo Tribble

5:28 am on Sep 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



To add some explanation: prompt() is a built-in JavaScript method (a.k.a. "function", though the term "method" is usually used if the function is attached to an object [or, in the case of Java, not JavaScript, a class]; in this case the method is attached to the window object and is intrinsic to that entity). It returns (gives back to the calling function or statement) whatever value is entered into the text window. In the script, that is, in turn, assigned to the variable "curr_in" (short for "current input"). That value is passed to the alert method, which displays the value and the product of its multiplication with the constant you specified (I'm sure you can see how that is accomplished). The whole shootin' match is initiated by the HTML document's body's onload event (onload fires when a page has completely loaded, with some minor potential exceptions, like iframes, but that's another story).

I hope this helps. I delayed explanation to give you some time to cogitate, digest, and ruminate. (Not to suggest that you are a ruminant; that's more a tribble's domain.)

midwestguy

10:13 pm on Sep 22, 2004 (gmt 0)

10+ Year Member



Hi Angela,

One thing to mention:

I would check to make sure they really want you to code this with the exchange rate of U.S. dollars to Euros

*****FIXED*****

at 1.24!

Exchange rates vary quite a bit over time. I suspect whomever gave you the 1.24 number was just providing an example, using something close to the current value in the marketplace at the time; it WILL change -- and has already since you posted.

Suggest you check this issue out with whomever gave you the 1.24 "programming spec". You most likely will have to find a source of up to date (if not up to the minute) exchange rate data. Suggest trying google for a data source if you or your company doesn't have one already picked out for you to use. One site that does exchange rates I found via google is xe dot com. You might find looking at their site gives you some helpful ideas.

Also, whomever gives you the "spec" for this task might want to specify both how and to what decimal place to round the conversion. For instance, I doubt they would want you to tell customers the (converted) price will be 4.5678 dollars or Euros...rather than 4.57 dollars or Euros.

Hope this helps you out,

Louis