Results 1 to 4 of 4
Thread: Quick Question
- 09-21-2008, 07:12 AM #1
Member
- Join Date
- Sep 2008
- Posts
- 2
- Rep Power
- 0
Quick Question
:confused: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
}
- 09-21-2008, 03:07 PM #2help me to display the total of the inventory in my program
- 09-22-2008, 05:16 AM #3
Member
- Join Date
- Sep 2008
- Posts
- 2
- Rep Power
- 0
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.
- 09-22-2008, 03:26 PM #4I do not understand is how do I total all the DVD in the column to give me a value of the entire DVD collection.
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.
Similar Threads
-
quick easy question
By jmHoekst in forum New To JavaReplies: 1Last Post: 06-19-2008, 04:28 PM -
Quick question about sorting
By nbd223 in forum New To JavaReplies: 10Last Post: 04-28-2008, 10:11 AM -
Quick Java question/help
By Zedy in forum New To JavaReplies: 6Last Post: 04-22-2008, 04:40 AM -
Quick Stupid Question
By bluekswing in forum New To JavaReplies: 7Last Post: 01-08-2008, 07:35 PM -
Quick Question (Functions)
By ibanez270dx in forum New To JavaReplies: 2Last Post: 11-16-2007, 02:42 AM
Bookmarks