/** * ============================================================ * CS 231 — Data Structures & Algorithms * Lab 1 ver.B: Java Foundations * * IMPORTANT: * - This file is tested using a SEPARATE test harness. * - Do NOT print inside these methods. * - Do NOT read input. * - Do NOT change method names or signatures. * * Each method should be implemented exactly as specified. * * ============================================================ */ public class LabA_v2 { /* ======================================================== * Task 1: Multiple of Three * ======================================================== * * Determine whether a value is evenly divisible by 3. */ public static boolean isMultipleOfThree(int value) { // TODO: Return true if value is divisible by 3 return false; // placeholder } /* ======================================================== * Task 2: Compare Two Numbers * ======================================================== * * Compare two integers. * * Return: * 1 if a > b * 0 if a == b * -1 if a < b */ public static int compare(int a, int b) { // TODO: Compare a and b and return the appropriate value return 0; // placeholder } /* ======================================================== * Task 3: Find Smallest Element in an Array * ======================================================== * * Assume: * values.length >= 1 */ public static int minElement(int[] values) { // TODO: Track and return the smallest value in the array return 0; // placeholder } /* ======================================================== * Task 4: Array Sum * ======================================================== * * Compute the sum of all values in the array. */ public static int arraySum(int[] values) { // TODO: Accumulate and return the sum return 0; // placeholder } /* ======================================================== * Task 5: Return Values in Sorted Order * ======================================================== * * Return the two values in ascending order. * * EXAMPLE: * sortedPair(7, 3) → {3, 7} */ public static int[] sortedPair(int a, int b) { // TODO: Return a two-element array with values in order return null; // placeholder } /* ======================================================== * Task 6: Copy Array with Offset * ======================================================== * * Create a new array that contains all elements of the input * array, but each value increased by offset. * * EXAMPLE: * values = {1, 2, 3}, offset = 5 → {6, 7, 8} */ public static int[] copyWithOffset(int[] values, int offset) { // TODO: Create a new array // TODO: Copy values with offset applied return null; // placeholder } /* ======================================================== * Task 7: Is Digit Character * ======================================================== * * Determine whether a character represents a digit * ('0' through '9') using ASCII values. */ public static boolean isDigitChar(char ch) { // TODO: Check whether ch is between '0' and '9' return false; // placeholder } /* ======================================================== * Task 8: Adjacent Equals * ======================================================== * * Determine whether an array contains the same value * appearing in adjacent positions. * * EXAMPLE: * {1, 2, 2, 3} → true * {1, 2, 3, 2} → false */ public static boolean hasAdjacentEquals(int[] values) { // TODO: Check adjacent elements for equality return false; // placeholder } /* ======================================================== * Task 9: Appears Exactly Once * ======================================================== * * Determine whether a target value appears exactly once * in an array. */ public static boolean appearsOnce(int[] values, int target) { // TODO: Count occurrences and check whether count == 1 return false; // placeholder } /* ======================================================== * Task 10: Strictly Increasing Array * ======================================================== * * Determine whether the values in an array are in * strictly increasing order. */ public static boolean isStrictlyIncreasing(int[] values) { // TODO: Ensure each element is greater than the previous return true; // placeholder } }