Question

In: Computer Science

***IN JAVA*** 5. Currency conversion: Write a snippet that first asks the user to type   today's...

***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.

Solutions

Expert Solution

// 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();
        }
    }
}



Related Solutions

  1. Currency conversion: Write a snippet that first asks the user to type   today's price for...
  1. Currency conversion: Write a snippet that first asks the user to type   today's price for one dollar in Euros, then continues to read US dollar values from the user and convert each to Euros until the sentinel value 0 is entered. Format output to 2 decimal places. *****IN JAVA********
Write a program in Java that first asks the user to type in today's price of...
Write a program in Java that first asks the user to type in today's price of one dollar in Japanese yen, then reads U.S. dollar values and converts each to yen. Use 0 as a sentinel to denote the end of dollar input. THEN the program reads a sequence of yen amounts and converts them to dollars. The second sequence is terminated by another zero value.
Write a java simple document retrieval program that first asks the user to enter a single...
Write a java simple document retrieval program that first asks the user to enter a single term query, then goes through two docuements named doc1.txt and doc2.txt (provided with assignment7) to find which document is more relevant by calculating the frequency of the query term in each document. Output the conclusion to a file named asmnt7output.txt in the following format (as an example for query “java” and “problem”). The percentages in parenthese are respective supporting frequencies. java: doc1(6.37%) is more...
1. Write a Java program that asks the user to input a positive integer n first,...
1. Write a Java program that asks the user to input a positive integer n first, then create an array of size n. Fill n random integers between 5 and 555, inclusively, into the created array. Output the sum of all the integers in the array and the average of all the integers in the array. 2 .Find the output of the following Java program and explain your answer
Write a java code snippet to prompt the user for the number of names they’d like...
Write a java code snippet to prompt the user for the number of names they’d like to enter. Create a new array of the size chosen by the user and prompt the user for each of the names. Output the list of names in reverse order.
This is Java In this problem we will write a program that asks the user to...
This is Java In this problem we will write a program that asks the user to enter a) The user's first name and b) a series of integers separated by commas. The integers may not include decimal points nor commas. The full string of numbers and commas will not include spaces either, just digits and commas. An example of valid input string is:        7,9,10,2,18,6 The string must be input by the user all at once; do not use a loop...
IN JAVA write a program that asks a user for a maximum of 20 user-inputted elements...
IN JAVA write a program that asks a user for a maximum of 20 user-inputted elements and create an array. Then, write a Merge Sort function with recursion (in the main) that takes the user inputted elements in the array, sorts them, and prints them back.
Write Java program that asks a user to input a letter, converts the user input to...
Write Java program that asks a user to input a letter, converts the user input to uppercase if the user types the letter in lowercase, and based on the letter the user the user enters, display a message showing the number that matches the letter entered. For letters A or B or C display 2 For letter D or E or F display 3 For letter G or H or I display 4 For letter J or K or L...
Write a Java program that asks the user to enter an integer that is used to...
Write a Java program that asks the user to enter an integer that is used to set a limit that will generate the following four patterns of multiples of five using nested loops •Ascending multiples of five with ascending length triangle •Ascending multiples of five with descending length (inverted) triangle •Descending multiples of five with ascending length triangle •Descending multiples of five with descending length (inverted) triangle Use error checking to keep asking the user for a positive number until...
Write a program IN JAVA that asks the user for a number. The program should check...
Write a program IN JAVA that asks the user for a number. The program should check the number to ensure that it is valid (if not, the user should enter a valid number to continue.) The program should print out all of the prime numbers from 2 up to the number, with up to 10 numbers per line. (Recall: A prime number is a number that is only divisible by itself and 1.) The code should ask the user if...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT