20 January 2011

calculate investment java OOP example basic

//STARTING OF CODING
//CLASS FIXED INVESTMENT


public class FixedInvestment
{
  //PRIVATE DATA VALUE
  private double depositAmount=1000;//STORE DEFAULT DEPOSIT AMOUNT DATA
  private double annualInterestRate=0.05;//STORE DEFAULT INTEREST RATE DATA
  private int numberOfYears=1;//STORE DEFAULT YEAR DATA

  public FixedInvestment()//CONSTRUCTOR WITHOUT PERIMETER
  {
    //DEFAULT CONSTRUCTOR
    //EMPTY IT
  }
  //CONSTRUCTOR WITH PERIMETER,TO SET THE FIXED INVESTMENT
  //PUBLIC DATA VALUE
  public FixedInvestment(double depositAmount,double annualInterestRate,int numberOfYears)
  {
    //USED "THIS" REFERENCE TO MAKE SURE THE INSTANCE VARIABLE POINT TO THE CORRECT OBJECT
    this.depositAmount=depositAmount;
    this.annualInterestRate=annualInterestRate;
    this.numberOfYears=numberOfYears;
  }
  //METHOD TO RETURN THE DEPOSIT AMOUNT
  //POSTCONDITION:THE VALUE OF DEPOSIT AMOUNT IS RETURNED
  public double getdepositAmount()
  {
    return depositAmount;
  }
  //METHOD TO RETURN THE ANNUAL INTEREST RATE
  //POSTCONDITION:THE VALUE OF ANNUAL INTEREST IS RETURNED
  public double getannualInterestRate()
  {
    return annualInterestRate;
  }
  //METHOD TO RETURN THE NUMBER OF YEARS
  //POSTCONDITION:THE NUMBER OF YEARS IS RETURNED
  public int getnumberOfYears()
  {
    return numberOfYears;
  }
  //METHOD TO RETURN THE TOTAL RETURN
  //POSTCONDITION:THE VALUE OF TOTAL RETURN IS RETURNED
  public double getTotalReturn()
  {
    //THE FORMULA OF TOTAL RETURN
    return depositAmount*(1+annualInterestRate)*(numberOfYears*12);
  }
  //MAIN OF THE PROGRAM
  public static void main(String[]args)
  {
  
    FixedInvestment NewFixedInvestment=new FixedInvestment(10000,0.045,3);//THE DATA DEPOSIT AMOUNT,ANNUAL INTEREST RATE AND YEARS NEEDED
    FixedInvestment NewFixedInvestment2=new FixedInvestment();
    System.out.println("total return= " + NewFixedInvestment.getTotalReturn());//PRINT THE TOTAL RETURN VALUE
    //END MAIN
  }
}
//END OF PROGRAMMING~
//ALHAMDULILLAH,DA SIAP!
//THANK YOU MA'AM FOR THE LESSON

//THANKS TO MR BEAR a.k.a RAHMAT(KEUNIKAN HIDUP)

2 comments:

  1. ny code programmming utk JAVA, run program ny n anda akan lihat hasilnyer,, comp student maybe tau ar nyh

    ReplyDelete

Related Posts Plugin for WordPress, Blogger...