Inventory 2 Program

I need HELP!!!!!

Page 1 of 1

2 Replies - 543 Views - Last Post: 18 May 2009 - 09:11 PM Rate Topic: -----

#1 inmate188826  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 18-May 09

Inventory 2 Program

Post icon  Posted 18 May 2009 - 07:01 PM

public class Inventory2 {

	public static void main(String[] args) {

		System.out.println("\nTim's Game Collection\n");

		Game myGame;
		Inventory inventory = new Inventory();		
		String newArray[];
		newArray = new String[8];


		//New Game Records

		myGame = new Game(27, "NFL: Madden '09", 10, 69.43f);
		inventory.add(myGame);		
		
		myGame = new Game(28, "Far Cry 2", 4, 7.34f);
		inventory.add(myGame);		

		myGame = new Game(29, "NHL 2K9", 8, 59.34f);
		inventory.add(myGame);	

		myGame = new Game(30, "Lord of the Rings: Conquest", 1, 50.34f);
		inventory.add(myGame);	

		myGame = new Game(31, "Tiger Woods '08", 4, 49.99f);
	   inventory.add(myGame);	

		myGame = new Game(32, "Blazing Angels: Squadrons of WWII", 5, 40.34f);
		inventory.add(myGame);	

		myGame = new Game(33, "SmackDown VS. Raw: 2009", 7, 59.44f);
		inventory.add(myGame);	


		inventory.display();				// Display the inventory	

		System.out.println("End of Collection\n");
  
} // End Public Class Inventory1
}


// Game class is used to set data from Inventory 1,
// and store the information, as well as calculate totals  ///TIM : NO!! and display inventory.

class Game {
	private int itemNumber;
	private String prodName;
	private int inStock;
	private float itemPrice;
	String newArray[];

	// Game constructor
	Game(int itemNumber, String prodName, int inStock, float itemPrice) {
		this.itemNumber = itemNumber;
		this.prodName   = prodName;
		this.inStock	= inStock;
		this.itemPrice  = itemPrice;

	} //End Constructor

	// calculate totalPrice method
	public float totalPrice() {
		return inStock * itemPrice;
	} //End totalPrice

	// Set Game String output
	public String toString() {
		return String.format(
				   "	Item Number = %03d	 Description = %-12s\n" +
				   "Number in Stock = %3d	 Unit Price = $%.2f	 Total Price = $%.2f\n",
				   itemNumber, prodName, inStock, itemPrice, totalPrice());
	} //End method toString

} // end class Game


class Inventory {
	private Game[] games;	// The array of games
	private int nGames;		// Number of games in the array

	Inventory() {
		games = new Game[20];
		nGames = 0;
	}
	
	public void add(Game myGame) {
		System.out.println("add: " + myGame);	
	}
	
	public void display() {
				System.out.println("display:  nGames = " + nGames);	
	}

} // end class Inventory
 





Okay, Heres my problem... The program compiles but when I go to run it, it says this "

java.lang.NoClassDefFoundError: Inventory2
Caused by: java.lang.ClassNotFoundException: Inventory2
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
Could not find the main class: Inventory2. Program will exit.
Exception in thread "main" Exit code: 1

Here is what I need it to do....

Use an array to store the items. The output should display the information one product at a time, including the item number, the name of the product, the number of units in stock, the price of each unit, and the value of the inventory of that product. In addition, the output should display the value of the entire inventory.
 Create a method to calculate the value of the entire inventory.
 Create another method to sort the array items by the name of the product.
 Post as an attachment in java format.


Obviously, I haven't gotten to the lower half of this assignment.. I'm just trying to get my array to work and display for now.

Thanks for any help!

Is This A Good Question/Topic? 0
  • +

Replies To: Inventory 2 Program

#2 Fuzzyness  Icon User is offline

  • Comp Sci Student
  • member icon

Reputation: 669
  • View blog
  • Posts: 2,438
  • Joined: 06-March 09

Re: Inventory 2 Program

Posted 18 May 2009 - 08:51 PM

Have you tried to put the classes in their own seperate file that is in same folder/location as the inventory2 program?
Was This Post Helpful? 0
  • +
  • -

#3 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4425
  • View blog
  • Posts: 12,293
  • Joined: 18-April 07

Re: Inventory 2 Program

Posted 18 May 2009 - 09:11 PM

I have tested your code and it compiled and ran fine for me. So either it is the IDE you are using is not setting up the project correctly or you don't have the files named properly.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1