Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package week2;
- public class Day14A {
- public static void main(String[] args) {
- Walking callWalking = new Walking();
- callWalking.summary();
- }
- }
- abstract class TransportationMethods {
- abstract void transpoInfo();
- abstract void traspoSpeed();
- abstract void transpoPassengers();
- void summary() {
- transpoInfo();
- traspoSpeed();
- transpoPassengers();
- }
- }
- class Walking extends TransportationMethods{
- void transpoInfo() {
- System.out.println("Walking is a type of cardiovascular physical activity,"
- +" which increases your heart rate. This improves blood flow and can lower blood pressure.");
- }
- void traspoSpeed() {
- System.out.println("A walking speed can reach up to 4.8 kph");
- }
- void transpoPassengers() {
- System.out.println("You are only carrying yourself when walking");
- }
- }
- // class Biking extends TransportationMethods{
- // void transpoInfo() {
- // }
- // void traspoSpeed() {
- // }
- // void transpoPassengers() {
- // }
- // }
- // class Motorcycle extends TransportationMethods{
- // void transpoInfo() {
- // }
- // void traspoSpeed() {
- // }
- // void transpoPassengers() {
- // }
- // }
- // class Airplane extends TransportationMethods{
- // void transpoInfo() {
- // }
- // void traspoSpeed() {
- // }
- // void transpoPassengers() {
- // }
- // }
- // class Ship extends TransportationMethods{
- // void transpoInfo() {
- // }
- // void traspoSpeed() {
- // }
- // void transpoPassengers() {
- // }
- // }
- //-- TRY CATCH SAMPLE ---------------------------
- package week2;
- import java.util.Scanner;
- public class Day14D {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int cellNum;
- double[] numList = new double[5];
- String txtIn = "";
- System.out.print("enter cell number(0 - 4):");
- txtIn = sc.nextLine();
- if (isNumeric(txtIn)) {
- cellNum = (int) Double.parseDouble(txtIn);
- // kaya nag type casting kasi yung isNumeric ay pang double
- System.out.println("test cell num: " + cellNum);
- } else {
- cellNum = 0;
- }
- System.out.print("enter number for cell: ");
- txtIn = sc.nextLine();
- try {
- numList[cellNum] = Double.parseDouble(txtIn);
- } catch (ArrayIndexOutOfBoundsException e) {
- System.out.println("cell number bigger than array");
- } catch (NumberFormatException e) {
- System.out.println("user input not a number");
- }
- for (double d : numList) {
- System.out.println("|"+d);
- }
- // if (isNumeric(txtIn)) {
- // numList[cellNum] = Double.parseDouble(txtIn);
- // } else {
- // numList[cellNum] = Math.random()*22;
- // }
- }
- public static boolean isNumeric(String strNum) {
- if (strNum == null) {
- return false;
- }
- try {
- double d = Double.parseDouble(strNum);
- } catch (NumberFormatException nfe) {
- return false;
- }
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement