Advertisement
gastaojunior

Untitled

Jun 28th, 2013
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.58 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package Cap1_reforco;
  6.  
  7. import java.util.Date;
  8.  
  9. /**
  10.  *
  11.  * @author gastao
  12.  */
  13. public class CreditCard {
  14.     // Instance variables:
  15.  
  16.     private String number;
  17.     private String name;
  18.     private String bank;
  19.     private double balance;
  20.     private int limit;
  21.     private double tx;
  22.     private Date dataVencimento;
  23.  
  24.     public Date getDataVencimento() {
  25.         return dataVencimento;
  26.     }
  27.  
  28.     public String getNumber() {
  29.         return number;
  30.     }
  31.  
  32.     public String getName() {
  33.         return name;
  34.     }
  35.  
  36.     public String getBank() {
  37.         return bank;
  38.     }
  39.  
  40.     public double getBalance() {
  41.         return balance;
  42.     }
  43.  
  44.     public void setNumber(String number) {
  45.         this.number = number;
  46.     }
  47.  
  48.     public void setName(String name) {
  49.         this.name = name;
  50.     }
  51.  
  52.     public void setBank(String bank) {
  53.         this.bank = bank;
  54.     }
  55.  
  56.     public void setBalance(double balance) {
  57.         this.balance = balance;
  58.     }
  59.  
  60.     public void setLimit(int limit) {
  61.         this.limit = limit;
  62.     }
  63.  
  64.     public void setTx(double tx) {
  65.         this.tx = tx;
  66.     }
  67.  
  68.     public void setDataVencimento(Date dataVencimento) {
  69.         this.dataVencimento = dataVencimento;
  70.     }
  71.  
  72.     public int getLimit() {
  73.         return limit;
  74.     }
  75.  
  76.     public double getTx() {
  77.         return tx;
  78.     }
  79.  
  80.     ;
  81.   // Constructor:
  82.   CreditCard(String nm, String bk, double bal, int lim, String no, double txx, Date dtv) {
  83.         number = no;
  84.         name = nm;
  85.         bank = bk;
  86.         balance = bal;
  87.         limit = lim;
  88.         tx = txx;
  89.         dataVencimento = dtv;
  90.     }
  91.     // Accessor methods:
  92.  
  93.     // Action methods:
  94.     public boolean chargeIt(double price) { // Make a charge
  95.         if (price + balance > (double) limit) {
  96.             return false; // There is not enough money left to charge it
  97.         }
  98.         balance += price;
  99.         return true; // The charge goes through in this case
  100.     }
  101.  
  102.     public void makePayment(double payment) { // Make a payment
  103.         Date dataHoje = new Date();
  104.  
  105.         if (dataHoje.compareTo(dataVencimento) > 0 ) {
  106.             balance *= (tx / 100) + 1;
  107.         }
  108.         balance -= payment;
  109.     }
  110.  
  111.     public static void printCard(CreditCard c) { // Print a card's information
  112.         System.out.println("Number = " + c.getNumber());
  113.         System.out.println("Name = " + c.getName());
  114.         System.out.println("Bank = " + c.getBank());
  115.         System.out.println("Balance = " + c.getBalance()); // Implicit cast
  116.         System.out.println("Limit = " + c.getLimit()); // Implicit cast
  117.     }
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement