Unit Converters Application using packages

Algorithm:
Step 1 Start the process
Step 2 Prompt the user with converter choice 1. Currency 2.Distance 3. Time 4. Exit and the
choice.
Step 3 If user selects a Currency Converter then proceed to step 4
Step 4 Proceed with prompting Currency Converter Choices

1.DOLLER to INR 2. EURO to INR 3. YEN to INR

4.INR to DOLLER 5. INR to EURO 6. INR to YEN

7.Exit and get the user choice.


Step 4.1 If option 1 selected get in DOLLER and display DOLLER * 66.89 as INR
Step 4.2 If option 2 selected get in EURO and display EURO * 80 as INR
Step 4.3 If option 3 selected get in YEN and display YEN * 0.61 as INR
Step 4.4 If option 4 selected get in INR and display INR / 66.89 as DOLLER
Step 4.5 If option 5 selected get in INR and display INR / 80 as EURO
Step 4.6 If option 6 selected get in INR and display INR / 0.61 as YEN
Step 4.7 If option 7 selected exit from currency converter choice goto step 2


Step 5 If user selects a Distance Converter then proceed to step 6
Step 6 Proceed with prompting Distance Converter Choices

  1. METER to KILOMETER 2. MILES to KILOMETER

3. KILOMETER to METER 4. KILOMETER to MILES

5. Exit and get the user choice.


Step 6.1 If option 1 selected get in METER and display METER / 1000 as
KILOMETER
Step 6.2 If option 2 selected get in MILES and display MILES * 1.60934 as
KILOMETER
Step 6.3 If option 3 selected get in KILOMETER and display KILOMETER * 1000 as
METER
Step 6.4 If option 4 selected get in KILOMETER and display KILOMETER / 1.60934
as MILES
Step 6.5 If option 5 selected exit from distance converter choice goto step 2


Step 7 If user selects a Time Converter then proceed to step 8 currency
Step 8 Proceed with prompting Time Converter Choices

  1. HOURS to MINUTES 2. HOURS to SECONDS

3. MINUTES to HOURS 4. SECONDS to HOURS

5. Exit and get the user choice.


Step 8.1 If option 1 selected get in HOURS and display HOURS * 60 as MINUTES

Step 8.2 If option 2 selected get in HOURS and display HOURS * 3600 as SECONDS
Step 8.3 If option 3 selected get in MINUTES and display MINUTES / 60 as HOURS
Step 8.4 If option 4 selected get in SECONDS and display SECONDS / 3600 as
HOURS.
Step 8.5 If option 5 selected exit from tim converter choice and goto step 2


Step 9 If user selects exit then display Thank You !!! and exit from the system
Step 10 Stop the process

Currency.java

package com.msl.converters;
import java.util.Scanner;
public class Currency {
public static double covertEUROtoINR(double EURO) {
return EURO * 87.33;
}
public static double convertDOLLARtoINR(double DOLLAR) {
return DOLLAR * 75.35;
}
public static double convertYENtoINR(double YEN) {
return YEN * 0.66;
}
public static double covertINRtoEURO(double INR) {
return INR * 0.011;
}
public static double convertINRtoDOLLAR(double DOLLAR) {
return DOLLAR * 0.013;
}
public static double convertINRtoYEN(double YEN) {
return YEN * 1.51;
}
public static void userChoice(){
Scanner input = new Scanner(System.in);
int currency_choice = 0;
double money = 0;
while(currency_choice != 7){
System.out.println("\nCurrency Converter");
System.out.println(" As per Date: 14.10.2021 ");
System.out.println("------------------");
System.out.println("1. DOLLOR to INR\n2. EURO to INR\n3. YEN to INR\n"+ "4. INR to DOLLOR\n5. INR to EURO\n6. INR to YEN\n"+ "7. Exit\n\nEnter Your Choice");
currency_choice = input.nextInt();
switch(currency_choice){case 1:
System.out.println("Enter in DOLLER");
money = input.nextDouble();
System.out.println(money+" DOLLER is equal to "+Currency.convertDOLLARtoINR(money)+" INR");
break;
case 2:
System.out.println("Enter in EURO");
money = input.nextDouble();
System.out.println(money+" EURO is equal to "+Currency.covertEUROtoINR(money)+" INR");
break;
case 3:
System.out.println("Enter in YEN");
money = input.nextDouble();
System.out.println(money+" YEN is equal to "+Currency.convertYENtoINR(money)+" INR");
break;
case 4:
System.out.println("Enter in INR");
money = input.nextDouble();
System.out.println(money+" INR is equal to "+Currency.convertINRtoDOLLAR(money)+" DOLLORS");
break;
case 5:
System.out.println("Enter in INR");
money = input.nextDouble();
System.out.println(money+" INR is equal to "+Currency.covertINRtoEURO(money)+" EURO");
break;
case 6:
System.out.println("Enter in INR");
money = input.nextDouble();
System.out.println(money+" INR is equal to "+Currency.convertINRtoYEN(money)+" YEN");
break;
case 7:
break;
default:
System.out.println("Please choose valid option");
break;
}
}
}
}

