Use a while loop
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
//Class for compound interest
class ComputeInterest {
//variables
private int newBalance;
private double interestRate;
//Constructor
ComputeInterest(int newBalance, double interestRate){
this.newBalance = newBalance;
this.interestRate = interestRate;
}
//Getter and setter
public int getNewBalance() {
return newBalance;
}
public void setNewBalance(int newBalance) {
this.newBalance = newBalance;
}
public double getInterestRate() {
return interestRate;
}
public void setInterestRate(double interestRate) {
this.interestRate = interestRate;
}
//Find balance after n years
public double getBalance(int n){
double ans = newBalance;
while(n-->0){
ans = ans*(1+interestRate/100);
}
return ans;
}
public static void main(String[] args) {
ComputeInterest c = new ComputeInterest(100,5);
System.out.println("Balance after 5 years: "+c.getBalance(5));
}
}
Use a do while loop :
import java.util.HashMap; import java.util.Map; import java.util.Scanner; //Class for compound interest class ComputeInterest { //variables private int newBalance; private double interestRate; //Constructor ComputeInterest(int newBalance, double interestRate){ this.newBalance = newBalance; this.interestRate = interestRate; } //Getter and setter public int getNewBalance() { return newBalance; } public void setNewBalance(int newBalance) { this.newBalance = newBalance; } public double getInterestRate() { return interestRate; } public void setInterestRate(double interestRate) { this.interestRate = interestRate; } //Find balance after n years public double getBalance(int n){ double ans = newBalance; n--; do{ ans = ans*(1+interestRate/100); }while(n-->0); return ans; } public static void main(String[] args) { ComputeInterest c = new ComputeInterest(100,5); System.out.println("Balance after 5 years: "+c.getBalance(5)); } }
Using a for loop :
import java.util.HashMap; import java.util.Map; import java.util.Scanner; //Class for compound interest class ComputeInterest { //variables private int newBalance; private double interestRate; //Constructor ComputeInterest(int newBalance, double interestRate){ this.newBalance = newBalance; this.interestRate = interestRate; } //Getter and setter public int getNewBalance() { return newBalance; } public void setNewBalance(int newBalance) { this.newBalance = newBalance; } public double getInterestRate() { return interestRate; } public void setInterestRate(double interestRate) { this.interestRate = interestRate; } //Find balance after n years public double getBalance(int n){ double ans = newBalance; for(int i=0;i<n;i++){ ans = ans*(1+interestRate/100); } return ans; } public static void main(String[] args) { ComputeInterest c = new ComputeInterest(100,5); System.out.println("Balance after 5 years: "+c.getBalance(5)); } }
OUTPUT :
[8 MARKS] Question 3 Assume a bank account begins with a balance of R100 and earns...
Im having trouble with this C++ program. Lab 10/object/test files provided LAB 10 1 //Savings.cpp - displays the account balance at 2 //the end of 1 through 3 years 3 //Created/revised by <your name> on <current date> 4 5 #include <iostream> 6 #include <iomanip> 7 #include <cmath> 8 using namespace std; 9 10 //function prototype 11 double getBalance(int amount, double rate, int y); 12 13 int main() 14 { 15 int deposit = 0; 16 double interestRate = 0.0; 17...
QUESTION 3 [49 MARKS 3.1) Write the Java statements for a class called Calculator to produce the GUI below. Use 3 panels to arrange the components. You must use an array when defining the numbered buttons (o-9. Do not declare 10 buttons individually. The textfield must be initialized with the text as shown below, and be able to accommodate up to 25 characters. The spacing between the numbered buttons is 10. (28) for caloula Add Equals 3.2 Rewrite any existing...
Question 4 (8 pts): Suppose that you deposit $12,000 in a savings account that earns 7% in annually. Inflation is 2.5%. a) What is the real interest rate? (2 pts) 5) How much money is in your account at the end of the year? (In nominal amount) (3 pt - What is the real purchasing power of that amount? (In real amount) (3 pts)
JAVA Write a method called computeBalance( ) that computes the balance of a bank account with a given initial balance and interest rate, after a given number of years. Assume interest is compounded yearly. You can use the standard calculator here to check your results (note that you'll have to change the dropdown to compound the interest yearly): http://www.thecalculatorsite.com/finance/calculators/compoundinterestcalculator.php Use a loop to control the iterations through the years in your method. Your method should return a double value. In...
Project 9-2: Account Balance Calculator Create an application that calculates and displays the starting and ending monthly balances for a checking account and a savings account. --->Console Welcome to the Account application Starting Balances Checking: $1,000.00 Savings: $1,000.00 Enter the transactions for the month Withdrawal or deposit? (w/d): w Checking or savings? (c/s): c Amount?: 500 Continue? (y/n): y Withdrawal or deposit? (w/d): d Checking or savings? (c/s): s Amount?: 200 Continue? (y/n): n Monthly Payments and Fees Checking fee: $1.00 Savings...
3. Write Java methods to accomplish each of the following Write a method named simpleAry which accepts and return nothing. It creates an array that can hold ten integers. Fill up each slot of the array with the number 113. Then, display the contents of the array on the screen. You must use a loop to put the values in the array and also to display them. Write a method named sury which accepts an array of type double with...
*Step1: -Create UML of data type classes: reuse from lab3 for class Account, CheckingAccount and SavingAccount -Read the requirement of each part; write the pseudo-code in a word document by listing the step by step what you suppose to do in main() and then save it with the name as Lab4_pseudoCode_yourLastName *Step2: -start editor eClipse, create the project→project name: FA2019_LAB4PART1_yourLastName(part1) OR FA2019_LAB4PART2_yourLastName (part2) -add data type classes (You can use these classes from lab3) Account_yourLastName.java CheckingAccount_yourLastName.java SavingAccount_yourLastName.java -Add data structure...
Develop a VI that computes the balance of a bank account (compounded yearly) at a given interest rate with yearly monetary additions. Use the following base equation: X=P1+in Where X is end of year account balance, P is the initial account balance, i is the interest rate, and n is the number of years. NOTE: This equation does not account for additional yearly deposits! It is your job to figure out how to include that portion of the equation. User...
Question 8 0/9 pts Leona opens a savings account with an initial deposit of $150. She then deposits $150 into that savings account at the end of every subsequent month. This savings account pays an annual interest rate of 3.6% and is compounded monthly. How much does Leona have in her account at the end of each of the first 3 years? not ((1+5)* - 1 B(t)= P. (5) Round your answer to the nearest penny. Input the dollar sign...
Use Excel to answer this question 3 Part 1 (8 marks) 4 Suppose you receive $100 at the end of each year for the next three years. 5 6 a. (2 marks) 7 If the interest rate is 8% per annum (interest paid annually), what is the present value of these cash flows? 8 9 b. (2 marks) 10 What is the future value in three years of the present value you computed in part (a)? 11 12 c. (2...