Skip to content

Commit 73955aa

Browse files
committed
Chapter 14 completed new questions + added JavaFx resources that come with the book....
1 parent 338e2de commit 73955aa

File tree

292 files changed

+485
-302
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

292 files changed

+485
-302
lines changed

README.md

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
11
# INTRODUCTION TO JAVA PROGRAMMING 10TH EDITION <br> _Exercise Solutions_
22
### This repo contains solutions to the end-of-chapter exercise’s from <a href="https://www.amazon.com/Intro-Java-Programming-Comprehensive-Version/dp/0133761312">Y. Daniel Liang’s Intro to Java Programming (10th Edition)</a>
3-
##### _The goal of this repo is to solve the end-of-chapter exercises by satisfying the requirements of the <i><a href="https://liveexample.pearsoncmg.com/CheckExercise/faces/CheckExercise.xhtml?chapter=1&programName=Exercise01_01">Exercise Check Tool</a> that comes with the book</i>._
43
#### - About the 10th Edition -
54
_"Daniel Liang teaches concepts of problem-solving and object-oriented programming using a fundamentals-first approach
65
. Beginning programmers learn critical problem-solving techniques then move on to grasp the key concepts of
7-
object-oriented, GUI programming, advanced GUI and Web programming using Java. Liang approaches Java GUI programming using JavaFX, not only because JavaFX is much simpler for new Java programmers to learn and use but because it has replaced Swing as the new GUI tool for developing cross-platform-rich Internet applications on desktop computers, on hand-held devices, and on the Web. Additionally, for instructors, JavaFX provides a better teaching tool for demonstrating object-oriented programming."_
6+
object-oriented, GUI programming, advanced GUI and Web programming using Java..."_
87

98
### **Companion Content:**
109
- ### <a href="http://liveexample.pearsoncmg.com/liang/intro10e">10th Edition Companion Website</a>
1110
- ### <a href="https://liveexample.pearsoncmg.com/CheckExercise/faces/CheckExercise.xhtml?chapter=1&programName=Exercise01_01">Exercise Check Tool</a>
1211
- ### <a href="https://liveexample.pearsoncmg.com/javarevel2e.html">Hints to Quizzes and Programming Projects</a>
1312
- ### <a href='#checkpoint-answers'>Checkpoint Answers</a>
13+
- ### <a href="https://media.pearsoncmg.com/ph/esm/ecs_liang_ijp_10/ExampleByChapters.html">Example Programs By Chapter</a>
14+
- ### <a href="http://liveexample.pearsoncmg.com/liang/animation/animation.html">Algorithm Animations</a>
15+
- ### <a href="https://media.pearsoncmg.com/ph/esm/ecs_liang_ijp_10/supplement/Supplement1dcodingguidelines.html">Java Coding Style Guidelines</a>
1416

1517

1618

17-
____
18-
### <em>Contributors:</em>
19-
20-
### Harry Dulaney, _Your Name Here_
2119
____
2220
### <em>Pull requests:</em>
23-
_Please feel free to make pull requests. I will do my best to review them quickly._
21+
_Please feel free to make pull requests. They are reviewed quickly_
2422
- ##### Pull Requests should be used for adding new solutions to the repo that do not already exist.
23+
2524
____
2625
### <em>Issue's:</em>
2726
_Please feel free to open new Issues._

