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
Write a program in Java that reads in a set of positive integers and outputs how...
Write a program in Java that reads in a set of positive integers and outputs how many times a particular number appears in the list. You may assume that the data set has at most 100 numbers and -999 marks the end of the input data. The numbers must be output in increasing order. For example, for the data 15 40 28 62 95 15 28 13 62 65 48 95 65 62 65 95 95 -999 The output is...
Im working with visual basics for these problem. 1) Write a program that accepts five integers,...
Im working with visual basics for these problem. 1) Write a program that accepts five integers, and for each integer following the first, prints "GREATER" or "LESS" depending on whether or not the current integer is greater than the previous one. At the end, your application will let user know the largest and the smallest of the five numbers provided (BONUS): consider using the concepts of swapping the current and previous values as needed and don't use 5 variables.
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...
Write a Java program that reads two integers on the keyboard and displays them on the...
Write a Java program that reads two integers on the keyboard and displays them on the screen.
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 two versions of a program that reads from the user a sequence of positive integers...
Write two versions of a program that reads from the user a sequence of positive integers ending with -1, and another positive integer num that the user wishes to search for. The program should then print all the line numbers in sequence entered by the user, that contain num, or a message saying that num does not show at all in the sequence. Your program should interact with the user exactly as it shows in the following example: Please enter...
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.
6. Write a Java program to rotate an array (length 3) of integers in left direction...
6. Write a Java program to rotate an array (length 3) of integers in left direction 7. Write a Java program to store a collection of integers, sort them in ascending order and print the sorted integers.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT