From ee043482412c1e14cbb0e9de764bda2470f0bb83 Mon Sep 17 00:00:00 2001 From: Josh Ashton Date: Wed, 3 Apr 2024 10:48:30 -0600 Subject: [PATCH] leetcode challenge 193. --- spring24/week13/ParsePhone.java | 47 +++++++++++++++++++++++++++++++++ spring24/week13/input.txt | 3 +++ spring24/week13/run.sh | 3 +++ 3 files changed, 53 insertions(+) create mode 100644 spring24/week13/ParsePhone.java create mode 100644 spring24/week13/input.txt create mode 100755 spring24/week13/run.sh diff --git a/spring24/week13/ParsePhone.java b/spring24/week13/ParsePhone.java new file mode 100644 index 0000000..7a321f2 --- /dev/null +++ b/spring24/week13/ParsePhone.java @@ -0,0 +1,47 @@ +import java.io.File; +import java.util.Scanner; + +/** + * This challenge is inspired from LeetCode Problem 193. + * + * Given an input file called "inut.txt" that contains a list of potential + * phone numbers on each line, determine if each line is a valid phone number. + * + * A valid phone number is defined as any sequence of digits that has the + * following characteristics: + * 1. It may contain a '+' at the start of the string, for the international + * dialing code. The '+' is optional. + * + * 2. It may contain a '-' in the string, to separate the country code, area + * code, and local number. The '-' is optional. + * + * 3. It may contain a '(' and ')' in the string, to enclose the area code. + */ +public class ParsePhone { + private static boolean isValidNumber(String number) { + return false; // TODO: Implement this method + } + + public static void main(String[] args) { + File input = new File("input.txt"); + + if(input.exists() == false) { + System.out.println("File not found"); + return; + } + + try { + Scanner sc = new Scanner(input); + + while(sc.hasNextLine()) { + String number = sc.nextLine(); + System.out.println(isValidNumber(number) ? number : "Invalid"); + } + + sc.close(); + + } catch(Exception e) { + e.printStackTrace(); + } + } +} diff --git a/spring24/week13/input.txt b/spring24/week13/input.txt new file mode 100644 index 0000000..ab5499c --- /dev/null +++ b/spring24/week13/input.txt @@ -0,0 +1,3 @@ +987-123-4567 +123 456 7890 +(123) 456-7890 diff --git a/spring24/week13/run.sh b/spring24/week13/run.sh new file mode 100755 index 0000000..dabbb49 --- /dev/null +++ b/spring24/week13/run.sh @@ -0,0 +1,3 @@ +javac *.java +java ParsePhone +rm *.class