This is topic My first Java program! :) in forum Books, Films, Food and Culture at Hatrack River Forum.


To visit this topic, use this URL:
http://www.hatrack.com/ubb/main/ultimatebb.php?ubb=get_topic;f=2;t=052226

Posted by Blayne Bradley (Member # 8565) on :
 
code:
import javax.swing.JOptionPane;
public class CanadianToUSCurrencyConverterApp
{
/**
*
* @param args
*/
public static void main(String[] args)
{
//variables
int max = 110;
int interval = 10;
double usDoll;
double caDoll;
String response;

//code
response = JOptionPane.showInputDialog("Exchange Rate of 1 Can$ in US$");
double exchangeRate = Double.parseDouble(response);

for ( int count = 10; count < max; count = count + interval )
{
//for loop

usDoll = count * exchangeRate;
caDoll = count;
//output to console
System.out.println( caDoll + "$Can = " + usDoll + "$US");

}
}
}

Its a rough currency converter from CA to US dollars, it prompts the user for an exchange rate and then prints out the US dollar based on intervals of ten.
 
Posted by C3PO the Dragon Slayer (Member # 10416) on :
 
Not "Hello world?"
 
Posted by Primal Curve (Member # 3587) on :
 
I think it would be interesting if you found an RSS feed for USD/CAD exchange rates and integrated that into the calculation so that it gives up-to-the-minute values.
 
Posted by Xavier (Member # 405) on :
 
I think your style could use a lot of work, and it's not taking advantage of Object Orientation in any way, but I wouldn't expect that stuff from your first program.

Good luck in your future Java endeavors.
 
Posted by Nighthawk (Member # 4176) on :
 
By slightly modifying just four lines, you can tell people it's your first C# application, too!
 
Posted by Threads (Member # 10863) on :
 
If you have to turn this in for a class then you will probably want to make the max and interval variables constant (final or static final). Professors can be sticklers about stuff like that.
 
Posted by King of Men (Member # 6684) on :
 
quote:
Originally posted by Xavier:
I think your style could use a lot of work, and it's not taking advantage of Object Orientation in any way, but I wouldn't expect that stuff from your first program.

Ok, I'll agree on the style; they call it the One True Brace Style for a reason. But OO? Dude, it's a twenty-line, one-off problem. Just what benefit are you going to get from making a CurrencyInterfaceManagerFactory object? Object-oriented is for complex problems that require maintenance. Keep It Simple When Possible, eh?
 
Posted by Threads (Member # 10863) on :
 
I prefer the brace on a separate line but I find K&R equally readable.
 
Posted by Xavier (Member # 405) on :
 
"Keep it simple" depends on the goal. If his goal is to learn Java, I'd incorporate object oriented concepts early and often.

(Though not in the first program, which I pointed out.)
 
Posted by anti_maven (Member # 9789) on :
 
Does it work? Shurley that is the chief criteria.

Nice one Blayne!
 
Posted by Slim (Member # 2334) on :
 
Overall, good work!

My only recommendation is to make your comments more descriptive.
 


Copyright © 2008 Hatrack River Enterprises Inc. All rights reserved.
Reproduction in whole or in part without permission is prohibited.


Powered by Infopop Corporation
UBB.classic™ 6.7.2