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 asks the user to enter a bunch of words until they type...
Write a program that asks the user to enter a bunch of words until they type the word “quit”. Count how many words had 5 letters or more. Sample program Enter a word: nothing Enter a word: stop Enter a word: word Enter a word: program Enter a word: supercalifragilisticexpialidocious Enter a word: quit You entered 3 words that were longer than 5 letters.
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...
Java Programming : Email username generator Write an application that asks the user to enter first...
Java Programming : Email username generator Write an application that asks the user to enter first name and last name. Generate the username from the first five letters of the last name, followed by the first two letters of the first name. Use the .toLowerCase() method to insure all strings are lower case. String aString = “Abcd” aString.toLowerCase(); aString = abcd Use aString.substring(start position, end position + 1) aString.substring(0, 3) yields the first 3 letters of a string If the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT