Question

In: Computer Science

java Problem 3: An Interesting Problem Write a program that accepts two positive integers: a deposited...

java Problem 3: An Interesting Problem
Write a program that accepts two positive integers: a deposited amount of money and an
interest rate, as an annual percentage rate. Your program will calculate the number of years that
will take for the account balance to reach $1, 000,000. You can assume that the initial deposit is
less than $1,000,000
Input
The input will begin with a single line containing T , the number of test cases to follow. The
remaining lines contain the lines to be calculated. Each of these lines has two positive integers
separated by a single space. The first value is the deposited amount, the second is the interest
rate.
Output
The output should consist of the number of years.
Sample Input Sample output
2 cases
10000 10 49 Years
500 5 156 years

Solutions

Expert Solution

CODE IN JAVA:

Interest.java file:

import java.util.Scanner;
public class Interest {

   public static void main(String[] args) {
       // declaring variables
       double initialAmount,interestRate,interest;
       int n;
       //taking inputs
       Scanner sc = new Scanner(System.in);
       System.out.print("Enter the number of test cases:");
       n = sc.nextInt();
       for(int i=1;i<=n;i++) {
           System.out.print("Enter the initial amount and interest rate:");
           initialAmount = sc.nextDouble();
           interestRate = sc.nextDouble();
           int count = 0;
           //calculating the number of years needed
           while(initialAmount < 1000000) {
               interest = (initialAmount * interestRate)/100;
               initialAmount+=interest;
               count += 1 ;
           }
           //displaying the result
           System.out.println("Total years needed:"+count);
       }
   }

}

OUTPUT:


Related Solutions

Write a complete Java program to solve the following problem. Read two positive integers from the...
Write a complete Java program to solve the following problem. Read two positive integers from the user and print all the multiple of five in between them. You can assume the second number is bigger than the first. For example if the first number is 1 and the second number is 10, then your program should output 5 10 Java must be grade 11 work easy to understand and not complicated code
Java Program Problem // Description: Read five positive integers and average them. // Enter a negative...
Java Program Problem // Description: Read five positive integers and average them. // Enter a negative integer to end the program. import java.util.Scanner; public class Lab5 { public static void main (String args[]) {        Scanner sc;        sc = new Scanner(System.in);    final int MAX_NUMS = 5;        int num;       // variable to store the number        int sum;   // variable to store the sum        int count;    // variable to store...
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...
Design, code, and test a program that accepts positive integers until the value 204 is entered....
Design, code, and test a program that accepts positive integers until the value 204 is entered. After input terminates, the program should report the total number of even integers (excluding the special number 204) , the average value of the even integers, the total number of odd integers, and the average value of the odd integers. The program should also report "Evens won!", "Odds won!", or "Evens and odds tied!" based on which total was greater. Test your program thoroughly...
Write a complete MiniMIPS program that accepts a seqeunce of integers at input and after the...
Write a complete MiniMIPS program that accepts a seqeunce of integers at input and after the receipt of each new input value, displays the largest and smallest integers thus far. An input of 0 indicates the end of input values and is not an input value itself. Note that you do not need to keep all integers in memory.
Write a Java program that reads a list of integers into an array. The program should...
Write a Java program that reads a list of integers into an array. The program should read this array from the file “input.txt”. You may assume that there are fewer than 50 entries in the array. Your program determines how many entries there are. The output is a two-column list. The first column is the list of the distinct array elements; the second column is the number of occurrences of each element. The list should be sorted on entries in...
JAVA PROGRAM Write program that will prompt user generate two random integers with values from 1...
JAVA PROGRAM Write program that will prompt user generate two random integers with values from 1 to 10 then subtract the second integer from the first integer. Note, if the second integer is greater than the first integer, swap the two integers before making the subtraction.Then prompt user for the answer after the subtraction. If the answer is correct, display “Correct”otherwise display “Wrong”.You will need to do this in a loop FIVE times and keep a count of how many...
Using Java, write a program that takes in two integers from the keyboard called m and...
Using Java, write a program that takes in two integers from the keyboard called m and n, where m > n. Your program should print the first m natural numbers (m..1) downwards in n rows.
Write a java program that lets the user to enter any two integers and weave them...
Write a java program that lets the user to enter any two integers and weave them digit by digit and print the result of weaving their digits together to form a single number. Two numbers x and y are weaved together as follows. The last pair of digits in the result should be the last digit of x followed by the last digit of y. The second-to-the-last pair of digits in the result should be the second-to- the-last digit of...
Java Recursion (Timelimit: 3 seconds) Problem Description Write a Java program to solve the following problem....
Java Recursion (Timelimit: 3 seconds) Problem Description Write a Java program to solve the following problem. Recursion may appear in various contexts and in different forms. For fast implementation, we should always aim at transforming recursions into a simpler form of computation. In this assignment, the task is to evaluate X(·), which is defined as follows:               |0,if m = 0 or n = 0               | X(m,n−1),if n is odd and m is even X(m,n) = | X(m−1,n),if m...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT