Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

### I've included links below to all the freely accessible companion material and quick links to navigate through my solutions by chapter.

### If you would like to contribute, please see: <a href="#contribute">Ways to Contribute</a>
### See <a href="#contribute">Contribution Guide</a> for coding guidelines and information on how to contribute.

____

Expand Down Expand Up @@ -41,9 +41,35 @@ object-oriented, GUI programming, advanced GUI and Web programming using Java...
### <a href="https://media.pearsoncmg.com/ph/esm/ecs_liang_ijp_10/supplement/Supplement1dcodingguidelines.html">Java Coding Style Guidelines</a>

____

<span id="contribute"><span/>
## How to Contribute

### _Coding Guidelines_
- #### Solution must use Java 8 SE, as this is the version used by the book.
- #### Every solution should have a java file containing a public main method for testing it.
- #### Naming convention is: ExerciseCC_EE.java where CC is the chapter number and EE is the exercise number.
- #### The public Exercise class containing the main method must include a JavaDoc comment on the class with original exercise question.
- #### Each solution should be its own self-contained program with minimal dependencies on other files. If you need multiple files please create a package for the exercise.
- #### ch_XX/exercise22_07/Exercise22_07.java
- #### This allows us to utilize the Exercise Checking Tool [Exercise Checking Tool](https://liveexample.pearsoncmg.com/CheckExercise/faces/CheckExercise.xhtml?chapter=1&programName=Exercise01_01) to verify solutions.
- ### Example exercise solution:
```java
package ch_01;
/**
* 1.1 (Display three messages) Write a program that displays Welcome to Java,
* Welcome to Computer Science, and Programming is fun.
*/
public class Exercise01_01 {
public static void main(String[] args) {
System.out.println("Welcome to Java");
System.out.println("Welcome to Computer Science");
System.out.println("Programming is fun");
}

}
```

## Contribution Guide:

### <em id="prs">Pull requests:</em>

Expand Down Expand Up @@ -132,7 +158,7 @@ Indicates 100% completion of all exercises for that chapter
<li><a href="https://github.com/HarryDulaney/intro-to-java-programming/tree/master/ch_15"><strong>Chapter 15
</strong></a> - Event-Driven Programming and Animations
<h6>
Exercises Needed: 23, 25, 27,31,33,35
Exercises Needed: 25,27,31,33,35
</h6>
</li><br>
<li><a href="https://github.com/HarryDulaney/intro-to-java-programming/tree/master/ch_16"><strong>Chapter
Expand Down
1 change: 0 additions & 1 deletion ch_01/Exercise01_01.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/
public class Exercise01_01 {
public static void main(String[] args) {

System.out.println("Welcome to Java");
System.out.println("Welcome to Computer Science");
System.out.println("Programming is fun");
Expand Down
73 changes: 73 additions & 0 deletions ch_15/Exercise15_23.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package ch_15;

import javafx.application.Application;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Polygon;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.scene.text.TextAlignment;
import javafx.stage.Stage;

/**
* *15.23 (Auto resize stop sign) Rewrite Programming Exercise 14.15 so that the stop
* sign’s width and height are automatically resized when the window is resized.
*/
public class Exercise15_23 extends Application {
double originalWidth = 200, originalHeight = 200;
double originalFontSize = 42;
@Override
public void start(Stage primaryStage) throws Exception {
StackPane stackPane = new StackPane();
stackPane.setPrefWidth(originalWidth);
stackPane.setPrefHeight(originalHeight);
drawStopSign(stackPane);
Scene scene = new Scene(stackPane, originalWidth, originalHeight);
primaryStage.setScene(scene);
primaryStage.setTitle(getClass().getName());
primaryStage.setResizable(true);
primaryStage.show();

scene.widthProperty().addListener((observable, oldValue, newValue) -> {
stackPane.setPrefWidth((double) newValue);
drawStopSign(stackPane);

});

scene.heightProperty().addListener((observable, oldValue, newValue) -> {
stackPane.setPrefHeight((double) newValue);
drawStopSign(stackPane);
});
}

void drawStopSign(StackPane stackPane) {
Polygon polygon = new Polygon();
stackPane.getChildren().clear();
double width = stackPane.getPrefWidth();
double height = stackPane.getPrefHeight();
stackPane.getChildren().add(polygon);
polygon.setFill(Color.RED);
polygon.setStroke(Color.RED);

ObservableList<Double> list = polygon.getPoints();
double centerX = width / 2, centerY = height / 2;
double radius = Math.min(width, height) * 0.4;
// Add points to the polygon list -> divide Math.PI by 8 for Octagon
for (int i = 0; i < 8; i++) {
list.add(centerX + radius * Math.cos(2 * i * Math.PI / 8));
list.add(centerY - radius * Math.sin(2 * i * Math.PI / 8));
}
polygon.setRotate(22.5);

Text text = new Text("STOP");
text.setTextAlignment(TextAlignment.CENTER);
text.setFill(Color.WHITE);
text.setStroke(Color.WHITE);
text.setFont(Font.font(originalFontSize * Math.min(width, height) / Math.min(originalWidth, originalHeight)));
stackPane.getChildren().add(text);

}

}
17 changes: 17 additions & 0 deletions ch_15/Exercise15_25.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package ch_15;

import javafx.application.Application;
import javafx.stage.Stage;

/**
* **15.25 (Animation: ball on curve) Write a program that animates a ball moving along
* a sine curve, as shown in Figure 15.32. When the ball gets to the right border,
* it starts over from the left. Enable the user to resume/pause the animation with
* a click on the left/right mouse button.
*/
public class Exercise15_25 extends Application {
@Override
public void start(Stage primaryStage) throws Exception {

}
}