Question

In: Computer Science

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

Solutions

Expert Solution

DollarsEuros.java :

//importing package
import java.util.*;

//Java class with name DollarsEuros
public class DollarsEuros {
   // main() method
   public static void main(String[] args) {
       // Scanner class instance
       Scanner keyboard = new Scanner(System.in);
       // this variable will store dollars
       int dollars = 1;
       // this variable stores euros price
       double EUROS = 0.85;
       // While loop in Java
       // This while loop will continue till dollar is greater than 0
       while (dollars > 0) {
           // Taking dollars as input from user
           System.out.print("Enter today's price for one dollar : ");
           // reading today's price for one dollar
           dollars = keyboard.nextInt();
           //checking dollars
           if(dollars<=0)
           {
               //if dollars is less than or equal to 0 then
               //break while loop
               break;
           }
           // conversion from dollars to euros
           double euro = dollars * EUROS;
           // print dollars to euros
           System.out.println(dollars + " dollars = " + euro+" euros");
       }

   }

}
=========================================

Screen showing dollars to euros conversion :


Related Solutions

***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.
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.
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 an application that asks a user to type an even number or the sentinel value...
Write an application that asks a user to type an even number or the sentinel value 999 to stop. When the user types an even number, display the message “Good job!” and then ask for another input. When the user types an odd number, display an error message, "x is not an even number", and then ask for another input. When the user types the sentinel value 999, end the program.
Write a program that: a. Asks the user for their first name using a JOptionPane. b....
Write a program that: a. Asks the user for their first name using a JOptionPane. b. Asks the user for their age using a JOptionPane. C. Asks the user for their last name using a JOptionPane. d. Pops up a dialog with the following information: i. Number of characters in the first & last name combined ii. The full name all-in upper-case letters iii. The full name all-in lower-case letters iv. The first letter of the name v. The age...
Write a program that asks the user to type in two integer values. Test these two...
Write a program that asks the user to type in two integer values. Test these two numbers to determine whether the first is evenly divisible by the second and then display the appropriate message to the terminal. Objective C
Write a complete shell script that first asks the user to enter a URL. The script...
Write a complete shell script that first asks the user to enter a URL. The script should read the URL into a variable named url. The shell script should then retrieve the file associated with the URL by using the curl command. The output of the curl command should be redirected to a file named html_file. The shell script should then use the grep command to search the file named html_file for the word manhattan. Finally, the shell script should...
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.
write a program that: 1) asks the user to enter grades, a negative number is the...
write a program that: 1) asks the user to enter grades, a negative number is the signal to stop entering. (while loop) - add each grade to a list (do not add the negative number to the list) after the while loop to enter grades is finished: 2) use a for loop on the list to calculate the average of all numbers in the list 3) use a for loop on the list to find the largest number in the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT