Advertisement
HarrJ

Day 14

Sep 29th, 2023 (edited)
1,205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.38 KB | None | 0 0
  1. package week2;
  2.  
  3. public class Day14A {
  4.     public static void main(String[] args) {
  5.         Walking callWalking = new Walking();
  6.         callWalking.summary();
  7.     }
  8. }
  9.  
  10. abstract class TransportationMethods {
  11.     abstract void transpoInfo();
  12.     abstract void traspoSpeed();
  13.     abstract void transpoPassengers();
  14.  
  15.     void summary() {
  16.         transpoInfo();
  17.         traspoSpeed();
  18.         transpoPassengers();
  19.     }
  20. }
  21.  
  22. class Walking extends TransportationMethods{
  23.     void transpoInfo() {
  24.         System.out.println("Walking is a type of cardiovascular physical activity,"
  25.         +" which increases your heart rate. This improves blood flow and can lower blood pressure.");
  26.     }
  27.  
  28.     void traspoSpeed() {
  29.         System.out.println("A walking speed can reach up to 4.8 kph");
  30.     }
  31.    
  32.     void transpoPassengers() {
  33.         System.out.println("You are only carrying yourself when walking");
  34.     }
  35.    
  36. }
  37.  
  38. // class Biking extends TransportationMethods{
  39. //     void transpoInfo() {
  40.        
  41. //     }
  42.  
  43. //     void traspoSpeed() {
  44.  
  45. //     }
  46.    
  47. //     void transpoPassengers() {
  48.        
  49. //     }
  50. // }
  51.  
  52.  
  53. // class Motorcycle extends TransportationMethods{
  54. //     void transpoInfo() {
  55.        
  56. //     }
  57.  
  58. //     void traspoSpeed() {
  59.  
  60. //     }
  61.    
  62. //     void transpoPassengers() {
  63.        
  64. //     }
  65. // }
  66.  
  67.  
  68. // class Airplane extends TransportationMethods{
  69. //     void transpoInfo() {
  70.        
  71. //     }
  72.  
  73. //     void traspoSpeed() {
  74.  
  75. //     }
  76.    
  77. //     void transpoPassengers() {
  78.        
  79. //     }
  80. // }
  81.  
  82.  
  83. // class Ship extends TransportationMethods{
  84. //     void transpoInfo() {
  85.        
  86. //     }
  87.  
  88. //     void traspoSpeed() {
  89.  
  90. //     }
  91.    
  92. //     void transpoPassengers() {
  93.        
  94. //     }
  95. // }
  96.  
  97. //-- TRY CATCH SAMPLE ---------------------------
  98. package week2;
  99. import java.util.Scanner;
  100.  
  101. public class Day14D {
  102.     public static void main(String[] args) {
  103.         Scanner sc = new Scanner(System.in);
  104.         int cellNum;
  105.         double[] numList = new double[5];
  106.         String txtIn = "";
  107.  
  108.         System.out.print("enter cell number(0 - 4):");
  109.         txtIn = sc.nextLine();
  110.         if (isNumeric(txtIn)) {
  111.             cellNum = (int) Double.parseDouble(txtIn);
  112.             // kaya nag type casting kasi yung isNumeric ay pang double
  113.             System.out.println("test cell num: " + cellNum);
  114.         } else {
  115.             cellNum = 0;
  116.         }
  117.  
  118.         System.out.print("enter number for cell: ");
  119.         txtIn = sc.nextLine();
  120.         try {
  121.             numList[cellNum] = Double.parseDouble(txtIn);
  122.         } catch (ArrayIndexOutOfBoundsException e) {
  123.             System.out.println("cell number bigger than array");
  124.         } catch (NumberFormatException e) {
  125.             System.out.println("user input not a number");
  126.         }
  127.  
  128.         for (double d : numList) {
  129.             System.out.println("|"+d);
  130.         }
  131.         // if (isNumeric(txtIn)) {
  132.         //     numList[cellNum] = Double.parseDouble(txtIn);
  133.         // } else {
  134.         //     numList[cellNum] = Math.random()*22;
  135.         // }
  136.     }
  137.    
  138.  
  139.     public static boolean isNumeric(String strNum) {
  140.         if (strNum == null) {
  141.             return false;
  142.         }
  143.         try {
  144.             double d = Double.parseDouble(strNum);
  145.         } catch (NumberFormatException nfe) {
  146.             return false;
  147.         }
  148.         return true;
  149.     }
  150. }
  151.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement