polymorphisim java [closed]

Your method is not too long. Here it is:

public  double computeFine( int loanPeriod){
  double loanPeriodFine= 0.0;
  if (loanPeriod <= maximumLoanPeriod)
  {
   loanPeriodFine= 0.0;
  }else if (loanPeriod > maximumLoanPeriod){
   if (getSubject()=="cs")
   {
    loanPeriodFine= loanPeriod-maximumLoanPeriod*10.0;
   }else{
    loanPeriodFine =  loanPeriod-maximumLoanPeriod*5.0;
   }
  }

You can get 0 here if

  1. loanPeriod <= maximumLoanPeriod
  2. maximumLoanPeriod is 0

As I can see from your code the loadPeriod passed to this method is always 7 while the maximalLoanPeriod for most items is greater. So in almost all cases fine should be 0. The only exception is book “Java Programming 3v”.

Leave a Comment