Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-21-2007, 06:16 PM
Member
 
Join Date: Nov 2007
Posts: 35
java_fun2007 is on a distinguished road
problem with Vectors and getTotal() function
Hi all,
I don't know how to use vectors to get the total number of amounts it should be in double.

this method is in one of the two classes, and it should count the total amounts that are in the other class (Aggregation) using vectors and return the total in double.
I don't really know how the total is done using vectors I just know how to do it using array lists.

here is what I meant and my solutionnot all methods are there just the methods related to my problem are added)
I hope you help me please.




Code:
class Coffee private String CoffeeName;//coffee name private Vector mybatch;//vector of batches double getTotalStock() { //NOT SURE //calculate the total amount for(int i =0;i<mybatch.size();i++) Batch total += (Batch)mybatch.elementAt(i).getStock(); //here I guess the type is a class and the way to get the total is wrong how to get the value in double??? } class Batch { private double stock; public Batch(double stock) { //Done //intialize new batch with stock stock = stock; } public double getStock() { return stock; } }
thank you
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-22-2007, 01:27 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
Code:
class Coffee { private String CoffeeName; //coffee name private Vector mybatch; //vector of batches double getTotalStock() { //calculate the total amount double total = 0; for(int i = 0; i < mybatch.size(); i++) { // You can do this in one line //total += ((Batch)mybatch.get(i)).getStock(); // or you can always break it down Batch batch = (Batch)mybatch.elementAt(i); total += batch.getStock(); } return total; } } class Batch { private double stock; public Batch(double stock) { //intialize new batch with stock stock = stock; } public double getStock() { return stock; } }
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 11-23-2007, 03:55 PM
Member
 
Join Date: Nov 2007
Posts: 35
java_fun2007 is on a distinguished road
thank you so much I understand now
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Vectors of Vectors or hash-somethings? mindwarp New To Java 3 03-10-2008 04:57 PM
Sorting JTable (Vectors) Problem ramapple AWT / Swing 5 02-05-2008 10:54 AM
Using Vectors in Java JavaForums Java Blogs 0 11-04-2007 09:31 PM
Problem with vectors in java toby New To Java 1 08-07-2007 07:56 AM
Function declaration problem. snooze-g Advanced Java 3 07-18-2007 11:15 PM


All times are GMT +3. The time now is 04:08 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org