So, i'm working on creating a very basic currency converter from Pounds to Euros or Euros to Pounds. It takes the exchange rate from the user then asks which way to convert. Then asks the amount of currency.
This was easy for me to do in just one main class, but I want the logic to be seperate from the interface, and this is confusing me. In two classes I am able to take the user input for the conversion rate, then work out both Euros to Pounds and Pounds to Euros. But I can't work out how to make a system where the user chooses which one to do. I'll include my code below for people to see:
import java.util.Scanner;
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String outcome1 = "";
String outcome2 = "";
int conversion, result;
float exchange, input, output123;
CurrencyConverter converter = new CurrencyConverter();
System.out.println("Welcome to the Currency Converter!");
System.out.println("What is the current exchange rate from Pounds to Euro?");
exchange = scan.nextFloat();
System.out.println("Enter 1 to convert from Pounds to Euros and 2 to convert from Euros to Pounds");
System.out.println("How much would you like to convert?");
input = scan.nextFloat();
output123 = converter.PoundEuro(input, exchange);
System.out.println(output123);
output123 = converter.EuroPound(input, exchange);
System.out.println(output123);
}
}
CurrencyConverter
public class CurrencyConverter {
private float exchange, output, input;
private int conversion;
public CurrencyConverter() {
}
public float EuroPound(float input, float exchange) {
output = (input / exchange);
return output;
}
public float PoundEuro(float input, float exchange) {
output = (input * exchange);
return output;
}
public void checkForCurrency() {
if (conversion == 1) {
} else if (conversion == 2) {
}
}
}
I realise there are a few bits of code that actually do nothing, thats mainly because I was working on different things that I eventually deleted because they didn't work.
Does anyone have any advice on how to proceed? The main thing I want to achieve is allowing the user to pick the conversion by entering 1 or 2. And having this choice influence the sum carried out.
Cheers