Question

Exercise 2. Write a program that uses a Scanner object to read a value in SUS (US Dollars). The program computes the equivalent amount in $CA (Canadian currency) and the equivalent in EUROs. Google the conversion rates. The program then writes the result in the following form: 12 marks- type a value in .. EUROs You need to choose whether the variables should be of type int or double. Test the program with three sets of data and include the results in this report. Do not concern yourself with controlling the display of the decimal point.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

/**
* The java program that prompts user
* to enter us dollars and converts
* the curreny in dollars to canadian
* and euros and print the results
* to console.
* */
//CurrencyConvertor.java
import java.util.Scanner;
public class CurrencyConvertor
{
   public static void main(String[] args)
   {
       //declare variables
       double usdollars;
       double canadianDollars;
       double euros;

       //exchange rates for us currency in dollars
       final double DOLLAR_TO_CANADIAN_DOLLARS=1.25;
       final double DOLLAR_TO_EUROS=0.85;
       //create a Scanner object
       Scanner scan=new Scanner(System.in);
       System.out.print("Please type a value in $US:");
       usdollars=scan.nextDouble();
      
       //convert us dollars to canadian dollars
       canadianDollars=usdollars*DOLLAR_TO_CANADIAN_DOLLARS;
       //convet usdollars to euros
       euros=usdollars*DOLLAR_TO_EUROS;
       //print usdollar, corresponding candian
       //and euros to console
       System.out.printf("\n$US=%5.2f $CA=%5.2f EUROs=%5.2f",usdollars,canadianDollars,euros);
          
   }
}//end of class

------------------------------------------------------------------------------------------------------------------

Sample Output screen shot:

<terminated> CurrencyConvertor [Java Application] D: Please type a value in $US:10 $US-10.00 $CA-12.50 EUROs- 8.50

Add a comment
Know the answer?
Add Answer to:
Exercise 2. Write a program that uses a Scanner object to read a value in SUS...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The following code uses a Scanner object to read a text file called dogYears.txt. Notice that...

    The following code uses a Scanner object to read a text file called dogYears.txt. Notice that each line of this file contains a dog's name followed by an age. The program then outputs this data to the console. The output looks like this: Tippy 2 Rex 7 Desdemona 5 1. Your task is to use the Scanner methods that will initialize the variables name1, name2, name3, age1, age2, age3 so that the execution of the three println statements below will...

  • Write a simple Java program with the following naming structure: Open Eclipse Create a workspace called...

    Write a simple Java program with the following naming structure: Open Eclipse Create a workspace called hw1 Create a project called hw1 (make sure you select the “Use project folder as root for sources and class files”) Create a class called Hw1 in the hw1 package (make sure you check the box that auto creates the main method). Add a comment to the main that includes your name Write code that demonstrates the use of each of the following basic...

  • Java Programming Reading from a Text File Write a Java program that will use an object...

    Java Programming Reading from a Text File Write a Java program that will use an object of the Scanner class to read employee payroll data from a text file The Text file payroll.dat has the following: 100 Washington Marx Jung Darwin George 40 200 300 400 Kar Car Charles 50 22.532 15 30 The order of the data and its types stored in the file are as follows: Data EmployeelD Last name FirstName HoursWorked double HourlyRate Data Tvpe String String...

  • With a Scanner object created as follows, what method do you use to read an int...

    With a Scanner object created as follows, what method do you use to read an int value? Scanner input = new Scanner(System.in); A. input.int(); B. input.nextInt(); C. input.integer(); D. input.nextInteger(); What is the output of the following code? x = 0; if (x > 0) System.out.println("x is greater than 0"); else if (x < 0) System.out.println("x is less than 0"); else System.out.println("x equals 0"); A. x is greater than 0 B. x is less than 0 C. x equals 0...

  • Write in JAVA Get Familiar with the Problem Carefully read the program description and look at...

    Write in JAVA Get Familiar with the Problem Carefully read the program description and look at the data file to gain an understanding of what is to be done. Make sure you are clear on what is to be calculated and how. That is, study the file and program description and ponder! Think! The Storm Class Type Now concentrate on the Storm class that we define to hold the summary information for one storm. First, look at the definition of...

  • Develop a flowchart and then write a menu-driven C++ program that uses several FUNCTIONS to solve...

    Develop a flowchart and then write a menu-driven C++ program that uses several FUNCTIONS to solve the following program. -Use Microsoft Visual C++ .NET 2010 Professional compiler using default compiler settings. -Use Microsoft Visio 2013 for developing your flowchart. -Adherence to the ANSI C++  required -Do not use <stdio.h> and <conio.h>. -Do not use any #define in your program. -No goto statements allowed. Upon execution of the program, the program displays a menu as shown below and the user is prompted to make a selection from the menu....

  • Problems: 1. Write a program to define the following variables, assign them values, and print their...

    Problems: 1. Write a program to define the following variables, assign them values, and print their values on screen: Integer x = 20, Float y = 40.45 Double z = 91.51e+5 Char w = A • • For the integer variable x, you need to print it in decimal notations, octal notations and hexadecimal notation. For the double variable y, you need to print it in double notations and scientific notation. 2. Write a program with the following three parts:...

  • (JAVA) Use the Pet.java program from the original problem (down below) Compile it. Create a text...

    (JAVA) Use the Pet.java program from the original problem (down below) Compile it. Create a text file named pets10.txt with 10 pets (or use the one below). Store this file in the same folder as your “class” file(s). The format is the same format used in the original homework problem. Each line in the file should contain a pet name (String), a comma, a pet’s age (int) in years, another comma, and a pet’s weight (double) in pounds. Perform the...

  • All information about the question (Task 1 and task 2) are down below Programming Assignments Task...

    All information about the question (Task 1 and task 2) are down below Programming Assignments Task 1 – Page 39. in Programming A Comprehensive Introduction Update your program from Assignment 2, Task #2 Allow the user to input their weight for the earth weight to moon weight conversion problem. Add an ifstatement that prompts the user if she inputs 0 or a negative number for her earth weight. #13. Mars’ gravity is about 17 percent less that of the earth’s....

  • Java programming 1. Write a program that reads an unspecified number of integers, determines how many...

    Java programming 1. Write a program that reads an unspecified number of integers, determines how many positive and negative value have been read, and computes the total and average of the input values (not counting zeros. Your program ends with the input 0. Display the average as a floating point number Here are sample runs: (red indicates a user input) Enter an integer, the input ends if it is 0: 1 2 -1 3 0 The number of positives is...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT