Knowee
Questions
Features
Study Tools

Develop a Java program to simulate a currency converter from USD toIndian Rupees using control statements

Question

Develop a Java program to simulate a currency converter from USD toIndian Rupees using control statements

🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is a simple Java program that simulates a currency converter from USD to Indian Rupees. This program uses the Scanner class for input and if-else control statements to handle invalid input.

import java.util.Scanner;

public class CurrencyConverter {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        double usdToInrRate = 74.28; // You can update this rate as per the current market rate

        System.out.println("Welcome to USD to INR converter. Please enter the amount in USD:");
        double usd = scanner.nextDouble();

        if (usd < 0) {
            System.out.println("Invalid input. Please enter a positive amount.");
        } else {
            double inr = usd * usdToInrRate;
            System.out.println("Amount in INR: " + inr);
        }
    }
}

In this program, we first import the Scanner class which we use to get the user input. We then define the conversion rate from USD to INR. We ask the user to input the amount in USD. If the user inputs a negative number, we print an error message. If the user inputs a positive number, we convert the amount to INR by multiplying it with the conversion rate and print the result.

This problem has been solved

Similar Questions

Single File Programming QuestionProblem StatementLiam is an international traveller curious about currency exchange rates. Create a simple program to assist Liam in converting a given amount in dollars to Indian Rupees. Input the amount in dollars and display the equivalent amount in Rupees.Note: 1 Dollar = 83.3339 RupeeInput format :The input consists of a double value, dollar, representing the amount in dollars to be converted.Output format :The output displays the dollar amount with two decimal places followed by "Dollar = ", and the corresponding rupee amount with two decimal places followed by "Rupees".Refer to the sample output for the formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:1.0 ≤ dollar ≤ 1000.0Sample test cases :Input 1 :1.0Output 1 :1.00 Dollar = 83.33 RupeesInput 2 :158.8Output 2 :158.80 Dollar = 13233.42 RupeesInput 3 :1000.0Output 3 :1000.00 Dollar = 83333.90 RupeesCode Size : 1024 kbNote :The program will be evaluated only after the “Submit Code” is clicked.Extra spaces and new line characters in the program output will result in the failure of the test case.

Problem StatementA person is planning a trip abroad and wants to convert their local currency to the destination currency. Write a program for this where the exchange rate is fixed at 1.18. The program should take an amount in one currency as input, convert it to another currency using the exchange rate, and then output the converted amount rounded to two decimal places. Input format :The input consists of double value n, representing the currency.Output format :The output prints the converted currency in double value with two decimal places.Refer to the sample output for formatting specifications.Code constraints :In this scenario, the given test cases fall under the following constraints:1.00 ≤ n ≤ 5000.00Sample test cases :Input 1 :1.00Output 1 :1.18Input 2 :5000.00Output 2 :5900.00Input 3 :2568.95Output 3 :3031.36

These controls are designed to govern the conversion, purchase and transfer of domestic currency into foreign currencies.

Topic : Japanese yen – USD exchange rate 1. Introduction of the importance of JPY/USD 2. Download the FEX of JPY/USD in R 3. Conduct an ADF test in R to test whether the FEX has a unit root and is stationary 4. Calculate the log return and conduct an ADF test

Develop a Java program that creates a simple GUI application for atemperature converter. The program should allow users to converttemperatures between Celsius and Fahrenheit.

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.