Help with java coding In my assignment we used these skills

/////Help with java coding///////////

In my assignment we used these skills covered in the chapter:

*Composition and Aggregation

*Inheritance

*Constructors in a Subclass Method Overriding

*Final Access Modifier

////////////////////////////////////////////////////////////////////

Write a program that tracks an investments for 2 person based on the input of an interest rate. The initial balance should be $2,000, and $4,000. The interest should be added to the balance and output in table format as shown in the supplied sample.

/////////////////////////////////////////////////////////////////////////////

LiFiUnit4Ch13.java o Instantiate an investor1 object using a two parameter constructor passing the account number 1001 and the initial balance of $2,000 o Instantiate an investor2 object using a two parameter constructor passing the account number 2001 and the initial balance of $4,000 o Get input for interest rate (in the format .08 for 8%) 45% Use class variable to set interest rate o Output header as per sample showing interest rate o Print the table using a for loop displaying the current month and calling: addInterest() to add the monthly interest for each iteration getBalance() to display the current balance (See sample) Output results for 15 months. o Print the interest earned as shown in the sample for each investor utilizing a printf statement. Don’t hard code the interest earned, or interest rate

////////////////////////////////////////////////////

LiFiUnit4Ch13Investor.java o All variables should be declared private. o Declare a class variable called interestRate (This will hold the annual interest rate) o Declare a constant called ACCOUNT_NUMBER o Declare an instance variable called balance o Provide a class method that will be used to set the annual interest rate o Provide a two parameter constructor to initialize the constant account number and balance o Provide an addInterest() method to update the balance based on the interestRate entered in the driver. Add the interest using (balance * interestRate / 12)

//////////////////////////////////////////////////////////////

Sample Output

///////////////////////////////////////////////////////////////////////////////////////

I have a code that I am working with but theres errors that leave me puzzled. Most of my errors seem to be \'int cannot be defered\' and i am not sure if I am using the \'extend\' right or need to at all.

//////////////////////////////////////////////////////////////////////////////////////

import java.util.*;

