Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Within the project, create an Investment class with the following data fields: o

ID: 3588049 • Letter: W

Question

Within the project, create an Investment class with the following data fields:
o initial investment (dollars and cents)
o annual interest rate (percent, e.g. 3.5)
o term (amount of time money will be invested) in whole years
o compounding type (char ‘A’, ‘Q’, ‘M’, or ‘D’)
o balance (dollars and cents)
o earnings (dollars and cents)

Within the Investment class:
Add a constructor with 4 parameters to instantiate an Investment type object and initialize all of the data fields.
o Set the first 4 data fields directly, using the passed in parameter values.
o Set the balance data field to the same value as the initial investment.
o Set the earnings data field to 0.

Add a getter for the earnings data field that returns the earnings value.
Add a convertCompoundingTypeToString instance method. The method will:
o Return a String equivalent for the compounding type character data field (i.e. “Annual”, “Quarterly”, “Monthly”, or “Daily”).

Add an instance method to calculate the investment results for an Investment object.
o Create a new variable to hold the converted annual interest rate -- a rate that can be used in math formulas (e.g. 3.5% would convert to 0.035).
o Decide which compounding rate to use by examining the compounding rate data field, and set up any necessary variables accordingly.
o Use a for loop to compute the end balance. (NOTE: You must use a loop, NOT banking interest formulas).
Interest earned must be calculated and added to the balance for each compounding period.
Calculate annual interest on the current balance using the annual interest rate. Add interest to the balance every year.
Calculate quarterly interest on the current balance using a quarterly interest rate (1/4th of the annual interest rate). Add interest to the balance every quarter for 4 quarters per year.
Calculate monthly interest on the current balance using a monthly interest rate (1/12th of the annual interest rate). Add interest to the balance every month for 12 months per year.

Calculate daily interest on the current balance using a daily interest rate (1/365th of the annual interest rate). Add interest to the balance every day for 365 days per year.

After calculating the end balance, store the correct value into the earnings data field. The earnings for an investment are the difference between the end balance and the initial investment.

Add an instance method to display the investment results for an Investment object
o Display a blank line before the results.
o Display a descriptive word (Annual, Quarterly, Monthly or Daily) in the description on the top line. HINT: Use your convert method.
o Display dollar figures to 2 decimal places, and interest rates to 3 decimal places.
o Dollar signs and decimal points of the dollar values should line up.

Compounding of an initial investment of 1000.00 yearly for 3 years at 4% annual interest. Calculate 4% of the current balance at the end of each year: End of year 1 : 1000.00 + 40.00 = 1040.00 End of year 2: 1040.0041.60- 1081.60 End of year 3: 1081.60 43.26 1124.86 Total earnings = 124.86 f an initial investment of I

Explanation / Answer

This is InvestmentComparision class

package chegg;

import java.util.Scanner;

public class InvestmentComparision {

   static double in_inv,rate;
   static int term;
   static char t;
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       System.out.println("Enter the Initial investment");
       in_inv = sc.nextDouble();
       System.out.println("Enter the rate of internet");
       rate = sc.nextDouble();
       System.out.println("Enter the time in years");
       term = sc.nextInt();
       System.out.println("Enter A for Annual, Q for Quaterly, M for Monthly and D for Daily interest calculation");
       t = sc.next().charAt(0);
      
       Investment i = new Investment(in_inv,rate,term,t);
       i.investment_Cal();
       i.display_results();
   }

}

This is investment class

package chegg;

import java.text.DecimalFormat;

public class Investment {

   double initial_investment,annual_interest_rate,balance,earnings,r;
   int term;
   char type;
  
   public Investment(double in_inv,double rate,int trm,char typ) {
       initial_investment = in_inv;
       balance = initial_investment;
       earnings = 0;
       annual_interest_rate = rate;
       term = trm;
       type = typ;
   }

   public double getEarnings() {
       return earnings;
   }
  
   public double getInitial_investment() {
       return initial_investment;
   }
  
