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 Program 1. Write a class that reads in a group of test scores (positive integers...

    Java Program 1. Write a class that reads in a group of test scores (positive integers from 1 to 100) from the keyboard. The main method of the class calls a few other methods to calculate the average of all the scores as well as the highest and lowest score. The number of scores is undetermined but there will be no more than 50. A negative value is used to end the input loop. import java.util.Scanner; public class GradeStat {...

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

  • Assignment: Write a program that prompts the user to enter 10 numbers, and then displays the...

    Assignment: Write a program that prompts the user to enter 10 numbers, and then displays the mean and standard deviation of these numbers I already have the source code all done. I just need this translated into a flowchart. Again I just need the flowchart, not any source code. I have already provided the source code below. Need Flowchart version of my code Here is the source code: public class Mean_Standard_Deviation {    public static void main(String[] args) {   ...

  • Lab Topics • The basics of Array object Use the following Coding Guidelines • When declaring...

    Lab Topics • The basics of Array object Use the following Coding Guidelines • When declaring a variable, you usually want to initialize it. Remember you cannot initialize a number with a string. Remember variable names are case sensitive. Use tabs or spaces to indent code within blocks (code surrounded by braces). Use white space to make your program more readable. Use comments after the ending brace of classes, methods, and blocks to identify to which block it belongs. Problem...

  • Programming Project #5 Project Outcomes: Develop a Java program that Uses selection constructs (if, and if...

    Programming Project #5 Project Outcomes: Develop a Java program that Uses selection constructs (if, and if else). Uses the Java iteration constructs (while, do, for). Uses static variables. Ensure integer variables input are within a range that will not cause integer overflow. Uses proper design techniques including reading UML Class Diagrams Background Information: The Unified Modeling Language (UML) provides a useful notation for designing and developing object-oriented software systems. One of the basic components of the UML is a class...

  • Please Write the following program in c# You are to write an application which will create...

    Please Write the following program in c# You are to write an application which will create a company, add agents (their name, ID, and weekly sales) to that company, and printout the details of all agents in the company. The application will contain three classes: Agent.cs, Company.cs, and CompanyTest.cs (this class is already provided). Flow of the application: The CompanyTest class creates an object of the Company class and reserves space for five agents. At this point if you call...

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

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