public class HJUnit4Ch13
{
   public static void main(String [] args)
   {
       Scanner scan = new Scanner(System.in);
       double rate; // rate
       int investor1 = 1001, investor2 = 2001; // investor 1 and 2
       double balance1 = 2000, balance2 = 4000; // balances for investor1 and 2
      
      
       HJUnit4Ch13Investor investor1 = new HJUnit4Ch13Investor(account1, account1Balance); //objects
       HJUnit4Ch13Investor investor2 = new HJUnit4Ch13Investor(account2, account2Balance);
      
       System.out.print(\"Please enter the APR in the form of .05 for 5%: \"); //APR input
       rate = scan.nextLine();
      
       HJUnit4Ch13Investor.setRateInterest(rate); // interest rates
      
       System.out.print(\"Month balances for one year with\" + rate + \"annual interest: \"); // display rate of interest
       System.out.printf(\"\ \ %-10s%-10s%-10s%-10s%-10s \ \", \"Month\", \"Account #\", \"Balance\", \"Account #\", \"Balance\"); //header
       System.out.printf(\"\ \ %-10s%-10s%-10s%-10s%-10s \ \", \"-----\", \"---------\", \"-------\", \"---------\", \"-------\");
       for (int month = 1; month <= 15; month++) // loop to display results for 15 months
       {
           investor1.addInterest(); //adding interest to both investors
           investor2.addInterest();
           System.out.printf(\"\ %-10d%-10d$%-10.2f%-10d$%-10.2f\", month, account1,investor1.getBalance(),account2, investor2.getBalance()); // output for 15 months
       }// end
       System.out.printf(\"\ \ Investor1 earned : %.2f interest in 15 months at %.2f%%\ \",(investor1.getBalance() - account1Balance),(rate*100)); // output results
       System.out.printf(\"\ \ Investor2 earned : %.2f interest in 15 months at %.2f%%\ \",(investor2.getBalance() - account2Balance),(rate*100));
   }
}// end public

/////////////////////////////////////////////////////////////////////////////////////////////


public class HJUnit4Ch13Investor extends HJUnit4Ch13
{
   private static double interestRate; // interest rate
   private final int ACCOUNT_NUMBER; // constant
   private double balance; // balance
  
   public HJUnit4Ch13Investor(int accNum, double initialBal) //constructor
   {
       ACCOUNT_NUMBER = accNum;
       balance = initialBal;
   } // end
  
   public static void setRateInterest(double intRate) // interest rate
   {
       interestRate = intRate;
   } // end
  
   public void addInterest() // update balance based on interest
   {
       balance += (balance * interestRate / 12);
   } // end
  
   public double getBalance() // get balance
   {
       return balance;
   } // end
} // end

////////////////////////////////////////////////////////////////////////

It\'s two files. comments are appreciated but not necessary on where I went wrong with my coding. Thank You.

alance Hccoun 1001 2013.33 2001 4026.67 2001 4853.51 1001 2040.27 2001 4080.53 2001 4107.74 1001 2067.56 2001 4135.12 1001 2081.35 2001 4162.69 1001 2095.22 2001 4190.44 1001 2109.19 2001 4218.38 1001 2123.25 2001 4246.50 10 1001 2137.41 2001 4274.81 11 1001 2151.65 2001 4303.31 12 1001 2166.00 2001 4332.00 13 1001 2180.44 2001 4360.88 14 1001 2194.98 2001 4389.95 15 1001 2209 .61 2001 4419-22 00 00 88 8e et tt aa ss hh 5a tt e-713429480110852 nn rn c-655716435830892 00 on n nn fa a-630752086432099 i-2580369-470368-55 111122233334 11 444444444444 oh #-111111111111111 tt t t-000000000000000 ss - n-000000000000000 ee rw u-222222222222222 rr ee tt ee A hy e-367765295150481 12 c-372853212460496 62 \'10 a-3603715937-6049 99 I-124568902356890 0 Rr a-000000011111112 2 4 Po B-222222222222222 Af es dd he #-111111111111111 ee tc 000000000000000 n n n t-000000000000000 ra n-111111111111111 e1 u ee ta o! nb c 12 00 tt at t! en n vv 10 0 nn

Solution

your logic is clear but you have made few mistakes that are following

I am highlighting the letter where you made mistakes

int investor1 = 1001, investor2 = 2001; // investor 1 and 2

[ it should be account1 and account2]
double balance1 = 2000, balance2 = 4000; // balances for investor1 and 2

[it should be account1Balance , account2Balance]
  
  
HJUnit4Ch13Investor investor1 = new HJUnit4Ch13Investor(account1, account1Balance); //objects
HJUnit4Ch13Investor investor2 = new HJUnit4Ch13Investor(account2, account2Balance);
  
System.out.print(\"Please enter the APR in the form of .05 for 5%: \"); //APR input


rate = scan.nextLine();

here you have defined rate as double variable and your are assigning String to a double variable

scan.nextLine() will give you following error

Type mismatch : can not convert from String to Double

you should write following

scan.nextDouble()

============== CORRRECT CODE===================

// CHANGES I MADE ARE HIGHLIGHTED
import java.util.*;
public class HJUnit4Ch13 {


public static void main(String [] args)
{
Scanner scan = new Scanner(System.in);
double rate; // rate
int account1 = 1001, account2 = 2001; // investor 1 and 2
double account1Balance = 2000, account2Balance = 4000; // balances for investor1 and 2
  

  
HJUnit4Ch13Investor investor1 = new HJUnit4Ch13Investor(account1, account1Balance); //objects
HJUnit4Ch13Investor investor2 = new HJUnit4Ch13Investor(account2, account2Balance);
  
System.out.print(\"Please enter the APR in the form of .05 for 5%: \"); //APR input
rate = scan.nextDouble();
  
HJUnit4Ch13Investor.setRateInterest(rate); // interest rates
  
System.out.print(\"Month balances for one year with\" + rate + \"annual interest: \"); // display rate of interest
System.out.printf(\"\ \ %-10s%-10s%-10s%-10s%-10s \ \", \"Month\", \"Account #\", \"Balance\", \"Account #\", \"Balance\"); //header
System.out.printf(\"\ \ %-10s%-10s%-10s%-10s%-10s \ \", \"-----\", \"---------\", \"-------\", \"---------\", \"-------\");
for (int month = 1; month <= 15; month++) // loop to display results for 15 months
{
investor1.addInterest(); //adding interest to both investors
investor2.addInterest();
System.out.printf(\"\ %-10d%-10d$%-10.2f%-10d$%-10.2f\", month, account1,investor1.getBalance(),account2, investor2.getBalance()); // output for 15 months
}// end
System.out.printf(\"\ \ Investor1 earned : %.2f interest in 15 months at %.2f%%\ \",(investor1.getBalance() - account1Balance),(rate*100)); // output results
System.out.printf(\"\ \ Investor2 earned : %.2f interest in 15 months at %.2f%%\ \",(investor2.getBalance() - account2Balance),(rate*100));
}
}// end public
/////////////////////////////////////////////////////////////////////////////////////////////

class HJUnit4Ch13Investor extends HJUnit4Ch13
{
private static double interestRate; // interest rate
private final int ACCOUNT_NUMBER; // constant
private double balance; // balance

public HJUnit4Ch13Investor(int accNum, double initialBal) //constructor
{
ACCOUNT_NUMBER = accNum;
balance = initialBal;
} // end

public static void setRateInterest(double intRate) // interest rate
{
interestRate = intRate;
} // end

public void addInterest() // update balance based on interest
{
balance += (balance * interestRate / 12);
} // end

public double getBalance() // get balance
{
return balance;
} // end
} // end
////////////////////////////////////////////////////////////////////////

/////Help with java coding/////////// In my assignment we used these skills covered in the chapter: *Composition and Aggregation *Inheritance *Constructors in a
/////Help with java coding/////////// In my assignment we used these skills covered in the chapter: *Composition and Aggregation *Inheritance *Constructors in a
/////Help with java coding/////////// In my assignment we used these skills covered in the chapter: *Composition and Aggregation *Inheritance *Constructors in a
/////Help with java coding/////////// In my assignment we used these skills covered in the chapter: *Composition and Aggregation *Inheritance *Constructors in a

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site