Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Contribute
Article
Blog
Video
Ebook
Interview Question
.NET
.NET Core
.NET MAUI
.NET Standard
Active Directory
ADO.NET
Agile Development
AI
AJAX
AlbertAGPT
Alchemy
Alexa Skills
Algorand
Algorithms in C#
Android
Angular
ArcObject
ASP.NET
ASP.NET Core
Augmented Reality
Avalanche
AWS
Azure
Backbonejs
Big Data
BizTalk Server
Blazor
Blockchain
Bootstrap
Bot Framework
Business
Business Intelligence(BI)
C#
C# Corner
C# Strings
C, C++, MFC
Career Advice
Careers and Jobs
Chapters
ChatGPT
Cloud
Coding Best Practices
Cognitive Services
COM Interop
Compact Framework
Copilot
Cortana Development
Cosmos DB
Cryptocurrency
Cryptography
Crystal Reports
CSS
Current Affairs
Custom Controls
Cyber Security
Data Mining
Data Science
Databases & DBA
Databricks
Design Patterns & Practices
DevExpress
DevOps
DirectX
Dynamics CRM
Enterprise Development
Entity Framework
Error Zone
Exception Handling
F#
Files, Directory, IO
Flutter
Games Programming
GDI+
General
Generative AI
GO
Google Cloud
Google Development
Graphics Design
Graphite Studio
Hardware
Hiring and Recruitment
HoloLens
How do I
HTML 5
Infragistics
Internet & Web
Internet of Things
Ionic
Java
Java and .NET
JavaScript
JQuery
JSON
JSP
Knockout
Kotlin
Langchain
Leadership
Learn .NET
Learn iOS Programming
LINQ
Machine Learning
Metaverse
Microsoft 365
Microsoft Fabric
Microsoft Office
Microsoft Phone
Microsoft Teams
Mobile Development
MongoDB
MuleSoft
MySQL
NEAR
NetBeans
Networking
NFT
NoCode LowCode
Node.js
Office Development
OOP/OOD
Open Source
Operating Systems
Oracle
Outsourcing
Philosophy
PHP
Polygon
PostgreSQL
Power Apps
Power Automate
Power BI
Power Pages
Printing in C#
Products
Progress
Progressive Web Apps
Project Management
Public Speaking
Python
Q#
QlikView
Quantum Computing
R
React
React Native
Reports using C#
Robotics & Hardware
RPA
Ruby on Rails
RUST
Salesforce
Security
Servers
ServiceNow
SharePoint
Sharp Economy
SignalR
Smart Devices
Snowflake
Software Architecture/Engineering
Software Testing
Solana
Solidity
Sports
SQL
SQL Server
Startups
Stratis Blockchain
Swift
SyncFusion
Threading
Tools
TypeScript
Unity
UWP
Visual Basic .NET
Visual Studio
Vue.js
WCF
Wearables
Web API
Web Design
Web Development
Web3
Windows
Windows Controls
Windows Forms
Windows PowerShell
Windows Services
Workflow Foundation
WPF
Xamarin
XAML
XML
XNA
XSharp
Register
Login
3
Answers
I am creating billing app not sure where I am going wrong
h dave
4y
601
1
Reply
Bill.cs
using
System;
using
System.Collections.Generic;
using
System.Text;
namespace
ConsoleApp2
{
public
class
Bill
{
public
int
BillNumber {
get
;
set
; }
public
DateTime BillDate {
get
;
set
; }
public
List LineItems {
get
;
set
; } =
new
List();
public
void
AddBillLine(BillLine billLine)
{
LineItems.Add(billLine);
}
public
void
RemoveBillLine(
int
SOMEID)
{
throw
new
NotImplementedException();
}
///
/// GetTotal should return the sum of (Cost * Quantity) for each line item
///
public
decimal
GetTotal()
{
throw
new
NotImplementedException();
}
///
/// MergeBill appends the items from the sourceBill to the current bill
///
/// Bill to merge from
public
void
MergeBill(Bill sourceBill)
{
throw
new
NotImplementedException();
}
///
/// Creates a deep clone of the current bill (all fields and properties)
///
public
Bill Clone()
{
throw
new
NotImplementedException();
}
///
/// Outputs string containing the following (replace [] with actual values):
/// Bill Number: [BillNumber], BillDate: [dd/MM/yyyy], LineItemCount: [Number of items in LineItems]
///
public
override
string
ToString()
{
throw
new
NotImplementedException();
}
}
}
BillLine.cs
namespace
ConsoleApp2
{
public
class
BillLine
{
public
int
BillLineId {
get
;
set
; }
public
string
Description {
get
;
set
; }
public
int
Quantity {
get
;
set
; }
public
double
Cost {
get
;
set
; }
}
}
Program.cs
using
System;
using
System.Collections.Generic;
namespace
ConsoleApp2
{
public
class
Program
{
static
void
Main(
string
[] args)
{
Console.WriteLine(
"Billing app started...."
);
CreateBillWithOneItem();
CreateBillWithMultipleItemsAndQuantities();
RemoveItem();
MergeBill();
CloneBill();
BillToString();
}
private
static
void
CreateBillWithOneItem()
{
var bill =
new
Bill();
bill.AddBillLine(
new
BillLine()
{
BillLineId = 1,
Cost = 6.99,
Quantity = 1,
Description =
"Apple"
});
Console.WriteLine(bill.GetTotal());
}
private
static
void
CreateBillWithMultipleItemsAndQuantities()
{
var bill =
new
Bill();
bill.AddBillLine(
new
BillLine()
{
BillLineId = 1,
Cost = 10.21,
Quantity = 4,
Description =
"Banana"
});
bill.AddBillLine(
new
BillLine()
{
BillLineId = 2,
Cost = 5.21,
Quantity = 1,
Description =
"Orange"
});
bill.AddBillLine(
new
BillLine()
{
BillLineId = 3,
Cost = 5.21,
Quantity = 5,
Description =
"Pineapple"
});
Console.WriteLine(bill.GetTotal());
}
private
static
void
RemoveItem()
{
var bill =
new
Bill();
bill.AddBillLine(
new
BillLine()
{
BillLineId = 1,
Cost = 5.21,
Quantity = 1,
Description =
"Orange"
});
bill.AddBillLine(
new
BillLine()
{
BillLineId = 2,
Cost = 10.99,
Quantity = 4,
Description =
"Banana"
});
bill.RemoveBillLine(1);
Console.WriteLine(bill.GetTotal());
}
private
static
void
MergeBill()
{
var bill1 =
new
Bill();
bill1.AddBillLine(
new
BillLine()
{
BillLineId = 1,
Cost = 10.33,
Quantity = 4,
Description =
"Banana"
});
var bill2 =
new
Bill();
bill2.AddBillLine(
new
BillLine()
{
BillLineId = 2,
Cost = 5.22,
Quantity = 1,
Description =
"Orange"
});
bill2.AddBillLine(
new
BillLine()
{
BillLineId = 3,
Cost = 6.27,
Quantity = 3,
Description =
"Blueberries"
});
bill1.MergeBill(bill2);
Console.WriteLine(bill1.GetTotal());
}
private
static
void
CloneBill()
{
var bill =
new
Bill();
bill.AddBillLine(
new
BillLine()
{
BillLineId = 1,
Cost = 6.99,
Quantity = 1,
Description =
"Apple"
});
bill.AddBillLine(
new
BillLine()
{
BillLineId = 2,
Cost = 6.27,
Quantity = 3,
Description =
"Blueberries"
});
var clonedBill = bill.Clone();
Console.WriteLine(clonedBill.GetTotal());
}
private
static
void
BillToString()
{
var bill =
new
Bill()
{
BillDate = DateTime.Now,
BillNumber = 1000,
LineItems =
new
List()
{
new
BillLine()
{
BillLineId = 1,
Cost = 6.99,
Quantity = 1,
Description =
"Apple"
}
}
};
Console.WriteLine(bill.ToString());
}
}
}
Can anyone please help on this I want to know how I can create bill for one item, create bill with multiple items and quantities, remove item, merge bill, clone bill.
Post
Reset
Cancel
Answers (
3
)
Next Recommended Forum
Make a partial loan payments in c# windows application
update multiple rows data in MySQL using c#