The program below is the answer to Liang’s Introduction to Java Programming (9th Edition) Chapter 2 Exercise 2.13.
1 2 |
/**<br /> *<br /> * @Author: Aghatise Osazuwa<br /> * Website: www.cscprogrammingtutorials.com<br /> *<br /> * Exercise 2.13 - Financial Application: Compound Value<br /> *<br /> */ <br /><br />import java.util.Scanner;<br /><br />public class CompoundValue {<br /><br /> public static void main(String[] args) {<br /> <br /> //Display Program Information<br /> System.out.println("This Program Calculates The Compound Value Of An "<br /> + "Account After The Sixth Month.n");<br /><br /> //create Scanner <br /> Scanner input = new Scanner(System.in);<br /><br /> //prompt user to enter details<br /> System.out.println("Enter the monthly saving amount:");<br /> double savings = input.nextDouble();<br /><br /> //calculate the account value after the sixth month<br /> double firstMonth = savings * (1 + 0.00417);<br /> double secondMonth = (savings + firstMonth) * (1 + 0.00417);<br /> double thirdMonth = (savings + secondMonth) * (1 + 0.00417);<br /> double fourthMonth = (savings + thirdMonth) * (1 + 0.00417);<br /> double fifthMonth = (savings + fourthMonth) * (1 + 0.00417);<br /> double sixthMonth = (savings + fifthMonth) * (1 + 0.00417);<br /><br /> //format the sixth month to two decimal places<br /> sixthMonth = (int) (sixthMonth * 100) / 100.0;<br /><br /> //display the result<br /> System.out.println("After the sixth month, the account value is $"<br /> + sixthMonth + "n");<br /> }<br />}<br /> |
Click here to…