π Day 7 β Building UnitXpress | #30Days30Projects

π Project Overview
UnitXpress is a command-line Java application designed to simplify unit conversion. Whether you're dealing with distances, weights, temperatures, currencies (mocked), or even speed and area β UnitXpress has you covered.
This mini-tool aims to strengthen your understanding of:
Javaβs
switch
statementsScanner
class input handlingBasic CLI design
Modular expansion for future features
π οΈ Technologies Used
Java (Core Java)
Command-Line Interface (CLI)
π‘ Features
The app currently supports:
Conversion Type | Units |
Distance | Kilometers β Miles |
Weight | Kilograms β Pounds |
Temperature | Celsius β Fahrenheit |
Currency | INR β USD (Mock rate) |
Area | Square Meter β Square Feet |
Speed | km/h β mph |
π How It Works
Upon running the program, the user is presented with a menu of conversion options. After selecting a choice, the program prompts for an input value, performs the conversion, and displays the result.
π§ Key Concepts Learned
Using
switch-case
for menu-based interactionReal-world use of basic math functions
Creating a clean and interactive CLI application
Building expandable code structure for future enhancements
π Code Walkthrough
import java.util.Scanner;
public class UnitXpress {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int choice;
do {
System.out.println("\n========== UnitXpress CLI ==========");
System.out.println("1. Kilometers β Miles");
System.out.println("2. Kilograms β Pounds");
System.out.println("3. Celsius β Fahrenheit");
System.out.println("4. INR β USD (Mock)");
System.out.println("5. Square Meter β Square Feet");
System.out.println("6. Speed: km/h β mph");
System.out.println("0. Exit");
System.out.print("Choose conversion type: ");
choice = sc.nextInt();
switch (choice) {
case 1:
System.out.print("Enter km: ");
double km = sc.nextDouble();
System.out.println("Miles: " + km * 0.621371);
break;
case 2:
System.out.print("Enter kg: ");
double kg = sc.nextDouble();
System.out.println("Pounds: " + kg * 2.20462);
break;
case 3:
System.out.print("Enter Celsius: ");
double c = sc.nextDouble();
System.out.println("Fahrenheit: " + (c * 9 / 5 + 32));
break;
case 4:
System.out.print("Enter INR: ");
double inr = sc.nextDouble();
System.out.println("USD (Mock Rate 1 USD = 83 INR): " + (inr / 83));
break;
case 5:
System.out.print("Enter sqm: ");
double sqm = sc.nextDouble();
System.out.println("sqft: " + (sqm * 10.7639));
break;
case 6:
System.out.print("Enter km/h: ");
double kmh = sc.nextDouble();
System.out.println("mph: " + (kmh * 0.621371));
break;
case 0:
System.out.println("Thank you for using UnitXpress");
break;
default:
System.out.println("Invalid choice! Try again.");
}
} while (choice != 0);
sc.close();
}
}
π₯οΈ Sample Output
========== UnitXpress CLI ==========
1. Kilometers β Miles
2. Kilograms β Pounds
3. Celsius β Fahrenheit
4. INR β USD (Mock)
5. Square Meter β Square Feet
6. Speed: km/h β mph
0. Exit
Choose conversion type: 1
Enter km: 5
Miles: 3.106855
========== UnitXpress CLI ==========
Choose conversion type: 3
Enter Celsius: 100
Fahrenheit: 212.0
π Ideas to Extend
π Add Bi-directional Conversions (e.g., ask if user wants to go km β miles or miles β km)
π± Use Real-Time Currency API (e.g., ExchangeRate API or OpenExchangeRates)
π¨ Build GUI with Swing/JavaFX
π± Convert into an Android App for mobile tools
πΎ Add conversion history tracking
π― Learning Outcomes
Reinforced
switch
statements and loops in JavaBuilt confidence in accepting user input and handling edge cases
Practiced writing modular code that's easy to expand
Started thinking in terms of real-world utility when coding
π Final Thoughts
This project proved that even a simple utility app can be a great way to reinforce fundamentals while building something useful. Itβs beginner-friendly, practical, and scalable.
Whether you're just learning Java or looking to brush up on CLI tools β give UnitXpress a try, or fork it and make it your own!
π GitHub Repo: https://github.com/Rushi-Unge/30Days30Projects
π¬ Share your feedback, or suggest more conversions!
Subscribe to my newsletter
Read articles from Rushikesh Unge directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
