Created
March 2, 2022 16:32
-
-
Save cbmeeks/1333737d36064b309f7b233498194a43 to your computer and use it in GitHub Desktop.
Pilot Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.company; | |
public class Main { | |
public static void main(String[] args) { | |
// write your code here | |
String badNumber = "ABC123"; | |
String goodNumber = "423-867-5309"; | |
/** This will NOT be generated because the number fails! */ | |
if(isValidNumber(badNumber)) { | |
System.out.println("You will never see me!"); | |
Pilot badPilot = new Pilot(badNumber); | |
} | |
if(isValidNumber(goodNumber)){ | |
System.out.println("Good Pilot created!"); | |
Pilot goodPilot = new Pilot(goodNumber); | |
System.out.println("\t" + goodPilot); | |
} | |
} | |
private static boolean isValidNumber(String number) { | |
String pattern = "(\\d{3}-)?\\d{3}-\\d{4}"; | |
if (number.matches(pattern)) | |
return true; | |
return false; | |
} | |
public static class Pilot { | |
public Pilot(String phoneNumber) { | |
System.out.println("I am a Pilot class!"); | |
System.out.println("Pilot class received number " + phoneNumber); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment