Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. class Conta {
  2.  
  3. //atributos
  4. private int numero;
  5. private String titular;
  6. private double saldo;
  7. private double limite;
  8.  
  9. //construtor
  10. Conta(int numero, String titular, double saldo, double limite) {
  11. this.numero = numero;
  12. this.titular = titular;
  13. this.saldo = saldo;
  14. this.limite = limite;
  15. }
  16.  
  17. private boolean podeSacar(double valor_a_sacar) {
  18. double valorDisponivelASacar = this.saldo + this.limite;
  19. return valor_a_sacar <= valorDisponivelASacar;
  20. }
  21.  
  22. boolean saca(double valor) {
  23. if(this.podeSacar(valor)) {
  24. this.saldo -= valor;
  25. return true;
  26. }
  27. throw new IllegalArgumentException("O valor passou o limite");
  28. }
  29.  
  30. void deposita(double valor) {
  31. this.saldo += valor;
  32. }
  33.  
  34. void extrato() {
  35. System.out.println("Saldo de " + this.saldo + " do titular " + this.titular);
  36. }
  37.  
  38. void transfere(double valor, Conta conta) {
  39. this.saca(valor);
  40. this.deposita(valor);
  41. }
  42.  
  43. public double getLimite() {
  44. return limite;
  45. }
  46.  
  47. public void setLimite(double limite) {
  48. this.limite = limite;
  49. }
  50.  
  51. public int getNumero() {
  52. return numero;
  53. }
  54.  
  55. public String getTitular() {
  56. return titular;
  57. }
  58.  
  59. public double getSaldo() {
  60. return saldo;
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement