Given an amount in R $ convert it to dollar.
Well, based on this context, the teacher asked us to use the object-oriented paradigm. Before I should clarify that I use BlueJ ide to solve the problem, according to my teacher it is better for didactic purposes, I created a class Cambio
and a class Main
, that is leased the methods that receives the amount, the rate exchange and conversion, this initializes system so to say contained the main
method.
class Change:
public class Cambio
{
private float amount;
private double conversion;
private float exchange;
/**
* Construtor
*/
public Cambio(float amount, float exchange)
{
setAmount(amount);
setExchange(exchange);
conversion = 0;
}
/**
* Método modificador: quantia.
*/
public void setAmount(float amount)
{
this.amount = amount;
}
/**
* Método modificador: taxa.
*/
public void setExchange(float exchange)
{
this.exchange = exchange;
}
/**
* Metodo acessador: quantia
*/
public float getAmount()
{
return this.amount;
}
/**
* Metodo acessador: taxa
*/
public float getExchange()
{
return this.exchange;
}
/**
* Metodo modificador: calcula o cambio.
*/
public double getConversion()
{
BigDecimal bd = new BigDecimal(d).setScale(2, RoundingMode.HALF_EVEN);
conversion = (float)this.amount / (float)this.exchange;
return df.doubleValue(conversion);
}
}
Class main:
public class Main
{
public static void main(String[] args)
{
Scanner read = new Scanner(System.in);
System.out.print("Digite a quantia: ");
float amount = read.nextFloat();
System.out.print("Digite a taxa cambial: ");
float exchange = read.nextFloat();
Cambio cb = new Cambio(amount, exchange);
System.out.println("A valor em dolar: USS$" + cb.getConversion());
}
}
I am using the class to format the values BigDecimal
. It gives an error and does not compile:
can not find symbol (BigDecimal class)
On line:
BigDecimal bd = new BigDecimal(d).setScale(2, RoundingMode.HALF_EVEN);
As far as I understand reading the BlueJ documentation I'm calling an object that does not exist. I already used BigDecimal
to format values in double
in another exercise.