{"id":3481,"date":"2017-07-16T13:43:33","date_gmt":"2017-07-16T13:43:33","guid":{"rendered":"https:\/\/www.testingdocs.com\/questions\/?p=3481"},"modified":"2024-12-14T04:47:51","modified_gmt":"2024-12-14T04:47:51","slug":"dollar-to-rupee-converter-java-program","status":"publish","type":"post","link":"https:\/\/www.testingdocs.com\/questions\/dollar-to-rupee-converter-java-program\/","title":{"rendered":"Dollar to Rupee Converter Java Program"},"content":{"rendered":"<h1>Dollar to Rupee Converter Java Program<\/h1>\n<p>In this tutorial, we will write a java program to convert Dollar to Rupee and vice-versa. We will provide a program menu to the user.<\/p>\n<p>The dollar to the rupee exchange rate is taken as a constant in the program. In real-time, the exchange would vary from time to time.<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3499\" src=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Dollar-to-Rupee-Exchange-Rate.png\" alt=\"Dollar to Rupee exchange rate\" width=\"1877\" height=\"806\" title=\"\" srcset=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Dollar-to-Rupee-Exchange-Rate.png 1877w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Dollar-to-Rupee-Exchange-Rate-300x129.png 300w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Dollar-to-Rupee-Exchange-Rate-1024x440.png 1024w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Dollar-to-Rupee-Exchange-Rate-768x330.png 768w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Dollar-to-Rupee-Exchange-Rate-1536x660.png 1536w\" sizes=\"auto, (max-width: 1877px) 100vw, 1877px\" \/><\/p>\n<h2>Environment<\/h2>\n<ul>\n<li>JDK<\/li>\n<li>Eclipse IDE<\/li>\n<li>Windows 10 operating system<\/li>\n<\/ul>\n<h2>Eclipse IDE<\/h2>\n<p>Instructions to create a Java application, Java Package, Java Class on Eclipse IDE:<\/p>\n<ul>\n<li>Create Java Project in Eclipse<\/li>\n<\/ul>\n<p><a href=\"https:\/\/www.testingdocs.com\/create-a-new-java-project-in-eclipse\/\">https:\/\/www.testingdocs.com\/create-a-new-java-project-in-eclipse\/<\/a><\/p>\n<ul>\n<li>Create Java Package in Eclipse<\/li>\n<\/ul>\n<p><a href=\"https:\/\/www.testingdocs.com\/create-java-package-in-eclipse-ide\/\">https:\/\/www.testingdocs.com\/create-java-package-in-eclipse-ide\/<\/a><\/p>\n<ul>\n<li>Create Java Class in Eclipse<\/li>\n<\/ul>\n<p><a href=\"https:\/\/www.testingdocs.com\/create-a-new-java-class-in-a-project\/\">https:\/\/www.testingdocs.com\/create-a-new-java-class-in-a-project\/<\/a><\/p>\n<ul>\n<li>Run Java Project in Eclipse<\/li>\n<\/ul>\n<p><a href=\"https:\/\/www.testingdocs.com\/run-java-project-in-eclipse\/\">https:\/\/www.testingdocs.com\/run-java-project-in-eclipse\/<\/a><\/p>\n<h2>Java Code Listing<\/h2>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">package com.testingdocs.sample.Questions;\r\n\r\n\/*\r\n * Disclaimer: Exchange rate varies from time to time\r\n * www.TestingDocs.com\r\n * \r\n *\/\r\nimport java.util.Scanner;\r\n\r\npublic class DollarToRupeeConverter {\r\n  \/\/dollar to rupee exchange rate\r\n  public final static double EXCHANGE_RATE=75.17;\r\n  public static void main(String[] args) {\r\n    int menuChoice=1;\r\n    Scanner keyboard=new Scanner(System.in);\r\n    while(menuChoice !=3) {\r\n      System.out.println(\" ------------------------------------ \");\r\n      System.out.println(\" Program Menu --- www.TestingDocs.com \");\r\n      System.out.println(\" ------------------------------------ \");\r\n\r\n      System.out.println(\"1. Convert Dollars to Rupees?\");\r\n      System.out.println(\"2. Convert Rupees to Dollars?\");\r\n      System.out.println(\"3. Quit the Program.\");\r\n      System.out.print(\"Enter your menu choice :=\");\r\n      menuChoice = keyboard.nextInt();\r\n      if(menuChoice &lt; 1 || menuChoice &gt; 3) {\r\n        System.out.println(\"Invalid Choice. Please Try again\");\r\n        continue;\r\n      }\r\n      if(menuChoice ==1) {\r\n        System.out.print(\"Enter the dollars:=\");\r\n        double dollars=keyboard.nextDouble();\r\n        double rupees= dollars*EXCHANGE_RATE;\r\n        System.out.println(\"Dollars \" + dollars + \" = Rupees \" + rupees );\r\n      }\r\n      if(menuChoice ==2) {\r\n        System.out.print(\"Enter the rupees:=\");\r\n        double rupees=keyboard.nextDouble();\r\n        double dollars= rupees\/EXCHANGE_RATE;\r\n        System.out.println(\"Rupees \" + rupees + \"  = Dollars \" + dollars );\r\n      }\r\n      if(menuChoice ==3) {\r\n        System.out.println(\"Have a nice day. GoodBye! \");\r\n      }\r\n    }\r\n  }\r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n<h3>Sample Run Output<\/h3>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\nProgram Menu &#8212; www.TestingDocs.com<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\n1.Convert Dollars to Rupees?<br \/>\n2.Convert Rupees to Dollars?<br \/>\n3.Quit the Program.<br \/>\nEnter your menu choice :=1<br \/>\nEnter the dollars:=2<br \/>\nDollars 2.0 = Rupees 150.34<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\nProgram Menu &#8212; www.TestingDocs.com<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\n1.Convert Dollars to Rupees?<br \/>\n2.Convert Rupees to Dollars?<br \/>\n3.Quit the Program.<br \/>\nEnter your menu choice :=2<br \/>\nEnter the rupees:=500<br \/>\nRupees 500.0 = Dollars 6.6515897299454565<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\nProgram Menu &#8212; www.TestingDocs.com<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\n1.Convert Dollars to Rupees?<br \/>\n2.Convert Rupees to Dollars?<br \/>\n3.Quit the Program.<br \/>\nEnter your menu choice :=4<br \/>\nInvalid Choice. Please Try again<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\nProgram Menu &#8212; www.TestingDocs.com<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\n1.Convert Dollars to Rupees?<br \/>\n2.Convert Rupees to Dollars?<br \/>\n3.Quit the Program.<br \/>\nEnter your menu choice :=3<br \/>\nHave a nice day. GoodBye!<\/p>\n<hr \/>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3502\" src=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Dollar-to-Rupee-Program.png\" alt=\"Dollar to Rupee Java Program\" width=\"1730\" height=\"1023\" title=\"\" srcset=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Dollar-to-Rupee-Program.png 1730w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Dollar-to-Rupee-Program-300x177.png 300w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Dollar-to-Rupee-Program-1024x606.png 1024w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Dollar-to-Rupee-Program-768x454.png 768w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Dollar-to-Rupee-Program-1536x908.png 1536w\" sizes=\"auto, (max-width: 1730px) 100vw, 1730px\" \/><\/p>\n<h3><\/h3>\n<h3>Rounding the double<\/h3>\n<p>Notice that there are several digits displayed after the dot. We can round the value to display less number of digits.<\/p>\n<p><a href=\"https:\/\/www.testingdocs.com\/questions\/how-to-round-a-double-value-in-java\/\">https:\/\/www.testingdocs.com\/questions\/how-to-round-a-double-value-in-java\/<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&#8212;<\/p>\n<h2>Java Tutorials<\/h2>\n<p>Java Tutorial on this website:<\/p>\n<p><a href=\"https:\/\/www.testingdocs.com\/java-tutorial\/\">https:\/\/www.testingdocs.com\/java-tutorial\/<\/a><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Dollar to Rupee Converter Java Program In this tutorial, we will write a java program to convert Dollar to Rupee and vice-versa. We will provide a program menu to the user. The dollar to the rupee exchange rate is taken as a constant in the program. In real-time, the exchange would vary from time to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-3481","post","type-post","status-publish","format-standard","hentry","category-java-programs","has-post-title","has-post-date","has-post-category","has-post-tag","has-post-comment","has-post-author",""],"_links":{"self":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/3481","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/comments?post=3481"}],"version-history":[{"count":10,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/3481\/revisions"}],"predecessor-version":[{"id":26431,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/3481\/revisions\/26431"}],"wp:attachment":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/media?parent=3481"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/categories?post=3481"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/tags?post=3481"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}