• 0

Restaurant Cash Register


Question

I have a code and a dll that i made.

It's a windows application of a Restaurant Cash Register

The selected items from each category (listBox1 and listBox3) are copied on listBox2. How can i sum the items on listBox2 and make it display it on the textBox1 below?

Thanks,

****************

This is my DLL:

using System;

namespace ClassLibrary1
{
/// <summary>
/// Food class that holds the name and the price of a single food item.
/// Regular Menu class and Kid Menu Class that inherits from the Food class.
/// Choices class which contain an array of Regular Menu and/or Kid Menu objects.
/// </summary>

// parent class
public class Food
{ // starts class food

public string name;
public double price;

public Food() // default constructor - initializes name and price to its lowest values.
{
name = " ";
price = 0.00;
}

public Food( string iName, double iPrice) // constructor takes two arguments of type string & double
{
name = iName;
price = iPrice;
}

public string iName // functions set and get for iName
{
get
{
return name;
}
set
{
name = value;
}
}

public double iPrice // functions set and get for iPrice
{
get
{
return price;
}
set
{
price = value;
}
}

} //ends class Food

public class RegularMenu : Food // starts class RegularMenu which inherits from class Food
{

public RegularMenu(string iName, double iPrice) // constructor takes two arguments of type string & double
{
name = iName;
price = iPrice;
}

} // ends class RegularMenu


public class KidMenu : Food // starts class KidMeni which inherits from class Food
{
public KidMenu(string iName, double iPrice) // constructor takes two arguments of type string & double
{
name= iName;
price = iPrice;

}

} // ends class KidMenu


public class Selection // starts class Selection
{
// arrays of objects of RegularMenu and KidMenu
private RegularMenu[] rmenu = new RegularMenu[50];
private KidMenu[] kmenu = new KidMenu[50];

private int sizeRegmenu =0;
private int sizeKidmenu =0;

public int sizereg // get/set functions
{
get
{
return sizeRegmenu;
}
}

public int sizekid
{
get
{
return sizeKidmenu;
}
}


public Selection()
{
rmenu[0]= new RegularMenu("pizza slice", 2.50);
rmenu[1]= new RegularMenu("hamburguer", 1.75);
rmenu[2]= new RegularMenu("salad", 1.90);
rmenu[3]= new RegularMenu("large soda", 1.20);
rmenu[4]= new RegularMenu("medium soda", 0.90);

sizeRegmenu = 5;

kmenu[0]=new KidMenu("hot dog", 1.50);
kmenu[1]= new KidMenu("small soda", 0.60);
kmenu[2]= new KidMenu("cookie", 0.86);

sizeKidmenu =3;

}

public void add_rmenu( RegularMenu m)
{
rmenu[++ sizeRegmenu] = m;
}

public void add_kid(KidMenu m)
{
kid[++sizeKidmenu] = m;
}


}

}

------------------------

