Results 1 to 5 of 5
- 08-21-2009, 03:09 AM #1
Member
- Join Date
- Aug 2009
- Posts
- 2
- Rep Power
- 0
Help with Inventory Program, Please
I am new to java and I am having some trouble trying to add an array in my program. I need to use an array to store items. I have been told by others that may program has an array in it already, but I don't think I have done it properly. Can someone please help? Thank you so much.
Here's what I have so far:
public class Inventory2
{
public static void main ( String args[] )
{
cd CD;
cd = new CD(1, "The Block", 3, 12.99);
System.out.println(cd);
cd = new CD(2, "Step by Step", 5, 9.99);
System.out.println(cd);
cd = new CD(3, "Face the Music", 4, 7.99);
System.out.println(cd);
cd = new CD(4, "Summertime", 2, 2.99);
} // end main
} // end class
class CD
{
private String cdName;
private int cdCount;
private double cdPrice;
private int cdItem;
}
public class CD (int itemNumber, String productName, int unitCount, double unitPrice )
{
cdName = name;
cdCount = count;
cdPrice = price;
cdItem = item;
} // end constructor
public void Inventory2( String productName )
{
p_ProductName = productName; // initializes p_ProductName
} // end constructor
// constructor initializes p_ProductName, p_UnitCount;
// double instance variables are initialized to 0 by default
public void Inventory2( String productName, int unitCount, double unitPrice )
{
ProductName = productName; // initializes ProductName
UnitCount = unitCount; // initialized UnitCount
UnitPrice = unitPrice; // initialized UnitPrice
} // end constructor
// begin method
// method to retrieve the ProductName
public String getProductName()
{
return ProductName;
} // end method getProductName
// method to retrieve the UnitCount
public double getUnitCount()
{
return UnitCount;
} // end method getUnitCount
// method to retrieve the UnitPrice
public double getUnitPrice()
{
return UnitPrice;
} // end method getUnitPrice
// method to retrieve product's value.
public double getUnitValue()
{
return UnitCount*UnitPrice;
} // end method getUnitValue
public String toString()
{
return String.format( "name=%s count=%d price=%.2f item=%d value=$%.2f",
name, count, price, item,value ());
}
} // end class CD
class Inventory2
{
CD audio = new CD[200];
public void addToInventory2(CD audio)
{
} //end class
public double getProductValue()
{
Inventory2 myInventory = new Inventory();
myInventory.addToInventory2(new CD (1, "Hangin' Tough", 2, 4.99));
System.out.println( "The total value of inventory is:" + myInventory.getInventoryValue());
return myinventory.getInventoryValue();
} // end method
} //end class Inventory2
-
- 08-21-2009, 03:42 AM #3
Member
- Join Date
- Aug 2009
- Posts
- 2
- Rep Power
- 0
Tried that site
Thanks for the link but i've tried that site before. I guess my main question would be is where to place the array? Would I be correct to place it at the beginning of the program?
thank again
- 08-21-2009, 04:07 AM #4
Here is a basic bare bones inventory class.
However, maybe you need to freshen up on the very basics of creating variables and classes since you seem to get that very wrong in your post.Java Code:public class Inventory { private ArrayList<CD> cdList = new ArrayList<CD>(); // or you could also use CD[] public int getAmountOfCD() { return cdList.size(); } public void addCD(CD item) { cdList.add(item); } public void removeItem(CD item) { cdList.remove(item); } }
You should check out the Java TrailLast edited by Mr.Beans; 08-21-2009 at 04:14 AM.
- 08-21-2009, 11:09 AM #5
Senior Member
- Join Date
- Jun 2008
- Posts
- 339
- Rep Power
- 5
Similar Threads
-
Inventory Program Part 2 of 6
By tlouvierre in forum New To JavaReplies: 2Last Post: 05-28-2009, 01:30 AM -
Inventory Program
By tlouvierre in forum New To JavaReplies: 5Last Post: 05-17-2009, 05:09 AM -
[SOLVED] GUI Inventory Program
By marMcD in forum New To JavaReplies: 5Last Post: 03-03-2009, 06:12 AM -
Inventory Program Part 3 ~ please help!
By marMcD in forum New To JavaReplies: 13Last Post: 02-25-2009, 05:57 AM -
Inventory program
By Nexcompac in forum New To JavaReplies: 3Last Post: 07-27-2007, 05:51 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks