Question: Need help implementing a database.cs that will store the info for the code below and another database.cs that will perform operations Create, Read, Update, Delete

Need help implementing a database.cs that will store the info for the code below and another database.cs that will perform operations Create, Read, Update, Delete operations on an SQLite database. public class Category
{
public string Name { get; set; }
public Category(string name)
{
Name = name;
}
public string GetName()
{
return Name;
}
}
public class Expense
{
public int Id { get; set; }
public double Amount { get; set; }
public string Description { get; set; }
public Category Category { get; set; }
public DateTime Date { get; set; }
public Expense(int id, double amount, string description, Category category, DateTime date)
{
Id = id;
Amount = amount;
Description = description;
Category = category;
Date = date;
}
public double GetAmount()
{
return Amount;
}
public string GetDescription()
{
return Description;
}
public Category GetCategory()
{
return Category;
}
public DateTime GetDate()
{
return Date;
}
}
using System;
using System.Collections.Generic;
public class ExpenseTracker
{
public List Expenses { get; }= new List();
public void AddExpense(Expense expense)
{
Expenses.Add(expense);
}
public void RemoveExpense(Expense expense)
{
Expenses.Remove(expense);
}
public List GetExpensesByCategory(Category category)
{
return Expenses.FindAll(expense => expense.Category == category);
}
public double GetTotalSpending()
{
double totalSpending =0;
foreach (var expense in Expenses)
{
totalSpending += expense.Amount;
}
return totalSpending;
}
public double GetSpendingByCategory(Category category)
{
double spendingByCategory =0;
foreach (var expense in Expenses)
{
if (expense.Category == category)
{
spendingByCategory += expense.Amount;
}
}
return spendingByCategory;
}
}
using System;
using System.Collections.Generic;
namespace ExpenseTrackerApp
{
class Program
{
static void Main(string[] args)
{
// Create an instance of ExpenseTracker
ExpenseTracker expenseTracker = new ExpenseTracker();
// Add some sample expenses
expenseTracker.AddExpense(new Expense(1,45.50, "Groceries", new Category("Food"), DateTime.Now));
expenseTracker.AddExpense(new Expense(2,25.00, "Movie tickets", new Category("Entertainment"), DateTime.Now.AddDays(-2)));
expenseTracker.AddExpense(new Expense(3,100.00, "Car repair", new Category("Transportation"), DateTime.Now.AddDays(-5)));
// Print the total spending
Console.WriteLine("Total spending: {0:C}", expenseTracker.GetTotalSpending());
// Print expenses by category
Console.WriteLine("
Expenses by category:");
foreach (var category in expenseTracker.Expenses.Select(e => e.Category).Distinct())
{
Console.WriteLine($"-{category.GetName()}: {expenseTracker.GetSpendingByCategory(category):C}");
}
// Demonstrate other methods as needed (e.g., adding/removing expenses, getting expenses by category)
Console.ReadLine(); // Keep the console open
}
}
}
public class User
{
public int Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public User(int id, string name, string email)
{
Id = id;
Name = name;
Email = email;
}
public int GetId()
{
return Id;
}
public string GetName()
{
return Name;
}
public string GetEmail()
{
return Email;
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!