Building a Currency Converter in Java - Java Projects

Learn via video course
FREE
View all courses
Java Course - Mastering the Fundamentals
Java Course - Mastering the Fundamentals
by Tarun Luthra
1000
5
Start Learning
Java Course - Mastering the Fundamentals
Java Course - Mastering the Fundamentals
by Tarun Luthra
1000
5
Start Learning
Topics Covered

In this article, we are going to create a Java project that converts currency. This currency calculator can convert between the dollar,euro, rupee, andyen. We `are going to use a switch and function to create a currency converter.

What are we building?

We are building a currency converter that allows the user to convert one currency to another, such as the dollar, yen, and rupee.

Pre-requisites

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

How Are We Going to Build Currency-Converter?

  • First, we are going to take the user currency input in which currency he wants to enter the amount
  • Then will take the amount of input from the user
  • Then, using the switch case and function calculate the amount in the destinated currency

Final Output

currency-converter-currency-converter

Requirements

  • Scanner Class: Scanner class in the java.util package is used to get input of primitive types like int, double, etc., and strings. The simplest method to read input in a Java program is this one.

Building a Currency Converter in java

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

Create a class name CurrencyConverter

Create a class called CurrencyConverter in the Java file. Import the Scanner class and add the main method in the file.

Create a Switch case

We will ask the user for currency and amount and create a switch case.

Code Explanation

In the above code, we have taken input from the user about the currency he wants to convert and the amount of currency. Then, based on his currency, we are going to convert it to other currencies. For example, if the user has Ruppe, we are going to convert it to Dollars and Euros.

Add methods to convert to other currencies

We only need to add a method in CurrencyConverter class, so our code works perfectly.

Output:

Code Explanation

In the above code, using simple multiplication, we created three functions that convert the rupee to other currencies, the dollar to other currencies, and the euro to other currencies.

What's next?

We have created a Currency Converter in Java, but that doesn't look too well. Users can't interact better with this. By using a graphical user interface users can interact better. He can easily use our application. This allows our application to be more user-friendly. Our Application will be more attractive than before. To make it better, try to create a GUI interface using Swing in java The Java Swing Framework is a component of the Java Foundation Classes (JFC), a collection of classes that help programmers build Java-based applications.

Conclusion

  • In this article, we have created a currency converter
  • This converter can convert between Ruppe, euro and US Dollar.
  • We created this using Simple switches and methods in Java.
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more