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

1. Member
Join Date
Feb 2015
Posts
2
Rep Power
0

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[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

// ProductTest.java
// 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",
displayMessage);
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
myProduct.displayMessage();

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. Senior Member
Join Date
Jan 2013
Location
Northern Virginia, United States
Posts
6,226
Rep Power
14

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"

Regards,
Jim

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

Posting Permissions

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