src/ch_03/Exercise03_01.java

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
* Note that you can use Math.pow(x, 0.5) to compute SQRT(x). Here are some
1919
* sample runs.
2020
*
21-
* @author Harry Dulaney IV
2221
*/
2322
public class Exercise03_01 {
2423
public static void main(String[] args) {

src/ch_03/Exercise03_02.java

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
* Revise the program to generate three single-digit integers and prompt the user to
99
* enter the sum of these three integers.
1010
*
11-
* @author Harry Dulaney IV
1211
*/
1312
public class Exercise03_02 {
1413

src/ch_03/Exercise03_03.java

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
* the user to enter a, b, c, d, e, and f and displays the result. If ad - bc is 0, report
99
* that �The equation has no solution.�
1010
*
11-
* @author Harry Dulaney
1211
*/
1312
public class Exercise03_03 {
1413

src/ch_03/Exercise03_04.java

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
* between 1 and 12 and displays the English month name January,
66
* February, �, December for the number 1, 2, �, 12, accordingly.
77
*
8-
* @author Harry Dulaney IV
98
*/
109
public class Exercise03_04 {
1110
public static void main(String[] args) {

src/ch_03/Exercise03_05.java

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
* prompt the user to enter the number of days after today for a future day and display
99
* the future day of the week.
1010
*
11-
* @author Harry G. Dulaney IV
1211
*/
1312
public class Exercise03_05 {
1413

src/ch_03/Exercise03_06.java

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* inches, you will enter 5 for feet and 10 for inches.
77
* <p>
88
*
9-
* @author Harry Dulaney IV
109
*/
1110
public class Exercise03_06 {
1211
public static void main(String[] args) {

src/ch_03/Exercise03_07.java

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* units such as 1 dollar and 1 penny, and plural words for more than one unit such
77
* as 2 dollars and 3 pennies.
88
*
9-
* @author Harry Dulaney IV
109
*/
1110
public class Exercise03_07 {
1211
public static void main(String[] args) {

src/ch_03/Exercise03_09.java

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
* displays the 10-digit ISBN (including leading zeros). Your program should
2020
* read the input as an integer.
2121
*
22-
* @author Harry Dulaney
2322
*/
2423
public class Exercise03_09 {
2524

src/ch_03/Exercise03_10.java

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
* Revise the program to randomly generate an addition question with two
1010
* integers less than 100.
1111
*
12-
* @author Harry Dulaney
1312
*/
1413
public class Exercise03_10 {
1514

src/ch_03/Exercise03_11.java

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
* should display that February 2012 had 29 days. If the user entered month 3
1010
* and year 2015, the program should display that March 2015 had 31 days.
1111
*
12-
* @author Harry Dulaney
1312
*/
1413
public class Exercise03_11 {
1514

src/ch_03/Exercise03_12.java

-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
* right. Here is a sample run of this program:
1010
* <p>
1111
* Enter a three-digit integer: 121 121 is a palindrome
12-
*
13-
* @author Harry Dulaney
1412
*/
1513
public class Exercise03_12 {
1614
public static void main(String[] args) {

src/ch_03/Exercise03_13.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
* gives the source code to compute taxes for single filers. Complete Listing
88
* 3.5 to compute the taxes for all filing statuses
99
*
10-
* @author Harry Dulaney
11-
*
10+
*
1211
*/
1312
public class Exercise03_13 {
1413

src/ch_03/Exercise03_14.java

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
* the flip of a coin results in heads or tails. The program randomly generates
88
* an integer 0 or 1, which represents head or tail. The program prompts the
99
* user to enter a guess and reports whether the guess is correct or incorrect.
10-
* @author Harry Dulaney
1110
*/
1211
public class Exercise03_14 {
1312
public static void main(String[] args) {

src/ch_03/Exercise03_15.java

-3
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@
1717
* <p>
1818
* 3. If one digit in the user input matches a digit in the lottery number, the
1919
* award is $1,000
20-
*
21-
* @author Harry Dulaney
2220
*/
23-
2421
public class Exercise03_15 {
2522
public static void main(String[] args) {
2623

src/ch_03/Exercise03_16.java

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* 3.16 (Random point) Write a program that displays a random coordinate in a
77
* rectangle. The rectangle is centered at (0, 0) with width 100 and height 200
88
*
9-
* @author Harry Dulaney
109
*/
1110
public class Exercise03_16 {
1211
public static void main(String[] args) {

src/ch_03/Exercise03_17.java

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
* Here are sample runs: scissor (0), rock (1), paper (2): 1 The computer is
1717
* scissor. You are rock. You won
1818
*
19-
* @author Harry Dulaney
2019
*/
2120
public class Exercise03_17 {
2221

src/ch_03/Exercise03_18.java

-3
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@
1111
* Write a program that prompts the user to enter the weight of the package and
1212
* display the shipping cost. If the weight is greater than 50, display a
1313
* message “the package cannot be shipped.”
14-
*
15-
* @author Harry Dulaney
1614
*/
17-
1815
public class Exercise03_18 {
1916
public static void main(String[] args) {
2017
Scanner in = new Scanner(System.in);

src/ch_03/Exercise03_19.java

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
* The input is valid if the sum of every pair of two edges is greater than the
1111
* remaining edge
1212
*
13-
* @author Harry Dulaney
1413
*/
1514
public class Exercise03_19 {
1615
public static void main(String[] args) {

src/ch_03/Exercise03_20.java

-4
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,11 @@
1212
* speed. The program displays the wind-chill temperature if the input is valid;
1313
* otherwise, it displays a message indicating whether the temperature and/or
1414
* wind speed is invalid.
15-
*
16-
* @author Harry Dulaney
1715
*/
18-
1916
public class Exercise03_20 extends Exercise03_21 {
2017
public static void main(String[] args) {
2118

2219
Scanner input = new Scanner(System.in);
23-
2420
System.out.println("Enter the temperature in Fahrenheit between -58°F and 41°F: ");
2521
double temp = input.nextDouble();
2622

src/ch_03/Exercise03_21.java

-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
* year.)
3737
*
3838
*
39-
* @author Harry D.
4039
*/
4140
public class Exercise03_21 {
4241
public static void main(String[] args) {

src/ch_03/Exercise03_22.java

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package ch_03;
22

3-
import java.awt.*;
43
import java.util.*;
54

65
/**
@@ -24,8 +23,6 @@
2423
* <p>
2524
* Enter a point with two coordinates: 9 9
2625
* Point (9.0, 9.0) is not in the circle
27-
*
28-
* @author Harry Dulaney
2926
*/
3027
public class Exercise03_22 {
3128
public static void main(String[] args) {

src/ch_03/Exercise03_23.java

-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
* <p>
2121
* Enter a point with two coordinates: 6 4
2222
* Point (6.0, 4.0) is not in the rectangle
23-
*
24-
* @author Harry Dulaney
2523
*/
2624
public class Exercise03_23 {
2725
public static void main(String[] args) {

src/ch_03/Exercise03_24.java

-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
* Here is a sample run of the program:
1212
* <p>
1313
* The card you picked is Jack of Hearts
14-
*
15-
* @author Harry Dulaney
1614
*/
1715
public class Exercise03_24 {
1816
public static void main(String[] args) {

src/ch_03/Exercise03_25.java

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
* Enter x1, y1, x2, y2, x3, y3, x4, y4: 2 2 7 6.0 4.0 2.0 -1.0 -2.0
2525
* The two lines are parallel
2626
*
27-
* @author Harry Dulaney
2827
*/
2928
public class Exercise03_25 {
3029
public static void main(String[] args) {

src/ch_03/Exercise03_27.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323
* The point is in the triangle
2424
* <p>
2525
*
26-
* @author Harry Dulaney
27-
*/
26+
*/
2827
public class Exercise03_27 {
2928
public static void main(String[] args) {
3029
Scanner in = new Scanner(System.in);

src/ch_03/Exercise03_29.java

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
* Enter circle2's center x-, y-coordinates, and radius: 1 1.7 4.5
1818
* circle2 is inside circle1
1919
*
20-
* @author Harry Dulaney
2120
*/
2221
public class Exercise03_29 {
2322
public static void main(String[] args) {

src/ch_04/Exercise04_04.java

+13-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
import java.util.Scanner;
44

5+
/**
6+
* 4.4 (Geometry: area of a hexagon) The area of a hexagon can be computed using the
7+
* following formula (s is the length of a side):
8+
* Area =
9+
* 6 * s2
10+
* 4 * tan¢ p6 ≤
11+
* Write a program that prompts the user to enter the side of a hexagon and displays
12+
* its area. Here is a sample run:
13+
* Enter the side: 5.5
14+
* The area of the hexagon is 78.59
15+
*/
516
public class Exercise04_04 {
617
public static void main(String[] args) {
718

@@ -11,9 +22,9 @@ public static void main(String[] args) {
1122

1223
double side = input.nextDouble();
1324

14-
double area = (6 * Math.pow(side, 2))/(4 * Math.tan(Math.PI/6));
25+
double area = (6 * Math.pow(side, 2)) / (4 * Math.tan(Math.PI / 6));
1526

16-
System.out.println("The area of the hexagon is " + area +".");
27+
System.out.println("The area of the hexagon is " + area + ".");
1728

1829
}
1930
}

src/ch_04/Exercise04_05.java

+15
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@
22

33
import java.util.*;
44

5+
/**
6+
* 4.5 (Geometry: area of a regular polygon) A regular polygon is an n-sided polygon in
7+
* which all sides are of the same length and all angles have the same degree (i.e., the
8+
* polygon is both equilateral and equiangular). The formula for computing the area
9+
* of a regular polygon is
10+
* Area =
11+
* n * s2
12+
* 4 * tan¢ pn ≤
13+
* Here, s is the length of a side. Write a program that prompts the user to enter the
14+
* number of sides and their length of a regular polygon and displays its area. Here is
15+
* a sample run:
16+
* Enter the number of sides: 5
17+
* Enter the side: 6.5
18+
* The area of the polygon is 74.69017017488385
19+
*/
520
public class Exercise04_05 {
621
//computes the area of a regular polygon
722
public static void main(String[] args) {

src/ch_04/Exercise04_16.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
package ch_04;
22

3-
// displays a random upper-case character
4-
53

4+
/**
5+
* 4.16 (Random character) Write a program that displays a random uppercase letter
6+
* using the Math.random() method.
7+
*/
68
public class Exercise04_16 {
79
public static void main(String[] args) {
810

911
//Ascii characters A to Z are represented by numbers 65 to 90
1012
//So we need to generate a random number in range 65 to 90
1113
//And then print its char value
1214

13-
int random = 65 + (int)(Math.random() * 26);
15+
int random = 65 + (int) (Math.random() * 26);
1416

15-
System.out.println((char)(random));
17+
System.out.println((char) (random));
1618

1719
}
1820

src/ch_05/Exercise05_46.java

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
package ch_05;
22

3-
/* 5.46 (Reverse a string) Write a program that prompts
3+
import java.util.Scanner;
4+
5+
/**
6+
* 5.46 (Reverse a string) Write a program that prompts
47
* the user to enter a string and displays the string in reverse order.
58
*/
9+
public class Exercise05_46 {
10+
public static void main(String[] args) {
11+
Scanner input = new Scanner(System.in);
612

7-
import java.util.Scanner;
13+
System.out.print("Enter a string: ");
14+
String str = input.nextLine();
815

9-
public class Exercise05_46 {
10-
public static void main(String[] args) {
11-
Scanner input = new Scanner(System.in);
12-
13-
System.out.print("Enter a string: ");
14-
String str = input.nextLine();
15-
16-
for(int i = str.length()-1;i >= 0;i--) {
17-
18-
System.out.print(str.charAt(i));
19-
20-
}
21-
22-
}
16+
for (int i = str.length() - 1; i >= 0; i--) {
17+
18+
System.out.print(str.charAt(i));
19+
20+
}
21+
22+
}
2323

2424
}

0 commit comments

Comments
 (0)