1. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Nov 2012
Posts
2
Rep Power
0

#### Java Programming Help!

This is what my code is suppose to do:
Create an array of FIVE (5) RetailItem objects.
Read in data for the 5 RetailItem objects. After all data has been read in, use another loop to calculate the total price of the inventory. The total price of the inventory is calculated by adding the price * unitsOnHand for each item.

Sample Output:
Enter Units On Hand, Price and Description:
1: 10 5.00 pencil
2: 3 10.25 pen
3: 5 2.25 spoon
4: 12 11.15 book
5: 10 532 tv

Totals:
PENCIL: \$50.00
PEN: \$30.75 SPOON: \$11.25
BOOK: \$133.80
TV: \$5,320.00
Total Inventory: \$5,545.80

I have created this code here:

import java.util.Scanner;
public class Demo
{
public static void main(String []args)
{
Scanner keyboard =new Scanner(System.in);
int numItems = 0;
String description[];
description[] des = new description[numItems];
int unitsOnHand[];
unitsOnHand[] units = new unitsOnHand[numItems];
double price[];
price[] p = new price[numItems];
double totalPrice = 0;

System.out.print("Enter the number of items: ");
numItems = keyboard.nextInt();
//RetailItem item = new RetailItem(description, unitsOnHand, price);
RetailItem[] items = new RetailItem[numItems + 1];

System.out.println("Enter Units On Hand, Price and Description:");
for(int i=1; i<items.length; i++)
{
System.out.print(i + ": ");
unitsOnHand[i] = keyboard.nextInt();
price[i] = keyboard.nextDouble();
description[i] = keyboard.nextLine();
items[i] = new RetailItem(description[i], unitsOnHand[i], price[i]);

totalPrice = totalPrice + (price[i]*unitsOnHand[i]);
}
System.out.println("Totals:");
for(int i=1; i<items.length; i++)
{
System.out.println(description[i] + ": " + unitsOnHand[i]*price[i]);
}
System.out.println("Total Inventory: " + totalPrice);
}
}

And I keep getting errors no matter how I change it up! Currently I have these errors:

Demo.java:9: cannot find symbol
symbol : class description
location: class Demo
description[] des = new description[numItems];
^
Demo.java:9: cannot find symbol
symbol : class description
location: class Demo
description[] des = new description[numItems];
^
Demo.java:11: cannot find symbol
symbol : class unitsOnHand
location: class Demo
unitsOnHand[] units = new unitsOnHand[numItems];
^
Demo.java:11: cannot find symbol
symbol : class unitsOnHand
location: class Demo
unitsOnHand[] units = new unitsOnHand[numItems];
^
Demo.java:13: cannot find symbol
symbol : class price
location: class Demo
price[] p = new price[numItems];
^
Demo.java:13: cannot find symbol
symbol : class price
location: class Demo
price[] p = new price[numItems];
^
6 errors
2. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Jun 2010
Posts
93
Rep Power
26
These are syntax errors that are being generated by your improper use of arrays.

Check out some Java array tutorials and sample code:
http://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html

... and also please use code tags when posting your code to make it more readable. You can learn how to do this here:
http://forums.devshed.com/java-help-9/all-users--how-to-post-a-question-147056.html
3. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Nov 2012
Posts
2
Rep Power
0
Thanks so much for the tutorial link! It really helped me with my array confusions!