Reelement besoin d'aide

jolielady Messages postés 6 Date d'inscription dimanche 23 mars 2003 Statut Membre Dernière intervention 18 février 2004 - 17 févr. 2004 à 04:08
jolielady Messages postés 6 Date d'inscription dimanche 23 mars 2003 Statut Membre Dernière intervention 18 février 2004 - 18 févr. 2004 à 17:35
Je suis etudiante en webmestre et la je suis sur le cours de programmation java. J'ai ce travail a remettre et mon prof me dit qu'il me manque le polymorphisme. Je n'ai aucunes idees comment finir mon travail.

Voici mon 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");	}}



J'ai reelement besoin d'aide

Merci beaucoup
:blush)

Jolielady :kisses)

2 réponses

kirua12 Messages postés 1155 Date d'inscription samedi 17 janvier 2004 Statut Membre Dernière intervention 29 avril 2011 7
17 févr. 2004 à 11:38
Salut,

tu n'utilises pas la classe ChequingAccount. Je pense que c'est ça qu'il te manque. En fait tu doid créer un ChequingAccount et faire exactement la même chose qu'avec Account mais sans explicitement dire que c'est un ChecjingAccount (pas très clair hein ;))
Ex assez basique :
dans ta classe AccountRob:
tu crées ton account : Account account =new Account();
tu fais tes différentes actions.
Puis tu crées un ChequingAccount : account=new ChequingAccount();
Et tu refais exactement les mêmes actions.

Avec ça tu montres le polymorphisme : tu as une variable de type déclaré Account mais qui a un comportement différent à l'exécution car son type réel n'est pas forcément Account (ie. ChequingAccount)

En espérant que ça t'aide.
0
jolielady Messages postés 6 Date d'inscription dimanche 23 mars 2003 Statut Membre Dernière intervention 18 février 2004
18 févr. 2004 à 17:35
Merci je vais essayer de travailler ca...

Jolielady :kisses)
0
Rejoignez-nous