The program below is the solution to Liang’s Introduction to Java Programming (9th Edition) Chapter 2 Exercise 2.22.Question: Write a…
The program below is the solution to Liang’s Introduction to Java Programming (9th Edition) Chapter 2 Exercise 2.24.Question: Rewrite Listing…
The program below is the solution to Liang’s Introduction to Java Programming (9th Edition) Chapter 2 Exercise 2.21.
1 2 |
/**<br /> *<br /> * @Author: Aghatise Osazuwa<br /> * Website: www.cscprogrammingtutorials.com<br /> *<br /> * Exercise 2.21 - Financial application: calculate future investment value<br /> *<br /> */ <br /><br />import java.util.Scanner;<br /><br />public class Ex02_21 {<br /><br /> public static void main(String[] args) {<br /> <br /> // Display Program Information<br /> System.out.println("This Program Calculates The Future Investment Value"<br /> + " of Investment.n");<br /><br /> // create Scanner <br /> Scanner input = new Scanner(System.in);<br /><br /> // prompt user to enter details<br /> System.out.println("Enter investment amount:");<br /> double investmentAmount = input.nextDouble();<br /> System.out.println("Enter annual interest rate in percentage:");<br /> double monthlyInterestRate = input.nextDouble();<br /> System.out.println("Enter number of years:");<br /> double numberOfYears = input.nextDouble();<br /><br /> // calculate s using the formula futureInvestmentValue = <br /> // investmentAmount x (1 + monthlyInterestRate)^numberOfYears*12<br /> double futureInvestmentValue =<br /> investmentAmount * Math.pow((1 + (monthlyInterestRate / 1200)), (numberOfYears * 12));<br /> // format futureInvestmentValue to two decimal places<br /> futureInvestmentValue = (int) (futureInvestmentValue * 100) / 100.0;<br /><br /> // display the result<br /> System.out.println("Accumulated value is $" + futureInvestmentValue + "n");<br /> }<br />}<br /> |
Program outputClick here…
The program below is the solution to Liang’s Introduction to Java Programming (9th Edition) Chapter 2 Exercise 2.19.Question: Write a…
The program below is the answer to Liang’s Introduction to Java Programming (9th Edition) Chapter 2 Exercise 2.18.
1 2 |
/**<br /> *<br /> * @Author: Aghatise Osazuwa<br /> * Website: www.cscprogrammingtutorials.com<br /> *<br /> * Exercise 2.18 - Print a table<br /> *<br /> */ <br /><br />public class Ex02_18 {<br /><br /> public static void main(String[] args) {<br /> <br /> // Display Program Information<br /> System.out.println("This Program Prints A Table.n");<br /> System.out.println("tatbtpow(a, b)");<br /> System.out.println("t" + 1 + "t" + 2 + "t" + (int) Math.pow(1, 2));<br /> System.out.println("t" + 2 + "t" + 3 + "t" + (int) Math.pow(2, 3));<br /> System.out.println("t" + 3 + "t" + 4 + "t" + (int) Math.pow(3, 4));<br /> System.out.println("t" + 4 + "t" + 5 + "t" + (int) Math.pow(4, 5));<br /> System.out.println("t" + 5 + "t" + 6 + "t" + (int) Math.pow(5, 6));<br /> }<br />}<br /> |
Click here to…
The program below is the solution to Liang’s Introduction to Java Programming (9th Edition) Chapter 2 Exercise 2.17.Question: How cold is…
The program below is the solution to Liang’s Introduction to Java Programming (9th Edition) Chapter 2 Exercise 2.20.Question: If you…
The program below is the answer to Liang’s Introduction to Java Programming (9th Edition) Chapter 2 Exercise 2.16.
1 2 |
/**<br /> *<br /> * @Author: Aghatise Osazuwa<br /> * Website: www.cscprogrammingtutorials.com<br /> *<br /> * Exercise 2.16 - Geometry: Area of a Hexagon<br /> *<br /> */ <br /><br />import java.util.Scanner;<br /><br />public class Ex02_16 {<br /><br /> public static void main(String[] args) {<br /> <br /> //Display Program Information<br /> System.out.println("This Program Calculates The Area Of A Hexagon.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 length of a side of the hexagon:");<br /> double side = input.nextDouble();<br /><br /> //calculate area using the formula ((3√3) ÷ 2) * the square of the length of a side<br /> double area = ((3 * (Math.pow(3, 0.5))) / 2) * side * side;<br /> //format area to two decimal places<br /> area = (int) (area * 10000) / 10000.0;<br /><br /> //display the result<br /> System.out.println("The area of the hexagon is " + area + "n");<br /> }<br />}<br /> |
Click here to…
The program below is the answer to Liang’s Introduction to Java Programming (9th Edition) Chapter 2 Exercise 2.14.Question: Health application:…
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…
The program below is the answer to Liang’s Introduction to Java Programming (9th Edition) Chapter 2 Exercise 2.12.
1 2 |
/**<br /> *<br /> * @Author: Aghatise Osazuwa<br /> * Website: www.cscprogrammingtutorials.com<br /> *<br /> * Exercise 2.12 - Physics: Finding Runway Length<br /> *<br /> */ <br /><br />import java.util.Scanner;<br /><br />public class RunwayLength {<br /><br /> public static void main(String[] args) {<br /> <br /> //Display Program Information<br /> System.out.println("This Program Calculates The Minimum Runway Length "<br /> + "Needed For An Airplane To Take Off.n");<br /><br /> //create Scanner <br /> Scanner input = new Scanner(System.in);<br /><br /> //prompt user to enter details<br /> System.out.println("Enter speed (in meters per second) and "<br /> + "acceleration (in meters/second squared):");<br /> double speed = input.nextDouble();<br /> double acceleration = input.nextDouble();<br /><br /> //calculate length <br /> double length = ((speed * speed) / (2 * acceleration));<br /> <br /> //format length to 4 decimal places<br /> length = (int)(length * 10000) / 10000.0;<br /><br /> //display the result<br /> System.out.println("The minimum runway length for this airplane is "<br /> + length + "n");<br /> }<br />}<br /> |
Click here to…
The program below is the answer to Liang’s Introduction to Java Programming (9th Edition) Chapter 2 Exercise 2.11.Question: Rewrite Exercise…