Skip to content

Instantly share code, notes, and snippets.

@cbmeeks
Created March 2, 2022 16:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cbmeeks/1333737d36064b309f7b233498194a43 to your computer and use it in GitHub Desktop.
Save cbmeeks/1333737d36064b309f7b233498194a43 to your computer and use it in GitHub Desktop.
Pilot Example
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