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...
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...
(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...
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...
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.
In java. Prefer Bluej Create a program in java that calculates area and perimeter of a...
In java. Prefer Bluej Create a program in java that calculates area and perimeter of a square - use a class and test program to calculate the area and perimeter; assume length of square is 7 ft.
Needs to be in JAVA. Write a Java program that accepts the total amount of cars...
Needs to be in JAVA. Write a Java program that accepts the total amount of cars sold and total sales amount of a car salesperson for a given month. The salesperson’s paycheck is computed as follows: a. Every sales person gets 10% (commission) of total sales b. Sales totals greater than $50,000 get 5% of total sales amount c. 8 or more cars sold earns the salesperson an extra 3% Please remove 30% (taxes) of the gross pay and list...
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 program in java with the following information: Design a program that uses an array...
Create a program in java with the following information: Design a program that uses an array with specified values to display the following: The lowest number in the array The highest number in the array The total of the numbers in the array The average of the numbers in the array Initialize an array with these specific 20 numbers: 26 45 56 12 78 74 39 22 5 90 87 32 28 11 93 62 79 53 22 51 example...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT