Question__2

PHOTO EMBED

Tue Apr 18 2023 21:57:27 GMT+0000 (Coordinated Universal Time)

Saved by @Mohamedshariif #java

/*Question 2.  
    Write a program that prompts the user to enter the exchange rate 
    from currency in U.S. dollars to Turkish Lira. 
    Prompt the user to enter 0 to convert from U.S. dollars to Turkish Lira
    and 1 to convert from Turkish Lira and U.S. dollars. 
    Prompt the user to enter the amount in U.S. dollars 
    or Turkish Lira to convert it to Turkish Lira or U.S. dollars, respectively.
        */
                
        Scanner scanner = new Scanner(System.in);
        
       
        System.out.println("Enter the rate of exchange:");
        double exchangeRate = scanner.nextDouble();
        
        System.out.println("press 0: to convert Dollar to Turkish Lira\npress 1: to convert Turkish Lira to Dollar  ");
        int choice = scanner.nextInt();
        double amount;
        if(choice == 1)
        {
            System.out.println("Enter the amount in Dollar: ");
            amount = scanner.nextDouble();
            amount = amount * exchangeRate;
            System.out.println("The amount in Dollar is: " + amount);
        }
        else if ( choice == 0)
        {
            System.out.println("Enter the amount in Turkish Lira: ");
            amount = scanner.nextDouble();
            amount = amount / exchangeRate;
            System.out.println("The amount in Turkish Lira is: " + amount);
        }
    }
}
content_copyCOPY