Question

In: Computer Science

Write a program that prints and calls two methods. 1. Compute and return the future value...

Write a program that prints and calls two methods.

1. Compute and return the future value of an account based on the present value of the account, the interest rate, and the number of years.

future value = p * (1 + r   / 100) y

Your method should have the following characteristics:

• It should have three double parameters:

  • present value

• interest rate

• number of years

• It should return a double, the future value.

• It should use Math.pow in the calculation.

• It should not have any print statements. The main method should do all the printing.

2. Compute and return the future value of an annuity based on the payment per year, the interest rate, and the number of years.

For each method, the main method needs to obtain input from the user, call the method with the input values, save the result of the method in a local variable, and print the inputs and the result.

future value = p *( (1 + r/100)eY - 1) / r/100

Your method should have the following characteristics:

• It should have three double parameters:

• yearly payment

• interest rate

• number of years

• It should return a double, the future value.

• It should use Math.pow in the calculation.

• It should not have any print statements. The main method should do all the printing.

[ USE JAVA TO WORK ON THIS PROBLEM PLEASE]

_____________________________________________________________________________________________________________________________________________________

# This is my work so far:

import java.util.*;

public class Lab3 {

public static void main(String[] args) {
System.out.println("Lab 3 written by Tesfalem Tekie.");
Scanner input = new Scanner(System.in);
  
System.out.print(" ");// will work on the prompt
double Value = input.nextdouble();
double Rate = input.nextdouble();
double Years = input.nextdouble();
  
double futureValue = account(Value, Rate, Years);
System.out.println(" ");// keep working
double AnnFutureValue = annuity(Value, Rate, Years);
System.out.println(" ");// keep working
}//end main method

public static double account(double preValue, double intRate, double numOfYears ) {
double result = Math.sqrt(p*(1 + r/100)eY);// keep working
return result;
}
public static double annuity(double yearly_pay, double int_rate, double num_of_years) {
double outcome = Math.sqrt(p* ((1 + r/100)eY - 1)/r/100);// keep working
return outcome;
}
  
}//end class method

Solutions

Expert Solution

Program:

import java.util.*;

public class Lab3 {

public static void main(String[] args) {

System.out.println("Lab 3 written by Tesfalem Tekie.");

Scanner input = new Scanner(System.in);

System.out.print("Enter amount: ");// will work on the prompt

double Value = input.nextDouble();

System.out.print("Enter interest rate: ");

double Rate = input.nextDouble();

System.out.print("Enter number of years: ");

double Years = input.nextDouble();

double futureValue = account(Value, Rate, Years);

System.out.printf("The future value is %.2f",futureValue);// keep working

double AnnFutureValue = annuity(Value, Rate, Years);

System.out.printf("\nThe annual future value is %.2f",AnnFutureValue);// keep working

}//end main method

public static double account(double p, double r, double Y ) {

double result = p*Math.pow((1 + r/100),Y);// keep working

return result;

}

public static double annuity(double p, double r, double Y) {

double outcome = p * (Math.pow((1 + r/100),Y)-1)/(r/100);// keep working

return outcome;

}

}

Output:.


Related Solutions

Write a program calls each of the three methods described below and prints out the result...
Write a program calls each of the three methods described below and prints out the result of the two methods which return value reverse- a void method that reverses the elements of the array. Print the array before you call the method and after call the method. getMin- an int method that returns the smallest value in the array Sample output array: 22,34,21,35,12,4,2,3,99,81 array in reverse: 81,99,3,2,4,12,35,21,34,22 the smallest number is 2
/* Problem 1 * Write and run a java program that prints out two things you...
/* Problem 1 * Write and run a java program that prints out two things you have learned * so far in this class, and three things you hope to learn, all in different lines. */ You could write any two basic things in Java. /* Problem 2 * The formula for finding the area of a triangle is 1/2 (Base * height). * The formula for finding the perimeter of a rectangle is 2(length * width). * Write a...
C Programming question: Develop a program named “sample” that prints the value of two functions: 1....
C Programming question: Develop a program named “sample” that prints the value of two functions: 1. Function f1 takes a single input argument of type int and returns the value of its input argument as float 2. Function f2 takes a single input argument of type char and returns an int. The output of f2 is the result of the sum of the values of the global variables, and the input argument minus the value of char ‘a’ plus the...
a). Write a program that asks the user to enter an integer N and prints two...
a). Write a program that asks the user to enter an integer N and prints two integers, root and power, such that 1 < power < 6 and N = root ** power. If no such pair of integers exists, it should print a message to that effect. There are two loops, one for power and one for root. Order the loops so that if N = 64, then your program find that N = 8 ** 2 rather than...
Write a java program calls the following methods: a. printStars(): Takes an int (n) as parameter...
Write a java program calls the following methods: a. printStars(): Takes an int (n) as parameter and prints n stars (*) using for loop. ex. 6 ******
Write a program to compute intersection of two sorted array of integers and compute the CPU...
Write a program to compute intersection of two sorted array of integers and compute the CPU time for different sets of unsigned integers generated by a random number generator. Test this using the same data sets: atleast 3 of size 1000 integers, atleast 3 of size 10000 integers, atleast 3 of size 100000 integers, atleast 3 of one million integers and atleast 3 of size 10 million integers DONT FORGET CPU TIME FOR EACH ONE NO HASH SET
*Java program* Use while loop 1.) Write a program that reads an integer, and then prints...
*Java program* Use while loop 1.) Write a program that reads an integer, and then prints the sum of the even and odd integers. 2.) Write program to calculate the sum of the following series where in is input by user. (1/1 + 1/2 + 1/3 +..... 1/n)
Write a program that prompts a user for an integer from 1 to 99 and prints...
Write a program that prompts a user for an integer from 1 to 99 and prints it as an amount in words. The program will loop in case the user wants to input an additional number. If the user enters -99, the program will exit. Example: Input: 89 Output: Eighty nine Input: 45 Output: Fourty five Input: -99 Output: Have a nice day. <program exits> For this project, you are to: 1) You should validate any data coming from the...
1. Write a program that prints a set of sqaures based on the widths stored in...
1. Write a program that prints a set of sqaures based on the widths stored in an array. Below are the specifications:  Ask the user for the number of sqaures to be printed  Create an array (based on the number of sqaures) to hold the widths  Ask the user for widths and store in the array  Print the sqaures (using any character (e.g. asterisk)) based on the widths stored in the array. (Java language)
Write a program that prompts a user for an integer from 1 to 99 and prints...
Write a program that prompts a user for an integer from 1 to 99 and prints it as an amount in words. The program will loop in case the user wants to input an additional number. If the user enters -99, the program will exit. Example: Input: 89 Output: Eighty nine Input: 45 Output: Fourty five Input: -99 Output: Have a nice day. <program exits> c++ project. need help.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT