From 6246e964db10e8550120d5e5e903aded31f3253c Mon Sep 17 00:00:00 2001 From: Joshua Ashton Date: Tue, 6 Feb 2024 20:56:08 -0700 Subject: [PATCH] Basic challenge setup implemented and commented. --- spring24/week4/.gitignore | 1 + spring24/week4/Challenge.java | 77 +++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 spring24/week4/.gitignore create mode 100644 spring24/week4/Challenge.java diff --git a/spring24/week4/.gitignore b/spring24/week4/.gitignore new file mode 100644 index 0000000..518faed --- /dev/null +++ b/spring24/week4/.gitignore @@ -0,0 +1 @@ +/Challenge.class diff --git a/spring24/week4/Challenge.java b/spring24/week4/Challenge.java new file mode 100644 index 0000000..9473482 --- /dev/null +++ b/spring24/week4/Challenge.java @@ -0,0 +1,77 @@ +package spring24.week4; + +import java.io.File; +import java.io.FileNotFoundException; +import java.util.ArrayList; +import java.util.Scanner; + +public class Challenge { + + + /** + * CHALLENGE 1: + * Read and store the contents of a file into a String array for further processing. + * + * @param f + * @return + */ + public static String[] readFile(File f) { + if(f == null) return null; // Catch if the File does not exist. + + // TODO: Create a variable, potentially an object, to store Strings that are read in from the file. + + try (Scanner s = new Scanner(f)){ + // TODO: Populate the variable from above with Strings from the file. + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + + return null; // TODO: Return the variable. + } + + /** + * CHALLENGE 2: + * Given an input String array, store each token in an ArrayList. + * + * A token is a single word, symbol, or character, surrounded on both sides by a space. + * + * @param s + * @return + */ + public static ArrayList split(String[] s) { + ArrayList list = new ArrayList(); + + // TODO: Take the input String array s and add each separate word (separated by a space) to the ArrayList. + + return list; + } + + /** + * CHALLENGE 3: + * Given an input ArrayList of tokens (assume all are valid integers, doubles, or operations ('+','-','*','/','%','(', and ')')), + * calculate the result using correct order of operations. + * + * HINT: Think of a data structure that might be useful for this. + * + * @param tokens + */ + public static double calculate(ArrayList tokens) { + return 0.0; // TODO: Implement this method. + } + + public static boolean testChallenge1(String[] s) { + return false; // TODO + } + + public static boolean testChallenge2(ArrayList list) { + return false; // TODO + } + + public static boolean testChallenge3(double result) { + return false; // TODO + } + + public static void main(String[] args) { + + } +} \ No newline at end of file