1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

CurrencyConverter help!

Discussion in 'Java' started by ai5uzu, Oct 21, 2011.

  1. ai5uzu

    ai5uzu New Member

    I have this one assignment in class and it's suppose to loop the conversion until I tell it to stop by entering in Q. I tried to do an if statement before the while but it didn't seem to work. Please help

    Task: Write a program CurrencyConverter hat asks the user to enter today's price of one dollar in euro. Then the program reads US dollars vales and ocnverts each to euro values. Stop when the user enters Q.

    Code:
     
    [FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]import[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] java.util.Scanner;[/FONT]
     
    [FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]public[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]class[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] CurrencyConverter2[/FONT]
    [FONT=Courier New]{[/FONT]
    [FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]public[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]static[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]void[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] main(String args[])[/FONT]
    [FONT=Courier New]{[/FONT]
    [FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]private[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]double[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] UsdToEuro;[/FONT]
    [FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]private[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]double[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] convertToEuro;[/FONT]
    [FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]private[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]double[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] dollars;[/FONT]
     
    [FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]boolean[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] stop = [/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]false[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New];[/FONT]
    [FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]while[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] (!stop)[/FONT]
    [FONT=Courier New]{ [/FONT]
    [FONT=Courier New]System.out.print([/FONT][FONT=Courier New][COLOR=#00cb00][FONT=Courier New][COLOR=#00cb00]"Enter today's price of 1 dollar in euro, Q to Quit: "[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]); [/FONT][FONT=Courier New][COLOR=#fa6400][FONT=Courier New][COLOR=#fa6400]// Today's exchange rate is .72427[/COLOR][/FONT]
    [/COLOR][/FONT][FONT=Courier New]UsdToEuro = scan.nextDouble();[/FONT]
    [FONT=Courier New]System.out.println([/FONT][FONT=Courier New][COLOR=#00cb00][FONT=Courier New][COLOR=#00cb00]"You entered today's USD to Euro exchange rate is: "[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] + UsdToEuro);[/FONT]
    [FONT=Courier New]System.out.print([/FONT][FONT=Courier New][COLOR=#00cb00][FONT=Courier New][COLOR=#00cb00]"Enter USD value: "[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]);[/FONT]
    [FONT=Courier New]dollars = scan.nextDouble();[/FONT]
    [FONT=Courier New]convertToEuro = dollars * UsdToEuro;[/FONT]
    [FONT=Courier New]System.out.println([/FONT][FONT=Courier New][COLOR=#00cb00][FONT=Courier New][COLOR=#00cb00]"The value of "[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] + dollars + [/FONT][FONT=Courier New][COLOR=#00cb00][FONT=Courier New][COLOR=#00cb00]" USD is "[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] + convertToEuro + [/FONT][FONT=Courier New][COLOR=#00cb00][FONT=Courier New][COLOR=#00cb00]" in Euros."[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]);[/FONT]
    [FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]if[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] (scan.equals(quit))[/FONT]
    [FONT=Courier New]stop = [/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]true[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New];[/FONT]
    [FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]else[/COLOR][/FONT]
    [/COLOR][/FONT][FONT=Courier New]stop = [/FONT][FONT=Courier New][COLOR=#941edf][FONT=Courier New][COLOR=#941edf]false[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New];[/FONT]
    [FONT=Courier New]}[/FONT]
    [FONT=Courier New]}[/FONT]
    [FONT=Courier New]}[/FONT]
     
    
     

Share This Page