Results 1 to 3 of 3
  1. #1
    JakeB is offline Member
    Join Date
    Feb 2015
    Rep Power

    Default I do not know how to get the String Array to work with the int array

    Hello everyone, first time on the forums. I am doing a school assignment and I have to create an inventory program that displays a product number, name of product, number of units in stock, price of each unit, and then at the end total up the entire value of the inventory. I am a beginner as I am 5 weeks into my first programmer class and I do want to learn how to program. I am able to get the inventory array with the (int) to display in the columns but I do not know how to get the String array with the DVD's to display where they are suppose to. I also cannot figure out how to calculate the quantity with the price to give me an overall total. The program is due tonight but I want to know how to do it so if I have to turn it in late but have the knowledge knowing how to fix the issue then I will. Also, I am not sure if I am doing it right to begin with so any help would be appreciated.

    This is my code so far:

    // IT215: Product class for Inventory Program
    // by JakeB

    public class Product // begin Product class
    int Stock[] = { 101, 102, 103, 104, 105 };
    String[] DVD = new String[5];
    double Price[] = { 10.00, 10.00, 12.50, 18.50, 11.50 };
    int Quantity[] = { 1, 5, 4, 3, 4 };
    double sum = 0;
    double product = 0;

    // create inventory
    public void dvdInventory(String DVD[]){
    DVD[0]= "Lion King";
    DVD[1]= "Peter Pan";
    DVD[2]= "Aladdin ";
    DVD[3]= "Snow White";
    DVD[4]= "Cinderella";
    // display Inventory results
    public void displayMessage()
    // begin for loop
    for(double counter=0; counter<Quantity.length; counter++)
    System.out.println( (int)counter + 1 + "\t"
    + Stock[(int)counter] + "\t"
    + "\t" + "$" + Price[(int)counter] + " ea. "
    + "\t" + Quantity[(int)counter]);

    // constructor initializes sum with int argument
    public Product(double totalSum)
    {// constructor totalSum
    sum = totalSum; // initializes sum

    } //end constructor

    // method to set the sum
    public void setSum(double totalSum)
    sum = totalSum; // store the sum
    } // end method setCourseName

    // method to retrieve the sum
    public double getSum()
    return sum;
    } //end method retrieve

    } // end Product Class

    // by JakeB

    public class ProductTest {
    private static Object displayMessage;

    // main method begins
    public static void main(String[] args) // begin main
    System.out.printf("Welcome to the DVD Inventory!\n"); // display welcome message
    System.out.printf("Here is the current list of DVD's in inventories.\n\n",
    // display column headings
    System.out.println("Index\tStock#\t\tPrice\t\tQuan tity\tDVD");

    // create a Product object and assign it to myProduct
    Product myProduct = new Product(0);

    // call myProduct display message method

    System.out.printf("The total value of all DVD's is $\n" ); // display the total value of all the dvds
    } //end main
    } // end ProductTest class

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Northern Virginia, United States
    Rep Power

    Default Re: I do not know how to get the String Array to work with the int array

    You don't need a method to initialize the String array. You can do it just like you did with int[] and double[]. Just put the strings between double quotation marks. E.g. "a string"

    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power

    Default Re: I do not know how to get the String Array to work with the int array

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Integer array to String array
    By lakshmibvaraprasad in forum New To Java
    Replies: 1
    Last Post: 07-20-2011, 08:39 PM
  2. String Array to a Byte Array?
    By lazarus1410 in forum Advanced Java
    Replies: 1
    Last Post: 12-03-2010, 08:25 AM
  3. create a 2d char array from a 1D string array
    By jschmall12 in forum New To Java
    Replies: 1
    Last Post: 04-27-2010, 09:01 PM
  4. Convert Char Array to String Array
    By Mayur in forum New To Java
    Replies: 8
    Last Post: 10-12-2009, 11:41 AM
  5. String array to byte array?!
    By Joe2003 in forum Advanced Java
    Replies: 5
    Last Post: 02-28-2009, 06:09 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