Distance.java

package com.msl.converters;
import java.util.Scanner;
public class Distance {
public static double convertMeterToKiloMeter(double meter) {
return meter / 1000;
}
public static double convertMilesToKiloMeter(double miles) {
return miles * 1.60934;
}
public static double convertKiloMetertoMeter(double kilometer) {
return kilometer * 1000;
}
public static double convertKiloMeterToMiles(double kilometer) {
return kilometer / 1.60934;
}

public static void userChoice(){
Scanner input = new Scanner(System.in);
int distance_choice = 0;
double distance = 0;
while(distance_choice != 5){
System.out.println("\nDistance Converter");
System.out.println("------------------");
System.out.println("1. METER to KILOMETER\n2. MILES to KILOMETER\n"+ "3. KILOMETER to METER\n4. KILOMETER to MILES\n"+ "5. Exit\n\nEnter Your Choice");
distance_choice = input.nextInt();
switch(distance_choice){
case 1:
System.out.println("Enter in METERS");
distance = input.nextDouble();
System.out.println(distance+" METERS is equal to "+Distance.convertMeterToKiloMeter(distance)+" KILOMETER");
break;
case 2:
System.out.println("Enter in MILES");
distance = input.nextDouble();
System.out.println(distance+" MILES is equal to "+Distance.convertMilesToKiloMeter(distance)+" KILOMETER");
break;
case 3:
System.out.println("Enter in KILOMETER");
distance = input.nextDouble();
System.out.println(distance+" KILOMETER is equal to "+Distance.convertKiloMetertoMeter(distance)+" METER");
break;
case 4:
System.out.println("Enter in KILOMETER");
distance = input.nextDouble();
System.out.println(distance+" KILOMETER is equal to "+Distance.convertKiloMeterToMiles(distance)+" MILES");
break;
case 5:
break;
default:
System.out.println("Please choose valid option");
break;
}
}
}
}

Time.java

package com.msl.converters;
import java.util.Scanner;
public class Time {
public static double convertHoursToMinutes(double hours) {
return hours * 60;
}
public static double convertHoursToSeconds(double hours) {
return hours * 60 * 60;
}
public static double convertMinutesToHours(double minutes) {
return minutes / 60;
}
public static double convertSecondsToHours(double seconds) {
return seconds / 60 / 60;
}
public static void userChoice(){
Scanner input = new Scanner(System.in);
int time_choice = 0;
double time = 0;
while(time_choice != 5){
System.out.println("\nTime Converter");
System.out.println("-----------------");
System.out.println("1. HOURS to MINUTES\n2. HOURS to SECONDS\n"+ "3. MINUTES to HOURS\n4. SECONDS to HOURS\n"+ "5. Exit\n\nEnter Your Choice");
time_choice = input.nextInt();
switch(time_choice){
case 1:
System.out.println("Enter in HOURS");
time = input.nextDouble();
System.out.println(time+" HOURS is equal to "+Time.convertHoursToMinutes(time)+" MINUTES");
break;
case 2:
System.out.println("Enter in HOURS");
time = input.nextDouble();
System.out.println(time+" HOURS is equal to "+Time.convertHoursToSeconds(time)+" SECONDS");
break;
case 3:
System.out.println("Enter in MINUTES");
time = input.nextDouble();
System.out.println(time+" MINUTES is equal to "+Time.convertMinutesToHours(time)+" HOURS");
break;
case 4:
System.out.println("Enter in SECONDS");
time = input.nextDouble();
System.out.println(time+" SECONDS is equal to "+Time.convertSecondsToHours(time)+" HOURS");
break;
case 5:
break;
default:
System.out.println("Please choose valid option");
break;
}
}
}
}

Main.java

import java.util.Scanner;
import com.msl.converters.Currency;
import com.msl.converters.Distance;
import com.msl.converters.Time;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int choice = 0;
while(choice != 4){
System.out.println("Converters");
System.out.println("**********");
System.out.println("1. Currency\n2. Distance\n3. Time\n4. Exit\n\nEnter Your Choice");
choice = input.nextInt();
switch(choice){
case 1:
Currency.userChoice();
break;
case 2:
Distance.userChoice();
break;
case 3:
Time.userChoice();
break;
case 4:
break;
default:
System.out.println("Please choose valid option");
break;
}
}

System.out.println("Thank You !!!!");
System.out.println("Created by Shanthosh Lakshman");
}
}

Output:

Converters
**********
1. Currency
2. Distance
3. Time
4. Exit

Enter Your Choice

Compile java package file

javac -d . Currency.java
javac -d . Distance.java
javac -d . Time.java
javac -d . Main.java
java Main

Leave a comment