1
Given an amount in R$ convert it into dollar.
Well, based on this context, the teacher requested that we use the object orientation paradigm. Before I should clarify that I use to order ide Bluej to solve the problem, according to my teacher he is better for didactic purposes, I created a class Cambio
and a class Main
, that is leased the methods that receives the amount, the exchange rate and the conversion, this initializes system so to speak contained the method main
.
exchange class:
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);
}
}
Main class:
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
. Make a mistake and don’t compile:
cannot find Symbol (Bigdecimal class)
On the 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 doesn’t exist. I’ve used the BigDecimal
to format values in double
in another exercise.
There is nothing else in your code? Which line gives the error? Show the line, no use speaking the number.
– Maniero
Not all code is this, the line that gives error is 62 (Bigdecimal db = new Bigdecimal(d). setScale(2, Roundingmode.HALF_EVEN))
– Marcus Vinicius