diff --git a/source/ch3_javadatatypes.ptx b/source/ch3_javadatatypes.ptx
index 859fc5b..a9ae75a 100644
--- a/source/ch3_javadatatypes.ptx
+++ b/source/ch3_javadatatypes.ptx
@@ -281,42 +281,75 @@ public class TempConv {
The general rule in Java is that you must decide what kind of an object your variable is going to reference and then you must declare that variable before you use it. In our temperature converter, the calculation (fahr - 32) * 5.0/9.0 works correctly because 5.0 and 9.0 are treated as double values, preventing the integer division that would occur if we had written 5/9, which would result in 0.
-
-
+
- Write a program that converts km to miles. Use the Scanner class to read the input. Note that 1 km is approximately equal to 0.621 miles.
+ Construct a complete Java program that reads a distance in kilometers from the user and converts it to miles.
+ Drag the blocks into the correct order on the right.
-
-
-public class KmToMiles {
- public static void main(String[] args) {
- // write your code here
- }
-}
-
-
-
-
-
-import java.util.Scanner;
-public class KmToMiles {
- public static void main(String[] args) {
- Double kilometers;
- Double miles;
- Scanner input;
- input = new Scanner(System.in);
- System.out.print("Enter distance in kilometers: ");
- kilometers = input.nextDouble();
- miles = kilometers * 0.621;
- System.out.println(kilometers + " kilometers is equal to " + miles + " miles.");
- }
-}
-
-
-
+
+
+
+
+ import java.util.Scanner;
+
+
+ import Scanner;
+
+
+
+
+ public class KmToMiles {
+
+
+
+ public static void main(String[] args) {
+
+
+
+ Scanner input;
+ Double kilometers;
+ Double miles;
+
+
+
+
+ input = new Scanner(System.in);
+
+
+ input = new Scanner(System.out);
+
+
+
+
+
+ kilometers = input.nextDouble();
+
+
+ kilometers = input.readDouble();
+
+
+
+
+
+ miles = kilometers * 0.621;
+
+
+ miles = kilometers / 0.621;
+
+
+
+
+ System.out.println(kilometers + " kilometers is equal to " + miles + " miles.");
+
+
+ }
+ }
+
+
+
@@ -485,6 +518,63 @@ void main() {
In , we first create a Dog object and assign it to an Animal reference (upcasting). Then, we check if the Animal reference is actually pointing to a Dog object before downcasting it back to a Dog reference.
+
+
+
+
+ Construct a program that safely downcasts a Shape reference to a Circle object and calls a subclass method.
+ Drag the blocks into the correct order on the right.
+
+
+
+
+ class Shape {
+ ...
+ }
+
+
+
+ class Circle extends Shape {
+ public void drawCircle() {
+ System.out.println("Circle");
+ }
+ }
+
+
+
+ public class Downcast {
+ public static void main(String[] args) {
+ Shape myShape = new Circle();
+
+
+
+
+ if (myShape instanceof Circle) {
+
+
+ if (myShape.equals(Circle)) {
+
+
+
+
+
+ Circle myCircle = (Circle) myShape;
+ myCircle.drawCircle();
+
+
+ Circle myCircle = myShape;
+ myCircle.drawCircle();
+
+
+
+
+ }
+ }
+ }
+
+
+
+
@@ -1171,6 +1261,7 @@ public class HistoMap {
+
\ No newline at end of file