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…
The program below is the answer to Liang’s Introduction to Java Programming (9th Edition) Chapter 1 Exercise 1.11.
1 2 |
/**<br /> *<br /> * @Author: Aghatise Osazuwa<br /> * Website: www.cscprogrammingtutorials.com<br /> *<br /> * Exercise 1.11 - Population Projection<br /> *<br /> */ <br /><br />import java.util.Scanner;<br /><br />public class PopulationProjection {<br /><br /> public static void main(String[] args) {<br /> <br /> int birth = 7;<br /> int death = 13;<br /> int immigrant = 45;<br /> int currentPopulation = 312032486;<br /> int year = 365;<br /> int yearlyBirths = (((60 * 60 * 24 * year) / birth));<br /> int yearlyDeaths = (((60 * 60 * 24 * year) / death));<br /> int yearlyImmigrants = (((60 * 60 * 24 * year) / immigrant));<br /> int yearlyPopulation = (yearlyBirths + yearlyImmigrants - yearlyDeaths);<br /><br /> System.out.println("Current Year Population = " + currentPopulation);<br /> System.out.println("Next Year's Population = "<br /> + (currentPopulation + yearlyPopulation));<br /> System.out.println("Next Two Year's Population = "<br /> + (currentPopulation + (yearlyPopulation * 2)));<br /> System.out.println("Next Three Year's Population = "<br /> + (currentPopulation + (yearlyPopulation * 3)));<br /> System.out.println("Next Four Year's Population = "<br /> + (currentPopulation + (yearlyPopulation * 4)));<br /> System.out.println("Next Five Year'ss Population = "<br /> + (currentPopulation + (yearlyPopulation * 5)));<br /> }<br />}<br /> |
Click here to…
The program below is the answer to Deitel’s Java How to Program (9th Edition) Chapter 5 Exercise 5.32.Question: According to…
Question: Develop a Java application that determines whether any of several department-store customers has exceeded the credit limit on a charge…
Question: Drivers are concerned with the mileage their automobiles get. One driver has kept track of several trips by recording the…
This is a simple Java program to produce a 12×12 multiplication table using 2-dimensional array.
1 2 |
/**<br /> *<br /> * @Author: Aghatise Osazuwa<br /> * Website: www.cscprogrammingtutorials.com<br /> *<br /> */ <br /><br />public class ArrayMultiplicationTable {<br /><br /> public static void main(String[] args) {<br /> int[][] demo = new int[12][12];<br /> int row = 1, column = 1;<br /> for (int x = 0; x < demo.length; x++) {<br /> for (int y = 0; y < demo[x].length; y++) {<br /> demo[x][y] = row * column;<br /> column = column + 1;<br /> }<br /> row = row + 1;<br /> column = 1;<br /> }<br /> for (int x = 0; x < demo.length; x++) {<br /> for (int y = 0; y < demo[x].length; y++) {<br /> System.out.print(" " + demo[x][y] + "t|");<br /> }<br /> System.out.println();<br /> }<br /> }<br />}<br /> |
See program output below Program output