Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems For Advanced Applications 27th International Conference Dasfaa 2022 Virtual Event April 11 14 2022 Proceedings Part 2 Lncs 13246

Authors: Arnab Bhattacharya ,Janice Lee Mong Li ,Divyakant Agrawal ,P. Krishna Reddy ,Mukesh Mohania ,Anirban Mondal ,Vikram Goyal ,Rage Uday Kiran

1st Edition

3031001257, 978-3031001253

More Books

Students also viewed these Databases questions

Question

What are the three techniques used to estimate costs?

Answered: 1 week ago