   public String convertCompoundingTypeToString()
   {
       String s = null;
       if(type=='A')
       {
           s = "Annual";
           return s;
       }
       else if(type=='Q')
       {
           s = "Quaterly";
           return s;
       }
       else if(type=='M')
       {
           s = "Monthly";
           return s;
       }
       else if(type=='D')
       {
           s = "Daily";
           return s;
       }
       else
           return s;
   }
  
   public void investment_Cal()
   {
       if(type == 'A')
           r = annual_interest_rate/100;
       else if(type == 'Q')
           r = annual_interest_rate/400;
       else if(type == 'M')
           r = annual_interest_rate/1200;
       else
           r = annual_interest_rate/36500;
   }
  
   public void display_results()
   {
       DecimalFormat df = new DecimalFormat("#.00");
       if(type == 'A'){
           System.out.println("Compounding of an initial investment of $"+initial_investment+" yearly for "+term+" years at "+annual_interest_rate+"%   annual interest");
           System.out.println();
           System.out.println("Calculate "+annual_interest_rate+"% of the current balance at the end of each year");
           for(int i =1;i <= term;i++)
           {
               earnings = balance * r;
               earnings = Double.valueOf(df.format(earnings));
               System.out.println("End of year "+i+": $"+balance+" + $"+earnings+" = $"+(balance+earnings));
               balance = balance + earnings;
               balance = Double.valueOf(df.format(balance));
           }
           double tot = balance-initial_investment;
           tot = Double.valueOf(df.format(tot));
           System.out.println("Total earnings = $"+tot);
       }
       if(type == 'Q'){
           System.out.println("Compounding of an initial investment of "+initial_investment+" quarterly for "+term+" years at "+annual_interest_rate+"% annual interest");
           System.out.println();
           System.out.println("Calculate 1/4th of "+annual_interest_rate+"% of the current balance (i.e. "+annual_interest_rate/4+"%) at the end of each quarter:");
           int j;
           for(int i =1;i <= term;i++)
           {
               for(j=1;j<5;j++){
               earnings = balance * r;
               earnings = Double.valueOf(df.format(earnings));
               System.out.println("End of quarter "+j+" in year "+i+": $"+balance+" + $"+earnings+" = $"+(balance+earnings));
               balance = balance + earnings;
               balance = Double.valueOf(df.format(balance));
               }
           }
           double tot = balance-initial_investment;
           tot = Double.valueOf(df.format(tot));
           System.out.println("Total earnings = $"+tot);
       }
       if(type == 'M'){
           System.out.println("Compounding of an initial investment of "+initial_investment+" monthly for "+term+" years at "+annual_interest_rate+"% annual interest");
           System.out.println();
           System.out.println("Calculate 1/12th of "+annual_interest_rate+"% of the current balance (i.e. "+annual_interest_rate/12+"%) at the end of each month:");
           int j;
           for(int i =1;i <= term;i++)
           {
               for(j=1;j<13;j++){
               earnings = balance * r;
               earnings = Double.valueOf(df.format(earnings));
               System.out.println("End of month "+j+" in year "+i+": $"+balance+" + $"+earnings+" = $"+(balance+earnings));
               balance = balance + earnings;
               balance = Double.valueOf(df.format(balance));
               }
           }
           double tot = balance-initial_investment;
           tot = Double.valueOf(df.format(tot));
           System.out.println("Total earnings = $"+tot);
       }
       if(type == 'D'){
           System.out.println("Compounding of an initial investment of $"+initial_investment+" daily for "+term+" years at "+annual_interest_rate+"% annual interest");
           System.out.println();
           System.out.println("Calculate 1/365th of "+annual_interest_rate+"% of the current balance (i.e. "+annual_interest_rate/365+"%) at the end of each day:");
           int j;
           for(int i =1;i <= term;i++)
           {
               for(j=1;j<366;j++){
               earnings = balance * r;
               earnings = Double.valueOf(df.format(earnings));
               System.out.println("End of month "+j+" in year "+i+": $"+balance+" + $"+earnings+" = $"+(balance+earnings));
               balance = balance + earnings;
               balance = Double.valueOf(df.format(balance));
               }
           }
           double tot = balance-initial_investment;
           tot = Double.valueOf(df.format(tot));
           System.out.println("Total earnings = $"+tot);
       }
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote