I have a list of exercises on ArrayList, but only the first question has left me with several doubts:
The Cofine class should implement methods for:
- Count the number of coins stored
- Count the number of coins of a given value
- Report which currency is the most valuable
I've done these classes:
But I think that maybe the question is badly formulated, if you can help me .. my doubt stays in this part Using ArrayList, implement a coin bank (another class) with the ability to: -receive coins and -calculate the total deposited in the piggy bank.
package Banco;
public class Moeda implements Interface {
private String nome;
private float valor;
// CONSTRUTOR
public Moeda(String nome, float valor) {
this.nome = nome;
this.valor = valor;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public float getValor() {
return valor;
}
public void setValor(float valor) {
this.valor = valor;
}
@Override
public void getnome() {
// TODO Auto-generated method stub
}
@Override
public void getnalor() {
// TODO Auto-generated method stub
}
}
package Banco;
public class Cofrinho {
public void recebemoedas(float moeda){ }
public void moedasnocofre(){}
public void nmoedas_valor(){}
public void maiormoeda(){}
}
package Banco;
import java.util.ArrayList;
public class Array {
public static void main(String[] args) {
// TODO Auto-generated method stub
ArrayList<Moeda> a = new ArrayList<Moeda>();
Cofrinho add = new Cofrinho ();
Moeda moeda1 = new Moeda ("euro", 5.00f);
Moeda moeda2 = new Moeda("dolar", 3.00f);
a.add(moeda2);
a.add(moeda1);
for(int i = 0; i< a.size();i++){
System.out.println("Moeda : "+a.get(i).getNome());
}
}
}