BigDecimal error can not find symbol

1

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.

    
asked by anonymous 23.04.2016 / 22:55

1 answer

1

This code uses a variable called d on line BigDecimal bd = new BigDecimal(d).setScale(2, RoundingMode.HALF_EVEN); . This variable is not declared anywhere in the code. This certainly causes the problem. You have to see what you want to use there. If the method should get a parameter or if it should catch a class member.

In this line df.doubleValue(conversion); has another undeclared variable in use. Maybe in this case it was to be bd instead of df .

Working with float and double for monetary value does not work . But this is another problem.

Playing random codes also does not work. The code needs to make sense, it needs to have a minimum of consistency with what exists.

    
23.04.2016 / 23:34