0% found this document useful (0 votes)
57 views

Assignment 1 Programming

The document contains code for a currency converter application with two Java classes. The CurrencyConverter class defines methods for converting between currencies, including Ringgit Malaysia, Euros, and Indonesian Rupiah. The TestCurrencyConverter class tests the converter by getting user input for the currency to convert from and to, the amount, and displays the converted value. It handles converting between each currency combination and displays output showing the conversion.

Uploaded by

Visnu Manimaran
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views

Assignment 1 Programming

The document contains code for a currency converter application with two Java classes. The CurrencyConverter class defines methods for converting between currencies, including Ringgit Malaysia, Euros, and Indonesian Rupiah. The TestCurrencyConverter class tests the converter by getting user input for the currency to convert from and to, the amount, and displays the converted value. It handles converting between each currency combination and displays output showing the conversion.

Uploaded by

Visnu Manimaran
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

currencyConverter.

java

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Question1;

/**
*
* @author Nasuha
*/
public class CurrencyConverter {

private String fromCurrency;


private String toCurrency;
private double conversionValue;
private double convertedValue;

public CurrencyConverter(String fromCurrency, String toCurrency, int conversionValue) {


this.fromCurrency = fromCurrency;
this.toCurrency = toCurrency;
this.conversionValue = conversionValue;
}
public double convertValue(double convertedValue) {
return convertedValue;
}
public double setConvertedValue(double convertedValue) {
this.convertedValue = convertedValue;
return convertedValue;
}
public double currencyConvert(double newConvertValue) {
int choose, choose2;
double x, y, z;
double conversionAmount;
double rm = 4.73950;
double euro = 0.210993;
double rupiah = 3509.79;

return newConvertValue;
}
public void displayInfo() {
System.out.println("RM Value : ");
System.out.println("Euro Value : ");
System.out.println("Indonesian Rupiah Value : ");
}
}

testCurrencyConverter.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Question1;

import java.util.Scanner;

/**
*
* @author Nasuha
*/
public class TestCurrencyConverter {
public static void main(String arg[]) {

Scanner scan = new Scanner(System.in);

System.out.println("CURRENCY CONVERTER");
System.out.println("----------------------------------------");
System.out.println("Choose currency to be converted");
System.out.print("FROM [1:Ringgit Malaysia 2:Euro 3:Indonesian Rupiah] : ");
int choice = scan.nextInt();

String inType = null;


switch (choice) {
case 1:
inType = "RM";
break;
case 2:
inType = "Euro";
break;
case 3:
inType = "Rupiah";
default:
System.out.print("Choose again");
}
System.out.print("TO [1:Ringgit Malaysia 2:Euro 3:Indonesian Rupiah] : ");
int choice2 = scan.nextInt();
String inType1 = null;
switch (choice2) {
case 1:
inType1 = "RM";
break;
case 2:
inType1 = "Euro";
break;
case 3:
inType1 = "Rupiah";
default:
System.out.println("Choose again");
}
System.out.print("Enter the conversion amount : ");
double conversionValue = scan.nextDouble();

if (choice == 1 && choice2 == 1) {


System.out.println("----------------------------------------");
System.out.print("SAME CURRENCY!");
}
if (choice == 1 && choice2 == 2) {
double euro = 0.210993;
double rate = conversionValue * euro;
System.out.println("----------------------------------------");
System.out.printf("Currency converted : %.4f ", rate);
}
if (choice == 1 && choice2 == 3) {
double rupiah = 3509.79;
double rate = conversionValue * rupiah;
System.out.println("----------------------------------------");
System.out.printf("Currency converted : %.4f ", rate);
}
if (choice == 2 && choice2 == 1) {
double rm = 4.73950;
double rate = conversionValue * rm;
System.out.println("----------------------------------------");
System.out.printf("Currency converted : %.4f ", rate);
}
if (choice == 2 && choice2 == 2) {
System.out.println("----------------------------------------");
System.out.print("SAME CURRENCY!");
}
if (choice == 2 && choice2 == 3) {
double rupiah = 3509.79;
double rate = conversionValue * rupiah;
System.out.println("----------------------------------------");
System.out.printf("Currency converted : %.4f ", rate);
}
if (choice == 3 && choice2 == 1) {
double rm = 4.73950;
double rate = conversionValue * rm;
System.out.println("----------------------------------------");
System.out.printf("Currency converted : %.4f ", rate);
}
if (choice == 3 && choice2 == 2) {
double euro = 0.210993;
double rate = conversionValue * euro;
System.out.println("----------------------------------------");
System.out.printf("Currency converted : %.4f ", rate);
}
if (choice == 3 && choice2 == 3) {
System.out.println("----------------------------------------");
System.out.print("SAME CURRENCY");
}
}
}

Output

You might also like