Inheritance. Static variables and methods. Static and dynamic polymorp

Page 1 of 1

0 Replies - 2606 Views - Last Post: 08 December 2009 - 05:28 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=144194&amp;s=8c97802888f83cbaa291c0ca2e5df8f5&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

#1 AlinaM

Reputation: 0
• Posts: 1
• Joined: 06-October 09

Inheritance. Static variables and methods. Static and dynamic polymorp

Posted 08 December 2009 - 05:28 AM

Hi ,
Here is my problem description :
A bank offers loans to all the persons who want to buy apartments or household use products.
A loan is
identified by a unique number, data of the debtor (first and last names and address), and other data
about the loan like the debt sum (which is equal with the artifact’s cost), the installment and the
payment frequency.
By default, the payment installment is equal with 10% from the cost of the artifact (apartment or
household use product) and the payment has to be done monthly. But the debtor may choose another
frequency function of loan type
. If the debtor wants to buy an apartment, he/she may choose a
quarterly payment, but the bank would add to installment a 3% commission from the installment
amount. If the debtor wants to buy a householder use product, he/she may choose a half-yearly
payment
, but in this case, the bank will add a 7% commission to installment.
The program should every time display the money amount that the debtor has to pay. In the beginning,
this amount is equal with the loan and is updated every time when the debtor pays an installment
(meaning, when the method payInstalment() is called).

Could you please help me understand how should I define the methods payInstalment() in the superclass Loan and method computeInstalment() in the subclasses ApartmentLoan and HouseHoldProductLoan ?
Here is what I did so far:

```	   public abstract class Loan {
private int id;
private int number;
private String firstName;
private String lastName;
private double sum;
private double instalment;
private double unpaidSum;
private String frequency;
public Loan(){}
public Loan(String firstName,String lastName,String address,double sum){
this.firstName=firstName;
this.lastName=lastName;
this.sum=sum;
}
public Loan(String firstName,String lastName,String address,double sum,String frequency){
this.frequency=frequency;

}
public double getInstalment(){
return 10/100*sum;
}
public abstract double computeInstalment();
public double payInstalment(){
return	(sum * (instalment/12) * (1+instalment/12) * (12*30)/
((1+instalment/12)*12*30-1));

}
public double getUnpaidSum(){
return sum-payInstalment();
}
public double getSum(){
return sum;
}
@Override
public String toString(){
return " First name "+firstName+" Last name "+lastName+" Address "+address+" Loan "+sum+ " Frequency " +frequency;

}

}

```

```	public class HouseholdProductLoan extends Loan{
public HouseholdProductLoan(String firstName,String lastName,String address,double sum,String frequency){
}

public double computeInstalment(){
return getInstalment()+7/100*getInstalment();
}

}

```

```	public class ApartmentLoan extends Loan{
public ApartmentLoan(){}
public ApartmentLoan(String firstName,String lastName,String address,double sum){
}

public double computeInstalment(){
return getInstalment()+3/100*getInstalment();
}
}

```

Thank you very much for you time and help.

Attached File(s)

Is This A Good Question/Topic? 0

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }