0
I have an exercise list on Arraylist , but only the first question has left me with several doubts :
- Implement an interface with abstract methods getName, getValor, which should be implemented in the concrete class Currency. The currency class must have a constructor that starts the name and value attributes of the currency and, in addition to the interface methods, the set methods. Using Arraylist, implement a coin bank (another class) with the ability to: -receive coins and -calculate the total deposited in the piggy bank.
The Piggy Bank class must implement methods for:
- Count the number of coins stored
- Count the number of coins of a given value
- Provide the largest currency
I’ve done these classes:
But I think that perhaps the question is poorly formulated, if you can help me .. my doubt is 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());
}
}
}