473,385 Members | 1,461 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to calculate total in arrayList

I have a problem in that I have an arrayList called pizzaOrders which contains a number of pizza orders. The pizza orders contain information like names, addresses, total price for orders and the dates of orders.

The date is selected through a dateTimePicker. Basically what I need to do is count the orders on a particular day and produce a graph for this.

So I need, for example, to search the arrayList and calculate how many orders were made on each day. I assume this is done by totalling the number of times Monday appears in the arrayList to give me a figure.

Any help would be great, I've been trying hard but to no avail.

Thanks

Jack
Jul 6 '10 #1

✓ answered by Christopher Nigro

Ah, sorry about that! I misread your original post. All you need to do is change that one line to this:

Expand|Select|Wrap|Line Numbers
  1. int dayTotal = (from o in orders where o.OrderDate.DayOfWeek == DayOfWeek.Thursday select o.Total).Count();
I assume you are using Visual Studio - if so, delete that last '.' before Count() and then retype it - IntelliSense will pop up and show you all of the goodies that are available.

4 4096
Can you ditch the array list and use a List<PizzaOrder> instead? If so, you could do something similiar to this:

Expand|Select|Wrap|Line Numbers
  1. List<PizzaOrder> orders = new List<PizzaOrder>();
  2. orders.Add(new PizzaOrder("Customer A", new DateTime(2010, 7, 1, 12, 5, 0), (decimal)19.95d));
  3. orders.Add(new PizzaOrder("Customer B", new DateTime(2010, 7, 1, 13, 30, 0), (decimal)6.99d));
  4. orders.Add(new PizzaOrder("Customer C", new DateTime(2010, 7, 2, 11, 45, 0), (decimal)42.80d));
  5. orders.Add(new PizzaOrder("Customer D", new DateTime(2010, 7, 3, 04, 0, 0), (decimal)10.00d));
  6.  
  7. decimal dayTotal = (from o in orders where o.OrderDate.DayOfWeek == DayOfWeek.Thursday select o.Total).Sum();
  8.  
  9. Console.WriteLine(string.Format("The total for Thursday is: {0}", dayTotal));
  10.  
Jul 6 '10 #2
How would I use it to display the total number of orders on say Monday. I don't want the total for that day just the total number of orders.

For example (using your code):
Expand|Select|Wrap|Line Numbers
  1. orders.Add(new PizzaOrder("Customer A", new DateTime(2010, 7, 1, 12, 5, 0), (decimal)19.95d));
  2. orders.Add(new PizzaOrder("Customer B", new DateTime(2010, 7, 1, 13, 30, 0), (decimal)6.99d));
  3. orders.Add(new PizzaOrder("Customer C", new DateTime(2010, 7, 2, 11, 45, 0), (decimal)42.80d));
  4. orders.Add(new PizzaOrder("Customer D", new DateTime(2010, 7, 3, 04, 0, 0), (decimal)10.00d));
  5.  
To produce the result that 2 orders were made on Thursday? At the moment it is displaying the total price.

Thanks,

Jack
Jul 6 '10 #3
Ah, sorry about that! I misread your original post. All you need to do is change that one line to this:

Expand|Select|Wrap|Line Numbers
  1. int dayTotal = (from o in orders where o.OrderDate.DayOfWeek == DayOfWeek.Thursday select o.Total).Count();
I assume you are using Visual Studio - if so, delete that last '.' before Count() and then retype it - IntelliSense will pop up and show you all of the goodies that are available.
Jul 6 '10 #4
Works perfectly, thank you.
Jul 6 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: John | last post by:
hey all..... alright, I am frusterated to the point of throwing my machine out the window (this board went down, trying to find stuff on google, this has been a nightmare) so I hope you guys can...
2
by: MT | last post by:
Hi, I have an invoicing system using postgresql. Each time a customer makes a purchase, a new record is inserted into the "cart" table. The "cart" table, among other things, contains a customer_id...
5
by: RC | last post by:
I have a form with three text boxes on it. I want the third text box to show the total of the values in the other two text boxes. The first box is named: BoxOne and I type the number 2 into it...
3
by: JDiamond | last post by:
Hi, I have a table called Hosts. The Hosts table contains the following fields: Each field represents a step in the project. The tech that completes each step initials the respective...
2
by: dath | last post by:
Hi, Not really a programmer here, but have been forced into the role. I was asked to develop a basic time sheet for employees to enter time. I developed the Table without a problem. I then...
1
by: mesud | last post by:
helow i'm new but i wanna ask that i need the code to connect database access with vb and calculate total,subtotal,tax etc. and display it
9
by: mankolele | last post by:
Hi all I need an idea on where to start when calculating a total amount betwee n two dates from a database like I want amount of money paid out from 30/03/2004 and 30/07/2004 ,but in the database...
1
by: reshmaarora22 | last post by:
hi i have i table called Description which has details about StartTime , EndTime and ScheduleDate of the various Transaction occuring daily.I want to fetch total time spend on a particular...
4
by: sumit kale | last post by:
Hi, Can somebody help me resolve my problem ? I am getting error when calculating total using unbound textfiled in subform. I have a main form called purchase_register_master and a subform...
3
by: HTIDIRECT | last post by:
I am currently creating a form that requires me to have multiple comboboxes which have various options with different values. What I am having a problem with is finding a javascript snippet that...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.