Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package Cap1_reforco;
- import java.util.Date;
- /**
- *
- * @author gastao
- */
- public class CreditCard {
- // Instance variables:
- private String number;
- private String name;
- private String bank;
- private double balance;
- private int limit;
- private double tx;
- private Date dataVencimento;
- public Date getDataVencimento() {
- return dataVencimento;
- }
- public String getNumber() {
- return number;
- }
- public String getName() {
- return name;
- }
- public String getBank() {
- return bank;
- }
- public double getBalance() {
- return balance;
- }
- public void setNumber(String number) {
- this.number = number;
- }
- public void setName(String name) {
- this.name = name;
- }
- public void setBank(String bank) {
- this.bank = bank;
- }
- public void setBalance(double balance) {
- this.balance = balance;
- }
- public void setLimit(int limit) {
- this.limit = limit;
- }
- public void setTx(double tx) {
- this.tx = tx;
- }
- public void setDataVencimento(Date dataVencimento) {
- this.dataVencimento = dataVencimento;
- }
- public int getLimit() {
- return limit;
- }
- public double getTx() {
- return tx;
- }
- ;
- // Constructor:
- CreditCard(String nm, String bk, double bal, int lim, String no, double txx, Date dtv) {
- number = no;
- name = nm;
- bank = bk;
- balance = bal;
- limit = lim;
- tx = txx;
- dataVencimento = dtv;
- }
- // Accessor methods:
- // Action methods:
- public boolean chargeIt(double price) { // Make a charge
- if (price + balance > (double) limit) {
- return false; // There is not enough money left to charge it
- }
- balance += price;
- return true; // The charge goes through in this case
- }
- public void makePayment(double payment) { // Make a payment
- Date dataHoje = new Date();
- if (dataHoje.compareTo(dataVencimento) > 0 ) {
- balance *= (tx / 100) + 1;
- }
- balance -= payment;
- }
- public static void printCard(CreditCard c) { // Print a card's information
- System.out.println("Number = " + c.getNumber());
- System.out.println("Name = " + c.getName());
- System.out.println("Bank = " + c.getBank());
- System.out.println("Balance = " + c.getBalance()); // Implicit cast
- System.out.println("Limit = " + c.getLimit()); // Implicit cast
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement