Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 15th, 2012, 03:04 PM
mcrawfornorton mcrawfornorton is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 2 mcrawfornorton User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 m 21 sec
Reputation Power: 0
Homework - 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

Reply With Quote
  #2  
Old November 15th, 2012, 03:08 PM
jasondj jasondj is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2010
Posts: 93 jasondj User rank is Sergeant Major (2000 - 5000 Reputation Level)jasondj User rank is Sergeant Major (2000 - 5000 Reputation Level)jasondj User rank is Sergeant Major (2000 - 5000 Reputation Level)jasondj User rank is Sergeant Major (2000 - 5000 Reputation Level)jasondj User rank is Sergeant Major (2000 - 5000 Reputation Level)jasondj User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Day 5 h 54 m
Reputation Power: 24
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

Reply With Quote
  #3  
Old November 15th, 2012, 03:16 PM
mcrawfornorton mcrawfornorton is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 2 mcrawfornorton User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 m 21 sec
Reputation Power: 0
Thanks so much for the tutorial link! It really helped me with my array confusions!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Homework - Java Programming Help!

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap