Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-21-2008, 07:12 AM
Member
 
Join Date: Sep 2008
Posts: 2
Rep Power: 0
Spenc is on a distinguished road
Question Quick Question
I am taking my first Java class. In class we are making a DVD inventory program using an array and calculating the total of the entire inventory at the end. My total does not seem to be working, can you please help me to display the total of the inventory in my program::
import java.util.Scanner;

public class DVDWk6B
{
public static void main( String args[] )
{
// c Scanner to obtain input from command window
Scanner input = new Scanner( System.in );


String dvdName[] = new String[200];
int upc[] = new int[200];
double price[] = new double[200]; // price per item
double qty[] = new double[200]; // total qty
double inventory[] = new double[200]; // total inventory
int itemIndex = 0; // product index

System.out.print("DVD Title or type Stop to quit program.");
dvdName [itemIndex] = input.nextLine();

while (!dvdName[itemIndex].equals("stop")) // check for exit prompt
{
System.out.print("Enter UPC.");
upc [itemIndex] = input.nextInt();


System.out.println( "Price per DVD: " ); // prompt
price [itemIndex] = input.nextDouble(); // read price

System.out.print("Qty: ");
qty [itemIndex] = input.nextDouble();

itemIndex = itemIndex + 1; // increment index by 1
input.nextLine(); // clears input buffer

System.out.print( "DVD Name or stop to terminate: " ); // prompts user for next product item input
dvdName[itemIndex] = input.nextLine(); // gets next product name input from user


// while (qty <= -1) same as above, not really needed
//qty [itemIndex] = input.nextDouble(); // read price
}

// prints output headings
System.out.printf( "%s\t%s\t%s\t%s\t%s\t%s\n", "Index", "DVD Title", "UPC Code", "Qty", "Unit Cost", "Inventory Value");

// print list with inventory values
for (int index = 0; index < itemIndex; index++)
System.out.printf( "%5d\t%-12s\t%-9d\t%-5.2f\t$%-10.2f\t$%-14.2f\n", index+1, dvdName[index], upc[index],qty[index],price[index],
(qty[index] * price[index]));
System.out.print("Total Inventory:"(qty * price));
}//end main method

}
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 09-21-2008, 03:07 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: SouthWest Missouri, USA
Posts: 2,229
Rep Power: 4
Norm is on a distinguished road
Default
Quote:
help me to display the total of the inventory in my program
Can you post what the program is outputing now with a description of how you want to change it? And an example of what you want the output to look like.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 09-22-2008, 05:16 AM
Member
 
Join Date: Sep 2008
Posts: 2
Rep Power: 0
Spenc is on a distinguished road
Smile Thank you for your reply...
I have an array that is listing columns, the column Titles are DVD Title, UPC Code, QTY Unit Cost, Inventory Value. Under these headings is the display of the user input of the information of the DVD. In the last column the unit price and Qty are multiplied to give a total inventory for each DVD title. For example if you have 3 at $20 your inventory value for that DVD is $60. and that part of the program works fine. What I do not understand is how do I total all the DVD in the column to give me a value of the entire DVD collection. I have been working at it for two days and can't seem to get it. My text book does not explain this part very well and my teacher is of NO help. I know what I need the program to do I just do not know how to write the code. I also can not find an example on the internet so I thought I would try asking this forum. I'd be so delighted if you could enlighten me! Thank you.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 09-22-2008, 03:26 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: SouthWest Missouri, USA
Posts: 2,229
Rep Power: 4
Norm is on a distinguished road
Default
Quote:
I do not understand is how do I total all the DVD in the column to give me a value of the entire DVD collection.
There must be more to it than that. To accumulate a total, define a variable: int total = 0;
then add the amount for each item: total += amt;

At the end, total has the sum of all the amounts

When posting code, please use the code tags to keep your formatting.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

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

BB 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
quick easy question jmHoekst New To Java 1 06-19-2008 04:28 PM
Quick question about sorting nbd223 New To Java 10 04-28-2008 10:11 AM
Quick Java question/help Zedy New To Java 6 04-22-2008 04:40 AM
Quick Stupid Question bluekswing New To Java 7 01-08-2008 07:35 PM
Quick Question (Functions) ibanez270dx New To Java 2 11-16-2007 02:42 AM


All times are GMT +2. The time now is 03:07 PM.



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