Forum de discussion
Forum « Programmation JAVA » (archives)
Oiel expert en polymo.....aidez moi
Envoyé: 12 février 2004, 9h37 par jolielady
Voici mon code:
[code]
class AccountRob {
public static void main(String[] args) {
/**set account opening*/
Account account = new Account();
System.out.println("Initializing account... " + account.getBalance());
account.setID(1122);
System.out.println("Retrieving customer ID #... " + account.getID());
account.setAnnualInterestRate(4.5);
System.out.println("Retrieving annual interest rate... " + account.getAnnualInterestRate() + "%");
System.out.println("Calculating monthly interest rate... " + account.getMonthlyInterestRate() + "%");
account.setBalance(20000);
System.out.println("Retrieving customers initial account balance... $" + account.getBalance());
account.withdraw(3500);
System.out.println("Retrieving customers account balance post withdrawl... $" + account.getBalance());
account.deposit(3000);
System.out.println("Retrieving customers account balance post deposit... $" + account.getBalance());
/**Print statement to customer*/
System.out.println("\n\nCustomer ID #> " + account.getID() + ". Your new account balance is $"
+ account.getBalance() + "\nYou will accrue monthly interest at a rate of "
+ account.getMonthlyInterestRate() + "%");
System.out.println("\nThank you for banking at the Bank of Rob. Have a good day.");
}
}
class Account {
/**declare variables*/
private int id;
private double balance;
private double annualInterestRate;
private double monthlyInterestRate;
private double withdraw;
private double deposit;
private double ODLimit;
/**Default constructor*/
public Account() {
}
public Account(int id, double balance, double annualInterstRate) {
this.id = id;
this.balance = balance;
this.annualInterestRate = annualInterestRate;
}
public Account(double balance, double ODLimit) {
this.balance = balance;
this.ODLimit = ODLimit;
}
/**set an id*/
public void setID(int id) {
this.id = id;
}
/**return id*/ public int getID()
{
return id;
}
/**return balance*/
public double getBalance() {
return balance; }
/**set new balance*/
public void setBalance(double balance) {
this.balance = balance; }
/**setting annualInterestRate*/ public void setAnnualInterestRate(double annualInterestRate) {
this.annualInterestRate = annualInterestRate; }
/**return annualInterestRate*/ public double getAnnualInterestRate() {
return annualInterestRate; }
/**find monthly interest rate*/ public double getMonthlyInterestRate() {
double monthlyInterestRate = annualInterestRate / 1200;
return monthlyInterestRate; }
/** deposit amount*/
public void deposit(double amount) {
balance +=amount; }
/** withdraw amount*/
public void withdraw(double amount) {
balance = balance - amount; }}
//ChequingAccount.java - chequing account... with overdraft limitpublic
class ChequingAccount extends Account {private double ODLimit;
private double balance;private double amount = 30000;public ChequingAccount() { super();
balance = 0;
ODLimit = 0;}public ChequingAccount(double balance, double ODLimit) {
super(balance, ODLimit);
this.ODLimit = 5000;
this.balance = 20000; }
/**return balance*/
public double getODLimit() {
return ODLimit; }
/**set new balance*/
public void setODLimit(double ODLimit) {
this.ODLimit = ODLimit; }
/** Valid withdraw amounts must be less than the account balance + the limit */ public void withdraw(double amount) {
if (amount <= (balance + ODLimit))
balance = balance - amount;
else
System.out.println("You withdrew too much and exceed the overdraft limit"); }}
[[code]]
Merci
Réponses
|