← All posts

Java Array Assignment: Same Validation Library, Different Problem

2023Java · CLI

This is the same HelpCode validation library from the grade analyzer attached to a different assignment. Same character-level input checking. Same 346 lines of utility code. The difference is the problem: this one focuses on array manipulation through a menu-driven interface.

The Problem

Create an array with a configurable size between 5 and 5000. Set a range for random values. Populate the array. Display its contents. Compute statistics. The assignment was designed to teach array traversal, bounds, and basic aggregations like sum, average, minimum, maximum, and counting even numbers.

The menu runs in a loop until the user enters negative one to exit. Each option modifies or inspects the array. The structure is straightforward because the problem is straightforward.

The State Problem

The interesting part of this project is not the menu or the array operations. It is the state tracking. Three boolean flags track whether the array is populated, whether the size changed, and whether the range changed. If the user changes the size or range without repopulating, the display function prints a warning instead of showing stale data.

These flags prevent a specific class of bug: showing results that do not match the current configuration. Changing the size to 500 and displaying without repopulating would show the old array with zeros in the new slots. The flags catch that. It is a simple solution to a problem that would be confusing to debug without it.

What I Would Change

The statistics option is incomplete. It prints a placeholder message and does nothing. The average uses integer division, which truncates the decimal. The display function prints 1000 lines of zeros when the array is empty instead of showing a concise message. The console clearing uses ANSI codes that do not work everywhere.

It is a school assignment. It demonstrates arrays, loops, and conditionals. That is what it was supposed to do.

View all projects →View on GitHub ↗