//assignment 7, lab 2
//convert different currencies
import java.util.*;
public class ass7{
public static void main(){
double cash_in;
Currencyconv sek_pula = new Currencyconv(1.65);
Currencyconv sek_rand = new Currencyconv(1.14);
Scanner s = new Scanner(System.in);
System.out.println("How many SEK? Result in pula");
cash_in = s.nextDouble();
System.out.println("That is "+sek_pula.returnCurr2(cash_in)+" Pula");
}
}
class Currencyconv{
/*
This class assumes that the exchange rate is in the format of
curr1/curr2, that is to say that if an instance is called sek_usd the
rate should be around 8 or so
*/
//internal variables
private double cash_in, cash_out, rate;
//constructors
public Currencyconv(double rate_in){
if(rate_in < 0){
rate=0;
}
else{
rate=rate_in;
}
}
//methods
//returns currency 2 given currency 1
public double returnCurr2(double cash_in){
if( cash_in < 0){
cash_out=0;
}
else{
cash_out=cash_in*rate;
}
return cash_out;
}
//returns currency 1 given currency 2
public double returnCurr1(double cash_in){
if( cash_in < 0){
cash_out=0;
}
else{
cash_out=cash_in/rate;
}
return cash_out;
}
//set the exchange rate to something different
public void changeRate(double rate_in){
if( rate_in < 0){
rate=0;
}
else{
rate=rate_in;
}
}
}