FacebookTwitter
Hatrack River Forum   
my profile login | search | faq | forum home

  next oldest topic   next newest topic
» Hatrack River Forum » Active Forums » Books, Films, Food and Culture » My first Java program! :)

   
Author Topic: My first Java program! :)
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
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.
IP: Logged | Report this post to a Moderator
C3PO the Dragon Slayer
Member
Member # 10416

 - posted      Profile for C3PO the Dragon Slayer           Edit/Delete Post 
Not "Hello world?"
Posts: 1029 | Registered: Apr 2007  |  IP: Logged | Report this post to a Moderator
Primal Curve
Member
Member # 3587

 - posted      Profile for Primal Curve           Edit/Delete Post 
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.
Posts: 4753 | Registered: May 2002  |  IP: Logged | Report this post to a Moderator
Xavier
Member
Member # 405

 - posted      Profile for Xavier   Email Xavier         Edit/Delete Post 
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.

Posts: 5656 | Registered: Oct 1999  |  IP: Logged | Report this post to a Moderator
Nighthawk
Member
Member # 4176

 - posted      Profile for Nighthawk   Email Nighthawk         Edit/Delete Post 
By slightly modifying just four lines, you can tell people it's your first C# application, too!
Posts: 3486 | Registered: Sep 2002  |  IP: Logged | Report this post to a Moderator
Threads
Member
Member # 10863

 - posted      Profile for Threads   Email Threads         Edit/Delete Post 
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.
Posts: 1327 | Registered: Aug 2007  |  IP: Logged | Report this post to a Moderator
King of Men
Member
Member # 6684

 - posted      Profile for King of Men   Email King of Men         Edit/Delete Post 
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?
Posts: 10645 | Registered: Jul 2004  |  IP: Logged | Report this post to a Moderator
Threads
Member
Member # 10863

 - posted      Profile for Threads   Email Threads         Edit/Delete Post 
I prefer the brace on a separate line but I find K&R equally readable.
Posts: 1327 | Registered: Aug 2007  |  IP: Logged | Report this post to a Moderator
Xavier
Member
Member # 405

 - posted      Profile for Xavier   Email Xavier         Edit/Delete Post 
"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.)

Posts: 5656 | Registered: Oct 1999  |  IP: Logged | Report this post to a Moderator
anti_maven
Member
Member # 9789

 - posted      Profile for anti_maven   Email anti_maven         Edit/Delete Post 
Does it work? Shurley that is the chief criteria.

Nice one Blayne!

Posts: 892 | Registered: Oct 2006  |  IP: Logged | Report this post to a Moderator
Slim
Member
Member # 2334

 - posted      Profile for Slim   Email Slim         Edit/Delete Post 
Overall, good work!

My only recommendation is to make your comments more descriptive.

Posts: 172 | Registered: Aug 2001  |  IP: Logged | Report this post to a Moderator
   

   Close Topic   Feature Topic   Move Topic   Delete Topic next oldest topic   next newest topic
 - Printer-friendly view of this topic
Hop To:


Contact Us | Hatrack River Home Page

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