Skip to content

Week 2 day 5#5

Open
Ngozistephen wants to merge 2 commits intoBloceducare:mainfrom
Ngozistephen:week-2-day-5
Open

Week 2 day 5#5
Ngozistephen wants to merge 2 commits intoBloceducare:mainfrom
Ngozistephen:week-2-day-5

Conversation

@Ngozistephen
Copy link

@Ngozistephen Ngozistephen commented Feb 9, 2026

Task Submission PR

Student Info:

  • Registered Name: Ngozi Stephen
  • Week: <2>
  • Day: <5>

Task Details:

  • Task Name: Expence Tracker
  • Task Description: Briefly describe the task completed.

Checklist Before Submitting:

  • [ yes] My code follows the repository folder structure.
  • [ yes] I have properly named my files and folders.
  • [ yes] I have documented my code where necessary.
  • [ yes ] I have tested my solution and ensured it works as expected.

Additional Comments:

If any, mention here.

Copilot AI review requested due to automatic review settings February 9, 2026 09:43
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a Rust-based CLI “Expense Tracker” submission under submissions/week-2/day-5, including the core data model, tracker logic, and a sample saved output file.

Changes:

  • Introduces a CLI menu to add/view/update/delete expenses and save them to a text file on exit.
  • Implements an ExpenseTracker backed by a HashMap plus Expense / TransactionType types.
  • Adds Rust project scaffolding (Cargo.toml, Cargo.lock, .gitignore) and a sample stephen_expences.txt.

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 19 comments.

Show a summary per file
File Description
submissions/week-2/day-5/Stephen-Ngozi-Merkle-Tree/src/main.rs CLI menu, input parsing, and calling tracker operations + save-on-quit
submissions/week-2/day-5/Stephen-Ngozi-Merkle-Tree/src/tracker.rs Core CRUD logic and file persistence
submissions/week-2/day-5/Stephen-Ngozi-Merkle-Tree/src/expense.rs Expense and transaction type definitions
submissions/week-2/day-5/Stephen-Ngozi-Merkle-Tree/Cargo.toml Rust package configuration
submissions/week-2/day-5/Stephen-Ngozi-Merkle-Tree/Cargo.lock Cargo lockfile
submissions/week-2/day-5/Stephen-Ngozi-Merkle-Tree/.gitignore Ignores /target
submissions/week-2/day-5/Stephen-Ngozi-Merkle-Tree/stephen_expences.txt Sample persisted expense output

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +39 to +40
tracker.save_to_file("stephen_expences.txt");
println!("Data saved to stephen_expences.txt");
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The filename "stephen_expences.txt" contains a spelling error ("expences"). Consider renaming to "stephen_expenses.txt" (and updating the checked-in file name) to avoid confusion.

Suggested change
tracker.save_to_file("stephen_expences.txt");
println!("Data saved to stephen_expences.txt");
tracker.save_to_file("stephen_expenses.txt");
println!("Data saved to stephen_expenses.txt");

Copilot uses AI. Check for mistakes.
Comment on lines +78 to +80
println!("ID: {} | Name: {} | Amount: Naria{:.2} | Type: {:?}",
expense.id, expense.name, expense.amount, expense.tx_type);
}
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Naria" appears to be a misspelling of the currency name "Naira". Fixing the string will make output clearer.

Copilot uses AI. Check for mistakes.
Comment on lines +83 to +84
println!("Enter the ID of the Expence");

Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prompt text uses "Expence" instead of "Expense".

Copilot uses AI. Check for mistakes.
Comment on lines +19 to +22
pub struct ExpenseTracker {
pub values: HashMap<u8, Expense>,
pub next_id: u8,
}
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using u8 for IDs means next_id will overflow after 255 expenses (panic in debug builds, wrap in release), which can lead to duplicate IDs and lost data. Use a larger type (e.g., u32/u64/usize) and/or handle overflow explicitly.

Copilot uses AI. Check for mistakes.
Comment on lines +1 to +4
[package]
name = "Stephen-Ngozi-Merkle-Tree"
version = "0.1.0"
edition = "2024"
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The submission is described as an Expense Tracker, but the crate/package name is "Stephen-Ngozi-Merkle-Tree", which is confusing and suggests a different project. Consider renaming the package (and folder) to match the task (e.g., expense_tracker) to avoid confusion when building/running multiple submissions.

Copilot uses AI. Check for mistakes.
Comment on lines +98 to +105
let mut tx_input = String::new();
io::stdin().read_line(&mut tx_input).expect("Failed to read input");
let tx_input = tx_input.trim();

let tx_type = if tx_input == "c" {
TransactionType::Credit
} else {
TransactionType::Debit
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the update flow, any transaction type input other than "c" becomes Debit, which can record the wrong transaction type. Add validation/re-prompt for "c" or "d" (case-insensitive).

Suggested change
let mut tx_input = String::new();
io::stdin().read_line(&mut tx_input).expect("Failed to read input");
let tx_input = tx_input.trim();
let tx_type = if tx_input == "c" {
TransactionType::Credit
} else {
TransactionType::Debit
let tx_type = loop {
let mut tx_input = String::new();
io::stdin().read_line(&mut tx_input).expect("Failed to read input");
let tx_input = tx_input.trim().to_lowercase();
match tx_input.as_str() {
"c" => break TransactionType::Credit,
"d" => break TransactionType::Debit,
_ => {
println!("Invalid transaction type. Please enter 'c' for Credit or 'd' for Debit:");
}
}

Copilot uses AI. Check for mistakes.
let id: u8 = id_input.trim().parse().expect("Please enter a valid ID");

if tracker.delete(id){
println!(" Your Expence is Deleted ");
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete confirmation message uses "Expence" instead of "Expense".

Suggested change
println!(" Your Expence is Deleted ");
println!(" Your Expense is Deleted ");

Copilot uses AI. Check for mistakes.
Comment on lines +19 to +22
pub struct ExpenseTracker {
pub values: HashMap<u8, Expense>,
pub next_id: u8,
}
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

values and next_id are public, which exposes internal state (and allows callers to mutate/replace entries without invariants). Prefer keeping fields private and providing methods like get(id)/iter() for read access.

Copilot uses AI. Check for mistakes.
Comment on lines +108 to +112
if tracker.update(id, amount, tx_type){
println!("Expense Updated Successfu");

if let Some(expense) = tracker.values.get(&id) {
println!("ID: {}, Name: {}, Amount: Naria{:.2}, Type: {:?}",
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If tracker.update(...) returns false (ID not found), the program prints nothing and returns to the menu. Add an else branch to inform the user that the ID was not found.

Copilot uses AI. Check for mistakes.
@@ -0,0 +1,84 @@
use std::{collections::HashMap,fs::File,io::Write};
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The import list is missing standard spacing after commas (HashMap,fs::File,io::Write), which will fail rustfmt/linting if enabled. Run cargo fmt or fix spacing.

Suggested change
use std::{collections::HashMap,fs::File,io::Write};
use std::{collections::HashMap, fs::File, io::Write};

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants