0.4 First Day Assignment

Overview

Memory and Persistent Storage

In 0.3, the First Day application used information while it was running to make a clothing decision. In this assignment, you will explore what happens when information needs to remain available after the application closes.

You will add a small school shopping list, observe its text while the application is running, save the same text to a file, close the application, and then reopen the application so the saved list can be restored. Most of the file code is provided. Your job is to place it correctly, trace the information, and explain where the information exists at each point.

User Story

As a student preparing for the first day of class, I want my school shopping list saved outside the running application so that the information remains available after I close and reopen the program.

Acceptance Criteria

Task List

  1. Get Started From Your 0.3 Solution
  2. Read the First Day Class Diagram
  3. Add the Shopping-List Controls
  4. Observe Information While the Program Is Running
  5. Save the Shopping List to a Text File
  6. Read the Shopping List Back When the Program Opens
  7. Final Check and Submit
The Goal Is the Information Flow

You are not expected to design a file-storage system. The file-reading and file-writing statements are supplied so you can focus on the difference between information in a running application and information stored persistently.

  1. 1. Back Up and Open Your Existing First Day Solution

    Your First Day solution was renamed to your last name in 0.2. Keep that working name for the rest of the sequence. At the beginning of each module, make a backup of the completed previous checkpoint, then continue working in the original student-named solution.

    Step 1 — Make a checkpoint backup

    One Working Name

    The backup identifies the completed checkpoint. The working solution remains named for you, so later First Day assignments continue in the same project without repeatedly renaming the solution.

    Step 2 — Verify the previous checkpoint

    1. Build or run the solution before making the new 0.4 changes
    2. Verify the major behavior you completed in 0.3 is still present
    3. If the previous checkpoint is not working, correct that starting state before adding the new module work
    Go to top
  2. 2. Read the First Day Class Diagram

    Module 0.2 used object diagrams to represent particular objects and their values. Module 0.3 used activity diagrams to represent what happens next. A class diagram answers a different question: What information can this kind of object hold, and how are the types related?

    Step 1 — Compare classes and data types

    The class diagram below summarizes several classes already present in your First Day project. Scalar information appears inside the class with its data type. Relationships to other classes are shown as labeled arrows.

    UML class diagram showing Student with EnergyLevel double, FirstName string, Id int, IsHungry bool, and LastName string; Backpack with Weight double; Book with string, decimal, int, and double attributes; Laptop with Manufacturer string and Weight double; Breakfast with EnergyLevel double and Name string. Student relates to Backpack, and Backpack relates to Book and Laptop.
    Existing First Day classes provide examples of several basic data types and class relationships.

    Step 2 — Find examples of different data types

    1. Find one string attribute
    2. Find one int attribute
    3. Find one double attribute
    4. Find one bool attribute
    5. Find one decimal attribute
    Class Diagram vs. Object Diagram

    A class diagram describes reusable structure. It does not say that one particular Student currently has a particular name or ID. Those specific runtime values belong to an object diagram or debugger observation.

    Check Your Work

    You should be able to explain why IsHungry : bool represents a true/false kind of value while FirstName : string represents text. You do not need to change these classes in this assignment.

    Go to top
  3. 3. Add the Shopping-List Controls

    The next part of the application needs a place where you can enter several lines of text and a button that saves that text. The new controls are supplied so the focus stays on the information, not on designing the interface.

    Step 1 — Open MainWindow.xaml

    1. Open FirstDayScenario/MainWindow.xaml
    2. Keep the existing 0.3 StackPanel and controls unchanged
    3. Locate the space between the first StackPanel and the existing textOutput TextBox
    Screenshot placeholder showing where the School Shopping List controls belong in MainWindow.xaml
    Add the shopping-list section below the existing 0.3 controls.

    Step 2 — Make room for the shopping-list section

    Increase the Window height.

    MainWindow.xaml — update the Window height
    <Window x:Class="FirstDayScenario.MainWindow" ... Title="MainWindow" Height="720" Width="400">

    Step 3 — Add the supplied shopping-list controls

    Place this new StackPanel after the existing 0.3 StackPanel and before textOutput.

    MainWindow.xaml — add this StackPanel
    <StackPanel HorizontalAlignment="Center" Height="245" Margin="0,215,0,0" VerticalAlignment="Top" Width="300">
        <TextBlock Text="School Shopping List" FontWeight="Bold" Margin="5" />
        <TextBox x:Name="shoppingListTextBox" Height="160" Margin="5" AcceptsReturn="True" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto" />
        <Button x:Name="saveShoppingListButton" Content="Save Shopping List" Margin="5" Click="SaveShoppingListButton_Click" />
    </StackPanel>

    Replace the existing textOutput line with the version below so the output area appears below the shopping list.

    MainWindow.xaml — replace the textOutput line
    <TextBox x:Name="textOutput" HorizontalAlignment="Center" Height="170" Margin="0,480,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="300" BorderThickness="3" BorderBrush="#FFB3B3B4" />

    Check Your Work

    1. Build the solution
    2. Run the application
    3. Verify the existing 0.3 controls still appear
    4. Verify the new School Shopping List text area and Save Shopping List button appear
    5. Type several simple items such as Notebook, Pens, and USB cable, one per line
    Screenshot placeholder showing the First Day application with a multiline school shopping list and Save Shopping List button
    The new text area gives the running application a value you can observe and later save.
    Go to top
  4. 4. Observe Information While the Program Is Running

    Before saving anything, notice where the shopping-list information exists. You typed the text into a control in a running application. At this moment, the program can use the value, but you have not yet demonstrated that it will survive after the program stops.

    Step 1 — Add the file namespace

    Open MainWindow.xaml.cs. Add the following line with the other using statements near the top of the file.

    MainWindow.xaml.cs — add with the using statements
    using System.IO;

    Step 2 — Add the supplied Save handler

    Scroll to the bottom of the MainWindow class. Add the following event handler after the existing event handlers and before the closing brace of MainWindow.

    MainWindow.xaml.cs — add this event handler
    /// <summary>
    /// Saves the school shopping list to a text file.
    /// </summary>
    /// <param name="sender">The object that initiated the event.</param>
    /// <param name="e">The event arguments for the event.</param>
    private void SaveShoppingListButton_Click(object sender, RoutedEventArgs e)
    {
        File.WriteAllText("ShoppingList.txt", this.shoppingListTextBox.Text);
        this.textOutput.Text = "Shopping list saved.";
    }

    Step 3 — Pause before the file is written

    1. Set a breakpoint on the File.WriteAllText line
    2. Run the application
    3. Enter several shopping-list items
    4. Click Save Shopping List
    5. When Visual Studio pauses, inspect this.shoppingListTextBox.Text
    Screenshot placeholder showing Visual Studio paused before File.WriteAllText while the shopping list text is visible in the debugger
    Before the write occurs, the shopping-list text is information being used by the running application.
    Activity diagram showing a student entering shopping-list text, the text existing in the running application, pausing before save, inspecting the value, writing it to ShoppingList.txt, closing the application, opening the text file, and finding the saved text still available.
    Trace the same information from the running application into persistent storage.
    Where Is the Information Now?

    At the breakpoint, the shopping-list text is available to the running application. The next statement will copy that information into a text file. The purpose of the breakpoint is to observe the state immediately before that change in location.

    Go to top
  5. 5. Save the Shopping List to a Text File

    The supplied File.WriteAllText statement takes the current shopping-list text and writes it to a file named ShoppingList.txt. You are using the operation, not designing a file API.

    Step 1 — Complete the save

    1. At the breakpoint, verify the shopping-list text contains the items you entered
    2. Press F10 to execute the File.WriteAllText statement
    3. Continue the application
    4. Verify the output area says Shopping list saved.

    Step 2 — Find and inspect ShoppingList.txt

    1. Use File Explorer to search within your 0.4 solution folder for ShoppingList.txt
    2. Open the text file
    3. Compare the file contents with the shopping list in the running application
    Screenshot placeholder showing ShoppingList.txt in File Explorer and its saved shopping-list text
    The text file is a persistent representation of the information that was in the running application.

    Step 3 — Prove the information persists

    1. Stop debugging and close the First Day application
    2. Open ShoppingList.txt again
    3. Verify the saved items are still present even though the application is no longer running
    Persistence

    The application stopped, but the file remained. That is the important difference between information that exists only while a program is running and information that has been written to persistent storage.

    Go to top
  6. 6. Read the Shopping List Back When the Program Opens

    Saving proves the file survives. Reading the file when the application opens shows why persistent storage is useful: information from an earlier run can become part of a later run.

    Step 1 — Add the supplied startup read-back code

    Open MainWindow.xaml.cs and locate the MainWindow constructor. Place the following block immediately after this.InitializeComponent();.

    Screenshot placeholder showing the MainWindow constructor and the insertion point immediately after InitializeComponent
    The read-back check belongs after the window controls have been initialized.
    MainWindow constructor — add after InitializeComponent
    if (File.Exists("ShoppingList.txt"))
    {
        this.shoppingListTextBox.Text = File.ReadAllText("ShoppingList.txt");
    }

    Step 2 — Read the flow before running it

    The activity diagram shows both possible startup paths. If the file exists, the application reads it. If the file does not exist, the shopping list simply begins empty.

    Activity diagram: application starts; if ShoppingList.txt exists, read text from the file and display the saved shopping list; otherwise start with an empty shopping list; the student edits the list, chooses Save Shopping List, and the application writes the text to ShoppingList.txt.
    Startup read-back and save flow for the 0.4 First Day application.

    Step 3 — Trace the read-back path

    1. Make sure the ShoppingList.txt file you created earlier still exists
    2. Set a breakpoint on if (File.Exists("ShoppingList.txt"))
    3. Start the application
    4. When the constructor pauses, predict whether the if block should run
    5. Use F10 to step through the file check and the File.ReadAllText statement
    6. Continue running the application

    Check Your Work

    1. The shopping-list items saved during the earlier run should appear again
    2. You should not need to retype those items
    3. The restored text should match the contents of ShoppingList.txt
    Screenshot placeholder showing the First Day application reopened with the previously saved shopping list restored
    The new run of the application restores information that was saved by the earlier run.

    Step 4 — Observe the no-file path

    1. Close the application
    2. Temporarily rename ShoppingList.txt to ShoppingList-old.txt
    3. Start the application again
    4. Verify the shopping-list area starts empty because ShoppingList.txt does not exist
    5. Close the application and rename the file back to ShoppingList.txt
    What Changed Between Runs?

    The program code stayed the same. The external file state changed. The File.Exists decision lets the application respond appropriately to either condition.

    Go to top
  7. 7. Final Check and Submit

    Verify the complete 0.4 checkpoint before packaging the solution.

    Step 1 — Complete the final technical check

    Step 2 — Zip the solution

    1. Close Visual Studio
    2. Locate the LastName parent folder that contains the .sln file and project folder
    3. Create a ZIP file of the entire solution folder
    4. Open the ZIP and confirm the solution file and FirstDayScenario project folder are present

    Step 3 — Submit to the Feedback System

    1. Open the Feedback System
    2. Select the correct First Day 0.4 assignment
    3. Upload the zipped Visual Studio solution
    4. Review the Feedback System results and correct any in-scope issues if required
    5. Resubmit a corrected ZIP when needed

    Step 4 — Submit the Feedback System URL to Canvas

    1. After the required Feedback System submission is ready, copy its URL
    2. Open the correct 0.4 First Day Assignment in Canvas
    3. Submit the Feedback System URL as your Canvas submission
    Checkpoint Summary

    You observed text while it existed in a running application, wrote the text to persistent storage, proved the file remained after the application closed, and restored the saved information during a later run. You also used a UML class diagram to recognize the data types and structural relationships already represented in the First Day project.

    © 2026 Northcentral Technical College

    Go to top