This is the code right now but it gives me some errors. I think i should put the class Selections (That's on the DLL) on the code, but im not sure and i did it and it still gave me some errors.. Can someone help me?:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using ClassLibrary3; // dll created

namespace WindowsApplication1
{
/// <summary>
/// Program that will allow to pick several items from two different menus; RegularMenu
/// and KidMenu and will prepare a Custom Order for the customer.
/// At the end, it will display the total to be paid.
/// It will also allow the user to clear the form and/or click the Quit button and decide
/// what to do with the order.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.ListBox listBox1;
private System.Windows.Forms.ListBox listBox2;
private System.Windows.Forms.ListBox listBox3;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.PictureBox pictureBox1;
private System.ComponentModel.IContainer components;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.label7 = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.button4 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button1 = new System.Windows.Forms.Button();
this.label3 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.listBox3 = new System.Windows.Forms.ListBox();
this.listBox2 = new System.Windows.Forms.ListBox();
this.listBox1 = new System.Windows.Forms.ListBox();
this.label5 = new System.Windows.Forms.Label();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.Add(this.label7);
this.groupBox1.Controls.Add(this.label6);
this.groupBox1.Controls.Add(this.textBox1);
this.groupBox1.Controls.Add(this.label4);
this.groupBox1.Controls.Add(this.button4);
this.groupBox1.Controls.Add(this.button3);
this.groupBox1.Controls.Add(this.button2);
this.groupBox1.Controls.Add(this.button1);
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Controls.Add(this.listBox3);
this.groupBox1.Controls.Add(this.listBox2);
this.groupBox1.Controls.Add(this.listBox1);
this.groupBox1.Location = new System.Drawing.Point(16, 104);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(632, 312);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
//
// label7
//
this.label7.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label7.Location = new System.Drawing.Point(272, 288);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(88, 16);
this.label7.TabIndex = 13;
this.label7.Text = "Staff: Mar-Iam ";
//
// label6
//
this.label6.BackColor = System.Drawing.SystemColors.Window;
this.label6.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label6.ImageAlign = System.Drawing.ContentAlignment.TopLeft;
this.label6.Location = new System.Drawing.Point(256, 72);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(104, 16);
this.label6.TabIndex = 12;
this.label6.Text = "Description Price";
this.label6.TextAlign = System.Drawing.ContentAlignment.TopCenter;
//
// textBox1
//
this.textBox1.BackColor = System.Drawing.SystemColors.Control;
this.textBox1.Location = new System.Drawing.Point(536, 264);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(80, 20);
this.textBox1.TabIndex = 11;
this.textBox1.Text = "";
//
// label4
//
this.label4.Location = new System.Drawing.Point(472, 264);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(56, 23);
this.label4.TabIndex = 10;
this.label4.Text = "Total:";
//
// button4
//
this.button4.Location = new System.Drawing.Point(112, 264);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(64, 24);
this.button4.TabIndex = 9;
this.button4.Text = "Quit";
this.button4.Click += new System.EventHandler(this.button4_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(24, 264);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(64, 24);
this.button3.TabIndex = 8;
this.button3.Text = "Clear";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(400, 120);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(56, 24);
this.button2.TabIndex = 7;
this.button2.Text = "<<";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button1
//
this.button1.Location = new System.Drawing.Point(168, 120);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(56, 24);
this.button1.TabIndex = 6;
this.button1.Text = ">>";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// label3
//
this.label3.Font = new System.Drawing.Font("Eras Light ITC", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label3.Location = new System.Drawing.Point(480, 24);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(136, 23);
this.label3.TabIndex = 5;
this.label3.Text = "Kids Menu";
this.label3.TextAlign = System.Drawing.ContentAlignment.TopCenter;
//
// label2
//
this.label2.Font = new System.Drawing.Font("Eras Light ITC", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label2.Location = new System.Drawing.Point(248, 24);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(136, 23);
this.label2.TabIndex = 4;
this.label2.Text = "Custom Order";
this.label2.TextAlign = System.Drawing.ContentAlignment.TopCenter;
//
// label1
//
this.label1.Font = new System.Drawing.Font("Eras Light ITC", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label1.Location = new System.Drawing.Point(24, 24);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(128, 23);
this.label1.TabIndex = 3;
this.label1.Text = "Regular Menu";
this.label1.TextAlign = System.Drawing.ContentAlignment.TopCenter;
//
// listBox3
//
this.listBox3.Items.AddRange(new object[] {
"hot dog ($1.50)",
"small soda ($0.60)",
"cookie ($0.86)"});
this.listBox3.Location = new System.Drawing.Point(480, 64);
this.listBox3.Name = "listBox3";
this.listBox3.Size = new System.Drawing.Size(136, 160);
this.listBox3.TabIndex = 2;
//
// listBox2
//
this.listBox2.Items.AddRange(new object[] {
"",
"",
""});
this.listBox2.Location = new System.Drawing.Point(248, 64);
this.listBox2.Name = "listBox2";
this.listBox2.Size = new System.Drawing.Size(136, 160);
this.listBox2.TabIndex = 1;
//
// listBox1
//
this.listBox1.Items.AddRange(new object[] {
"pizza slice ($2.50)",
"burger ($1.75)",
"salad ($1.90)",
"large soda ($1.20)",
"medium soda ($0.90)"});
this.listBox1.Location = new System.Drawing.Point(16, 64);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(136, 160);
this.listBox1.TabIndex = 0;
//
// label5
//
this.label5.Font = new System.Drawing.Font("Edwardian Script ITC", 26.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label5.Location = new System.Drawing.Point(176, 8);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(344, 48);
this.label5.TabIndex = 1;
this.label5.Text = "Restaurant Cash Register";
this.label5.TextAlign = System.Drawing.ContentAlignment.TopCenter;
//
// pictureBox1
//
this.pictureBox1.Location = new System.Drawing.Point(264, 56);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(200, 40);
this.pictureBox1.TabIndex = 2;
this.pictureBox1.TabStop = false;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(664, 430);
this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.label5);
this.Controls.Add(this.groupBox1);
this.Name = "Form1";
this.Text = "Form1";
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

// >> add button from Regular Menu
private void button1_Click(object sender, System.EventArgs e)
{
listBox2.Items.Add (listBox1.SelectedItem);
double total = 0.00;

for (int r=0; r<5; r++)
{
if (listBox1.SelectedItems.Equals(RegularMenu[r].getName()))
{
total += RegularMenu[r].getPrice();
textBox1.Text = String.Format("${0:0.00}", total);
}
} // ends for loop
}

// << add button from Kids Menu
private void button2_Click(object sender, System.EventArgs e)
{
listBox2.Items.Add (listBox3.SelectedItem);
double total = 0.00;

for (int r=0; r<3; r++)
{
if (listBox1.SelectedItems.Equals(KidMenu[r].getName()))
{
total += KidMenu[r].getPrice();
textBox1.Text = String.Format("${0:0.00}", total);
}
}
}


// clears all selected items from the Custom Menu
private void button3_Click(object sender, System.EventArgs e)
{
listBox2.Items.Clear();
}

// quit
private void button4_Click(object sender, System.EventArgs e)
{
DialogResult res = MessageBox.Show("Are you sure you want to quit your order?", "Quit Order",
MessageBoxButtons.YesNo,MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
switch (res)
{
case DialogResult.Yes:
// application will exit
listBox2.Items.Clear();
textBox1.Clear();
break;

case DialogResult.No:
// will return to the main application
return;

}

}
/* WHAT I TRIED AT FIRST TO CALCULATE THE SUM
*
public int getPrice( ListBox aList )
{

int startIndex = 0;
int endIndex = 0;
string subString;

startIndex = aList.Text.LastIndexOf("$"); // give me the index at char "$"
endIndex = aList.Text.LastIndexOf("]"); // give me the index at char "]"

subString = aList.Text.Substring(startIndex + 1, (endIndex - 1) - startIndex);

return Convert.ToInt16(subString);
}


public void calculatePrice()
{ // begins calculatePrice

//listBox2.Items.Add (listBox3.SelectedItem);
double totalPrice = 0.00;

totalPrice += getPrice(listBox2);

textBox1.Text = totalPrice.ToString();

} // end calculatePrice

*/




}

}

Edited by marie
Link to comment
https://www.neowin.net/forum/topic/387388-restaurant-cash-register/
Share on other sites

3 answers to this question

Recommended Posts

  • 0

create a new class for the item so you can have it as an object, then override the to string to display the text as you want it... but to sum it go through each object in the one you want to sum call its price and add that up

this is VB.NET code

Public Class FoodItem

private name as string = string.empty

private price as decimal = 0d

public sub new(byval ItemName as string, byval Price as decimal)

price = Price

name = ItemName

end sub

Public Function Overrides ToString() as string

' this will be displayed when added to items collection of list box

return ItemName & " " & price

end function

public property Price as decimal

get

return price

end get

end property

end class

then make a new object for each item of that class type

me.listbox1.add(new FoodItem("Hamburger","1.99")

me.listbox1.add(new FoodItem("Cheeseburger","2.30")

to sum it

dim totalPrice as decimal = 0d

for each FoodItem in me.listbox1.items

totalPrice += FoodItem.price

next

that is VB.NET code, but C# is the same way just change the syntax

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Glad these prices are starting to come down, but that is still crazy. I bought the 2TB 9100 Pro (slightly more expensive version with PCIe 5.0) last year for $240.
    • The 2TB Samsung 990 PRO NVMe SSD hits lowest price in over three months by Sayan Sen Yesterday, we covered a really good deal wherein you can get a 4TB TeamGroup T-FORCE G50 NVMe PCIe Gen4 SSD for a low price of just $400 with a special discount coupon. That's just $100 per TB, making it a very good offer during these hard times. The deal is still live, so you can check it out in its dedicated article here if you do not want to miss out. Meanwhile, if you don't have that kind of budget but still wish to buy an SSD for a good price, the 2TB variant of the TeamGroup SSD at $280 its lowest price in over three months. Meanwhile, those seeking 2TB but faster performance can check out Samsung's 990 PRO, which has hit the lowest price also in the last quarter or so, as it's on sale for $370 (purchase links under the specs table down below). Thus, you want a faster drive, get the 990 Pro, or you want more capacity, grab the TeamGroup 4TB linked in the first para. The 990 PRO is a PCIe Gen4 NVMe SSD and still one of the fastest drives available today for under $500. Speaking of fast, sequential reads and writes are rated at 7450 MB/s and 6900 MB/s, respectively. The random throughputs for reads and writes are 1400K IOPS and 1550K IOPS, respectively. The 990 PRO is based on Samsung's 7th Gen V-NAND flash, and it too is TLC. It packs 2 gigs of LPDDR4 DRAM cache, which helps the random performance. The endurance rating for this is 1200 TBW (terabytes written), which should be sufficient for most users. The Samsung 990 PRO is compatible with the PlayStation 5, but if you are going to use the 990 PRO on a PC, check out the Samsung Magician app that lets you track your drive's health, update its firmware, customize various settings, and more. The tech specs are given below: Specification TeamGroup T-FORCE G50 2TB Samsung 990 PRO 2TB Interface PCIe 4.0 x4, NVMe 1.4 PCIe Gen 4.0 x4, NVMe 2.0 Form Factor M.2 2280 M.2 2280 Controller InnoGrit Controller Samsung In-house Controller NAND Flash 3D TLC 3D TLC DRAM Cache None (HMB supported) 2GB LPDDR4 Sequential Read (Max) 5,000 MB/s 7,450 MB/s Sequential Write (Max) 4,500 MB/s 6,900 MB/s Random Read (4K) Up to 600,000 IOPS Up to 1,400,000 IOPS Random Write (4K) Up to 700,000 IOPS Up to 1,550,000 IOPS TBW (Endurance) 1,300 TBW 1,200 TBW MTBF 3,000,000 hours 1,500,000 hours Operating Temperature 0°C to 70°C 0°C to 70°C Storage Temperature -40°C to 85°C -40°C to 85°C Shock Resistance 1,500G / 0.5ms 1,500G / 0.5ms Heatsink Patented Graphene Heat Spreader No Get them at the links below: Samsung 990 PRO SSD 2TB (MZ-V9P2T0B/AM): $369.99 (Sold and Shipped by Amazon US) TEAMGROUP T-Force G50 2TB SSD (TM8FFE002T0C129): $279.99 (Sold by TeamGroup, Shipped by Amazon US) Good to know This Amazon deal is U.S. specific, and not available in other regions unless specified. We only use first-party seller links (at the time of article publishing); ensure that you purchase from a first-party seller link only. Check out Today's Deals on Amazon | or our recent tech deals. Become a Prime member (for Students or SNAP) via Neowin Get Prime Access - Prime for half price (for qualifying Medicaid, EBT, SNAP) Subscribe to Prime Video, Audible Plus, Music Unlimited or Kindle Unlimited via Neowin As an Amazon Associate, we earn from qualifying purchases.
    • If you can't spell a simple word that 2nd graders learn, your entire argument is suspect.
    • And here goes the "Won't someone think of the children" brigade. Get stuffed mate. This has NOTHING to do with making the internet safe. It's about tracking adults, spying on your online activity, and sending the boys around when they don't like something you post. Also, again, parliament have voted TWICE against this, and Starmer is going ahead anyway. THAT is anti-democratic bullsh**. They will use this law to track you, they will use this law to control you, and they will use this law to punish you if they don't like what you do, even if it's legal. And your data? Say bye bye to that. It'll be on the darkweb in weeks. I'm not some rando online. I've been an IT professional for 40 years, many of it in security. I know exactly what this means and what will happen to your data. I do not consent and I will not comply.
    • "...but it may not be Microsoft's fault" seems like a reasonable way to tease what is going on without leaving the user with a false impression that an update is the problem. A title isn't a summery, it is meant to entice the user to read the article. It should not contain a misleading premise; which this title does not. You could maybe complain that the first paragraph should have included that detail. The writing style popularized over 100 years ago in newspapers will cover the most important information as soon as possible with details and nuance added later; the idea being that with each new paragraph you have less of the reader's focus.
  • Recent Achievements

    • First Post
      Jocimo earned a badge
      First Post
    • Week One Done
      suprememobiles48 earned a badge
      Week One Done
    • One Month Later
      Windows Guy earned a badge
      One Month Later
    • One Month Later
      Prasann earned a badge
      One Month Later
    • Week One Done
      Prasann earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      520
    2. 2
      +Edouard
      174
    3. 3
      PsYcHoKiLLa
      90
    4. 4
      Steven P.
      81
    5. 5
      ATLien_0
      70
  • Tell a friend

    Love Neowin? Tell a friend!