Results 1 to 4 of 4

Thread: Quick Question

  1. #1
    Spenc is offline Member
    Join Date
    Sep 2008
    Posts
    2
    Rep Power
    0

    Question 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

    }

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    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.

  3. #3
    Spenc is offline Member
    Join Date
    Sep 2008
    Posts
    2
    Rep Power
    0

    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.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    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.

Similar Threads

  1. quick easy question
    By jmHoekst in forum New To Java
    Replies: 1
    Last Post: 06-19-2008, 04:28 PM
  2. Quick question about sorting
    By nbd223 in forum New To Java
    Replies: 10
    Last Post: 04-28-2008, 10:11 AM
  3. Quick Java question/help
    By Zedy in forum New To Java
    Replies: 6
    Last Post: 04-22-2008, 04:40 AM
  4. Quick Stupid Question
    By bluekswing in forum New To Java
    Replies: 7
    Last Post: 01-08-2008, 07:35 PM
  5. Quick Question (Functions)
    By ibanez270dx in forum New To Java
    Replies: 2
    Last Post: 11-16-2007, 02:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •