0 Replies - 2447 Views - Last Post: 08 December 2009 - 05:28 AM Rate Topic: -----

#1 AlinaM  Icon User is offline

  • New D.I.C Head

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

Inheritance. Static variables and methods. Static and dynamic polymorp

Post icon  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 String address;
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.address=address;
  this.sum=sum;
  }
public Loan(String firstName,String lastName,String address,double sum,String frequency){
	this(firstName,lastName,address,sum);
	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){
	 super( firstName, lastName, address, sum,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){
	 super( firstName, lastName, address, 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