Question

In: Computer Science

Problem 1: In java Create a program to calculate interest rate and total balance - the...

Problem 1:
In java

Create a program to calculate interest rate and total balance - the program consists of

(a) A class that encapsulates the interest rate and total balance calculation

  • Constructor should accept initial balance and interest rate
  • Methods:
    • Returns interest rate
    • Returns total balance
    • Set interest rate
    • Set initial balance

(b) A test program that uses class from step (A) to perform the following:

  • Set interest rate to 5% and initial balance to 1000
  • Print interest amount and total balance
  • Increase interest rate to 10%
  • Print interest amount and total balance
  • Increase initial balance to 2000
  • Print interest amount and total balance

Solutions

Expert Solution

(a)

//Account.java
public class Account
{
   //variables to store total balance and interest rate
   private double total_balance;
   private double interest_rate;
   /*Constructor to set total balance and interest rate value*/
   public Account(double initial_balance, double interest_rate)
   {
       this.total_balance=initial_balance;
       //convert interest_rate to decimal value
       this.interest_rate=interest_rate/100.0;
   }

   public void setInterest_rate(double interest_rate)
   {
       this.interest_rate = interest_rate/100.0;
   }
  
   public void setInitial_balance(double initial_balance)
   {
       this.total_balance = initial_balance;
   }
   /*Return interest value to integer value*/
   public double getInterest_rate()
   {
       return interest_rate*100.0;
   }
   public double getInterestAmount()
   {
       return total_balance*interest_rate;
   }
   /**The method getTotalBalance returns the total balance */
   public double getTotalBalance()
   {
       total_balance=total_balance+ getInterestAmount();
       return total_balance;
   }
} //end of the class Account

-------------------------------------------------------------------------------------------------------------------------------------

(b)

/* * The java program that creates an instance of Account class with initial balance and interest rate.

Then print the rate of interest, interest amount and total balance .* */


//TestProgram.java
public class TestProgram
{
   public static void main(String[] args)
   {
       //Set interest rate to 5% and initial balance to 1000
       Account account= new Account(1000, 5);
      
       System.out.printf("Interest rate : %.2f %%\n",account.getInterest_rate());
       //Print interest amount and total balance
       System.out.printf("Interest amount : %.2f Total Balance: %.2f\n",
               account.getInterestAmount(),account.getTotalBalance());
      
       //Increase interest rate to 10%
       account.setInterest_rate(10);
       System.out.printf("Interest rate : %.2f %%\n",account.getInterest_rate());
       //Print interest amount and total balance
       System.out.printf("Interest amount : %.2f Total Balance: %.2f\n",
               account.getInterestAmount(),account.getTotalBalance());
      
      
       //Increase initial balance to 2000
       account.setInitial_balance(2000);
       System.out.printf("Interest rate : %.2f %%\n",account.getInterest_rate());
       //Print interest amount and total balance
       System.out.printf("Interest amount : %.2f Total Balance: %.2f\n",
               account.getInterestAmount(),account.getTotalBalance());
   }//end of main method
} //end of the class

------------------------------------------------------------------------------------------------------------

Sample Output:

Interest rate: 5.00 %
Interest amount: 50.00 Total Balance: 1050.00
Interest rate: 10.00 %
Interest amount: 105.00 Total Balance: 1155.00
Interest rate: 10.00 %
Interest amount: 200.00 Total Balance: 2200.00


Related Solutions

In java Create a program to calculate interest rate and total balance - the program consists...
In java Create a program to calculate interest rate and total balance - the program consists of (a) A class that encapsulates the interest rate and total balance calculation Constructor should accept initial balance and interest rate Methods: Returns interest rate Returns total balance Set interest rate Set initial balance (b) A test program that uses class from step (A) to perform the following: Set interest rate to 5% and initial balance to 1000 Print interest amount and total balance...
Calculate Interest in a Java program. If you know the balance and the annual percentage interest...
Calculate Interest in a Java program. If you know the balance and the annual percentage interest rate, you can compute the interest on the next monthly payment using the following formula: interest = balance * (annualInterestRate/1200) Write a program that reads the balance and the annual percentage interest rate and displays the interest for the next month. Create a scanner Prompt the user to enter a name and create variable for scanner Prompt the user to enter a balance and...
Java program problem 1 Come up with an idea for parallel arrays Create the arrays to...
Java program problem 1 Come up with an idea for parallel arrays Create the arrays to hold 5 items in each In the main(), load the arrays with data Then output the entire contents of the arrays Create a method called find1() and pass the 2 arrays to that method. problem 2 In the find1() method, ask the user to enter a value to search for Write logic to search the first array and then output the related data from...
In java Write a program called FileProcessor.java that reads the file numbers.txt, and: Calculate the total...
In java Write a program called FileProcessor.java that reads the file numbers.txt, and: Calculate the total number of numbers in the file, Calculate the sum of all the numbers in the file, Calculate the average of all the numbers in the file, Find the smallest value of all the numbers in the file, Find the largest value of all the numbers in the file, Calculate the standard deviation of all the numbers in the file
(JAVA PLS)You will create a program that will follow the queuing theory of the Barbershop Problem....
(JAVA PLS)You will create a program that will follow the queuing theory of the Barbershop Problem. In this you will use ques and random number generator to complete this project. You will create three queues Couch - the area where patron will wait just prior to getting their hair cut; Line - the area where patron will form a line just before reaching the couch; and Cashier - the area where patrons will line up to pay just before exiting...
Create a Java Program to calculate luggage costs. USING ECLIPSE IDE The Business Rules are: A....
Create a Java Program to calculate luggage costs. USING ECLIPSE IDE The Business Rules are: A. Two bags per person are free. B. The Excess Bag Charge is $75 per bag. The program needs to do the following: 1. In your main method(),    Create integers to store the number of Passengers and also the total number of bags    Prompt for the number of passengers on a ticket.    Prompt for the total number of bags for all passengers...
Create a Java Program to show a savings account balance. using eclipse IDE This can be...
Create a Java Program to show a savings account balance. using eclipse IDE This can be done in the main() method. Create an int variable named currentBalance and assign it the value of 0. Create an int variable named amountToSaveEachMonth. Prompt "Enter amount to save each month:" and assign the result to the int variable in step 2. Create an int variable name numberOfMonthsToSave. Prompt "Enter the number of months to save:" and store the input value into the variable...
A Java program that solves a real-world problem The remaining amount (balance) for a prepaid cellular...
A Java program that solves a real-world problem The remaining amount (balance) for a prepaid cellular phone, is computed by subtracting the cost of the phone usage from the original phone load. The phone usage is based only on the total cost of text messages and phone calls. The cost of text messages is determined from the number of text messages sent and the cost of phone calls is determined from the number of minutes of calls made. ● Based...
Problem 1. Calculate the nominal rate of interest given the following (you must show the formula):...
Problem 1. Calculate the nominal rate of interest given the following (you must show the formula): The real rate of interest = 2% Expected Inflation = 4% The Risk Free rate = 6% All risk factors = 3%
CREATE A NEW Java PROGRAM that demonstrates : 1.1 numeric and 1 string exception 2. Create...
CREATE A NEW Java PROGRAM that demonstrates : 1.1 numeric and 1 string exception 2. Create your own user defined exception, COMMENT it well, and add code so that it is thrown.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT