In: Computer Science
***IN JAVA***
5. Currency conversion: Write a snippet that first asks the user to type
today's US dollar price for one Euro. Then use a loop to:
-- prompt the user to enter a Euro amount. (allow decimals)
-- convert that amount to US dollars. (allow decimals)
-- print the amount to the screen, formatted to two decimal places
Use 0 as a sentinel to stop the loop.
// EurosToUS.java import java.util.Scanner; public class EurosToUS { public static void main(String[] args) { // Create a Scanner object to read input. Scanner scan = new Scanner(System.in); System.out.print("Enter today's US dollar price for one Euro: "); double dollarPrice = scan.nextDouble(); System.out.print("Enter a Euro amount: "); double euros = scan.nextDouble(); while(euros!=0){ System.out.println(dollarPrice*euros+" dollars"); System.out.print("Enter a Euro amount: "); euros = scan.nextDouble(); } } }