Write a Java program called Methods contained in 1 Java source file that contains 2 methods named calculateBalance and reverseString that take and return values and produces the output below. The calculateBalance method will calculate the yearly balance of a bank savings account each year for 5 years given a starting principle, the interest rate, and a yearly deposit amount. The method should accept these values as parameters and return the account balance 5 year period. The formula to use for the ending balance for a single year is principle (1+rate) yearly deposit. The starting balance for the first year is just the initial principle (i.e. nitial deposit amount) The reverse String method will simply take a string value (we assume not null) and return a string value that is the reverse of the in For example if we take This\" the method would return \"sihT\" Hint: Your main method should call calculateBalance like this: System. out. rintln \"New balance calculate Balance rinciple rate earl deposit) Hint: Your main method should call reverse Strin like this: System. out. rintln \"Reverse of str1 reverse String (strl) Note: in the output below, replace \"Student Name\" with your actual name Things that will cost you points (not necessarily a comprehensive list) doesn\'t compile doesn\'t produce correct output doesn\'t contain methods that take and return values hard-coded (non-calculated) output uses if-statement(s) uses extra un-needed variables file/class/methods named incorrectly hard to read indentation
HI Friend, Please find my implementation.
Please let me know in case of any issue.
import java.util.Scanner;
public class Methods {
public static double calculateBalance(double p, double r, double yd){
System.out.println(\"Year\\t\\tNew Balance\");
int i = 0;
double newBal = p;
while( i < 5){
i++;
newBal = newBal*(1+r) + yd;
System.out.println(i+\"\\t\\t\"+newBal);
}
return newBal;
}
public static String reverseString(String s){
String rev = \"\";
int i = s.length()-1;
while(i >= 0){
rev = rev + s.charAt(i);
i--;
}
return rev;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print(\"principle: \");
double p = sc.nextDouble();
System.out.print(\"rate: \");
double r = sc.nextDouble();
System.out.print(\"yearly deposite: \");
double yd = sc.nextDouble();
System.out.println(\"\ New Balance: \"+calculateBalance(p, r, yd));
System.out.println(\"\ Enter string: \");
sc.nextLine();
String str = sc.nextLine();
System.out.println(\"Reverse of \\\"\"+str+\"\\\" is: \\\"\"+
reverseString(str)+\"\\\"\");
}
}
/*
Sample run:
principle: 5000.0
rate: 0.025
yearly deposite: 100.0
Year New Balance
1 5225.0
2 5455.624999999999
3 5692.015624999998
4 5934.316015624998
5 6182.673916015622
New Balance: 6182.673916015622
Enter string:
THis is my string
Reverse of \"THis is my string\" is: \"gnirts ym si siHT\"
*/