Vlw brother…
consegui mano…consegui mais agora …to fazendo outros exercicios espero que se eu encontrar um proximo obstaculo
vcs …Me ajudem…
DeSDE jah agradeço pela atenção e pela disposição o código final fikou assim !!!
package livro;
import java.util.Calendar;
import java.util.Date;
public class CreditCard {
//Variaveis de instância:
private String number;
private String name;
private String bank;
private double balance;
protected double juros = 0.02;
protected double jurosAtraso = 0.1;
private int limit;
public Calendar datadeVencimento = Calendar.getInstance();
public Calendar datadePagamento = Calendar.getInstance();
//Construtor:
CreditCard(String no, String nm, String bk, double bal, int lim, int ano, int mes, int dia) {
number = no;
name = nm;
bank = bk;
balance = bal;
limit = lim;
datadeVencimento.set(ano, mes, dia);
}
//Métodos de acesso:
public String getNumber() {
return number;
}
public String getName() {
return name;
}
public String getBank() {
return bank;
}
public double getBalance() {
return balance;
}
public int getLimit() {
return limit;
}
public Calendar getdataVenc() {
return datadeVencimento;
}
//Métodos de modificação
public void setNumber(String n) {
this.number = n;
}
public void setName(String nome) {
this.name = nome;
}
public void setBank(String bank) {
this.bank = bank;
}
public void setBalance(Double bal) {
this.balance = bal;
}
public void setLimit(int lim) {
this.limit = lim;
}
public void setdataVenc(int ano, int mes, int dia) {
this.datadeVencimento.set(ano, mes, dia);
}
//Métodos de ação:
public boolean chargelt(double price) { //Debita
if (price > 0 && price + balance < (double) limit) {
System.out.println("O cliente " + this.getName() + " debitou o valor de R$:" + price);
balance += price;
System.out.println();
return true;//Debitado!
} else {
System.out.println("Operação não realizada!!!!");
System.out.println();
return false;//Neste não foi efetuada!
}
}
public void makePayment(double payment) {
if ((datadePagamento.before(datadeVencimento))) {
if (payment > 0) {
balance -= payment * jurosAtraso;
}
} else {
if (payment > 0) {
balance -= payment * juros;
}
}
}
public static void printCard(CreditCard c) {//Impri informações sobre o cartão
int dia = c.datadeVencimento.get(Calendar.DATE);
int mes = c.datadeVencimento.get(Calendar.MONTH);
int ano = c.datadeVencimento.get(Calendar.YEAR);
System.out.println("Number = " + c.getNumber());
System.out.println("Name = " + c.getName());
System.out.println("Bank = " + c.getBank());
System.out.println("Balance = " + c.getBalance());
System.out.println("Limit = " + c.getLimit());
System.out.println("Data de vencimento: " + dia + "/" + mes + "/" + ano);
System.out.println();
}
}
package livro;
import java.util.Calendar;
public class Test {
public static void main(String[] args) {
CreditCard wallet[] = new CreditCard[10];
wallet[0] = new CreditCard("5391 0375 9387 5309", "John Bowman", "California Savings", 0.0, 2500, 2010, 02, 21);
wallet[1] = new CreditCard("5391 0375 9387 5309", "John Bowman", "California Federal", 0.0, 3500, 2010, 03, 11);
wallet[2] = new CreditCard("5391 0375 9387 5309", "John Bowman", "California Finance", 0.0, 5000, 2010, 03, 11);
for (int i = 1; i <= 16; i++) {
wallet[0].chargelt((double) i);
wallet[1].chargelt(2.0 * i); //Conversão implícita
wallet[2].chargelt((double) 3 * i);//conversão explicita
}
System.out.println("Card payments: ");
for (int i = 0; i < 3; i++) {
CreditCard.printCard(wallet[i]);
while (wallet[i].getBalance() > 100.0) {
wallet[i].makePayment(100.0);
System.out.println("New balance =" + wallet[i].getBalance());
}
System.out.println();
}
}