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...
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.
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 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...
Write a java program that asks the user for a number n and gives them the...
Write a java program that asks the user for a number n and gives them the possibility to choose between computing the sum and computing the product of 1,…,n. Example of running this program: Enter an integer number n: __7________ Enter Sum or Product: __Sum__________________________________ Program output: Sum of 1 ... 7 Sum or Product: Sum Sum = 28 Now second sample of second execution Enter an integer number n: __5__________________________________ Enter Sum or Product: __Product__________________________________ Program output:  Product of 1...
Program should be written in Java a) Write a program that asks the user to enter...
Program should be written in Java a) Write a program that asks the user to enter the approximate current population of India. You should have the computer output a prompt and then YOU (as the user should enter the population.)  For testing purposes you may use the value of 1,382,000,000 from August 2020. Assume that the growth rate is 1.1% per year. Predict and print the predicted population for 2021 and 2022. The printout should include the year and the estimated...
Time Calculator – Intro To Programming - JAVA Write a program that asks the user to...
Time Calculator – Intro To Programming - JAVA Write a program that asks the user to enter a number of seconds. • There are 60 seconds in a minute. If the number of seconds entered by the user is greater than or equal to 60, the program should display the number of minutes in that many seconds. • There are 3,600 seconds in an hour. If the number of seconds entered by the user is greater than or equal to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT