PLEASE HELP ME FIND MY ERRORS

stuck in the middle of inventory program project

Page 1 of 1

3 Replies - 865 Views - Last Post: 30 July 2008 - 09:10 AM Rate Topic: -----

#1 StaceyE   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 30-July 08

PLEASE HELP ME FIND MY ERRORS

Posted 30 July 2008 - 07:01 AM

I am in week 8 of a 9 week Java class. I have seeked help from my professor, but to no avail.

I have completed the first three steps to my assignment (described below), however my Total Stock value and 5% restock fee do not appear in my output. NetBeans IDE says I had an error in line 154, But I can't figure out how to fix it. The success of the next three stages ( one of which I have already blown, gradewise any way), is dependent on the functionality of my code through stage 3.

My professor expects me to just move on since the assignment has already been graded, but how will I learn anything if I just keep failing without learning how to fix my mistakes.
I have already been graded through part 4 of this assignment, but would like to figure out what's wrong with my code, so I can experience a little bit of success in this class.

Here is what the code I have submitted is supposed to do:

PART 1: (I GOT 50/50 POINTS ON THIS PART)
* Choose a product that lends itself to an inventory (for example, products at your workplace, office supplies, music CDs, DVD movies, or software).
* Create a product class that holds the item number, the name of the product, the number of units in stock, and the price of each unit.
* Create a Java application that displays the product number, the name of the product, the number of units in stock, the price of each unit, and the value of the inventory (the number of units in stock multiplied by the price of each unit). Pay attention to the good programming practices in the text to ensure your source code is readable and well documented.[/color]

PART 2: (I GOT 35/50 HERE)
* Modify the Inventory Program so the application can handle multiple items. 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.

PART 3: (I GOT 30/50 HERE)
* Modify the Inventory Program by creating a subclass of the product class that uses one additional unique feature of the product you chose (for the DVDs subclass, you could use movie title, for example). In the subclass, create a method to calculate the value of the inventory of a product with the same name as the method previously created for the product class. The subclass method should also add a 5% restocking fee to the value of the inventory of that product.
*Modify the output to display this additional feature you have chosen and the restocking fee.



package inventory3;


/**
 *
 * @author Stacey
 */
public class inventory3 {

	   public static void main(String[] args) {
		Inventory inventory = new Inventory();
		Movie dvd;

		dvd = new Movie("DVD1", 2356, "Pinnochio", 25, 14.99);
		inventory.add(dvd);
		dvd = new Movie("DVD2", 5684, "Shark Tale", 3, 12.00);
		inventory.add(dvd);
		dvd = new Movie("DVD3", 5564, "Flushed Away", 15, 15.75);
		inventory.add(dvd);
		dvd = new Movie("DVD4", 5562, "Shrek", 7, 9.99);
		inventory.add(dvd);

		inventory.display();
	} //end main

} // end class Inventory3


class DVD {
	private int ItemNumber;
	private String ProductName;
	private int units;
	private double unitPrice;
	private double inventoryvalue;
	private double TotalStockValue;
	
	public DVD(int item, String title, int stock, double price) {
		ItemNumber  = item;
		ProductName = title;
		units = stock;
		unitPrice = price;
	} //end four-argument constructor

	// set DVD Item
	public void setDvdItem(int item) {
		ItemNumber = item;
	} //end method  set Dvd Item

	//return DVD Item
	public int getItemNumber() {
		return ItemNumber;
	} //end method get Dvd Item

	//set DVD Title
	public void setProductName(String title) {
		ProductName = title;
	} //end method set Dvd Title

	//return Dvd Title
	public String getProductName() {
		return ProductName;
	} //end method get Dvd Title

	public void setDvdStock(int stock) {
		units = stock;
	} //end method set Dvd Stock

	//return dvd Stock
	public int getunits() {
		return units;
	} //end method get Dvd Stock

	public void setunitPrice(double price) {
		unitPrice = price;
	} //end method setdvdPrice

	//return DVD Price
	public double getunitPrice() {
		return unitPrice;
	} //end  method get Dvd Price

	//calculate inventory value
	public double inventoryvalue() {
		return unitPrice * units;
	} //end method value

	//calculate total stock value
	public double TotalStockValue(){
		return inventoryvalue += inventoryvalue;
		
	}
	@Override
	public String toString() {
		return String.format("item=%3d   title=%-20s   units=%3d   price=$%6.2f   value=$%7.2f",
							  ItemNumber, ProductName, units, unitPrice, inventoryvalue());
	}

} //end class DVD


class Movie extends DVD {
	private String movieTitle;

	public Movie(String title, int item, String dtitle, int stock, double price) {
		super(item, dtitle,  stock, price);
		movieTitle = title;
	}

 
	public double value() {
		double inventoryvalue = getunitPrice() * getunits();
		inventoryvalue = 1.05 * inventoryvalue;
		return inventoryvalue;
	} //end method value

	@Override
	public String toString() {
		String s = String.format("Movie title=%-12s", movieTitle);
		s = s + " " + super.toString();
		return s;
	}

} // end class Movie


class Inventory {
	private DVD[] dvds;
	private int count;
	private Object[] dvd;
	private double entireValue;

	Inventory() {
		dvds = new DVD[4];
		count = 0;
	}

	public void add(DVD dvd) {
		dvds[count] = dvd;
		++count;
		sort();
	}

	public double entireValue() {
		double value = 0;
		for (int i = 0; i < count; i++) {
			value = value + dvds[i].value();
		}
		return value;
	}

	public void sort() {
		for (int index = 1; index < count; index++) {
			DVD key = dvds[index];
			int position = index;

			//  Shift larger values to the right
			while (position > 0 && key.getProductName().compareTo(dvds[position-1].getProductName()) < 0) {
				dvds[position] = dvds[position-1];
				position--;
			}
			dvds[position] = key;
		}
	}

	public void display() {
		System.out.println("\nThe inventory contains " + count + " DVDs\n");
		for (int i = 0; i < count; i++)
			System.out.printf("%3d  %s\n", i, dvds[i]);
		System.out.printf("\nThe total inventory value is $%.2f\n\n", entireValue());
	}

} // end class Inventory



Here's what I am supposed to do next:


PART 4: ( I GOT 28/50 ON THIS PART…..BOMBING FAST….)
* Modify the Inventory Program to use a GUI. The GUI 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 GUI should display the value of the entire inventory, the additional attribute, and the restocking fee.

PART 5: (THIS PART IS DUE THIS SUNDAY 8-3-08 worth 50 points)
* Modify the Inventory Program by adding a button to the GUI that allows the user to move to the first item, the previous item, the next item, and the last item in the inventory. If the first item is displayed and the user clicks on the Previous button, the last item should display. If the last item is displayed and the user clicks on the Next button, the first item should display.
* Add a company logo to the GUI using Java graphics classes.

PART 6: ( This part is due Sunday July 10, and is worth 200 points)
* Modify the Inventory Program to include an Add button, a Delete button, and a Modify
button on the GUI. These buttons should allow the user to perform the corresponding
actions on the item name, the number of units in stock, and the price of each unit. An
item added to the inventory should have an item number one more than the previous last
item.
* Add a Save button to the GUI that saves the inventory to a C:\data\inventory.dat file.
* Use exception handling to create the directory and file if necessary.
* Add a search button to the GUI that allows the user to search for an item in the inventory by the product name. If the product is not found, the GUI should display an appropriate message. If the product is found, the GUI should display that product’s information in the GUI.


Any help that can be offered is greatly appreciated, when I started this class my GPA was 3.9, but that's all out the window now...LOL...I hope to pass with a C...maybe better if I can get this figured out!!!

Is This A Good Question/Topic? 0
  • +

Replies To: PLEASE HELP ME FIND MY ERRORS

#2 lordms12   User is offline

  • D.I.C Regular
  • member icon

Reputation: 30
  • View blog
  • Posts: 339
  • Joined: 16-February 08

Re: PLEASE HELP ME FIND MY ERRORS

Posted 30 July 2008 - 07:21 AM

Do you mean this line value = value + dvds[i].value(); if so that's because DVD does not have method value() but if you are handling DVD[] in this case as Movie[] (dvds = new Movive[4];) then do casting (value = value + ((Movie) dvds[i]).value();) and your problems will solved

If you searched this forum you will find a lot of posts on what you are working on with Inventory in title.

This post has been edited by lordms12: 30 July 2008 - 07:23 AM

Was This Post Helpful? 1
  • +
  • -

#3 StaceyE   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 30-July 08

Re: PLEASE HELP ME FIND MY ERRORS

Posted 30 July 2008 - 07:40 AM

View Postlordms12, on 30 Jul, 2008 - 07:21 AM, said:

Do you mean this line value = value + dvds[i].value(); if so that's because DVD does not have method value() but if you are handling DVD[] in this case as Movie[] (dvds = new Movive[4];) then do casting (value = value + ((Movie) dvds[i]).value();) and your problems will solved

If you searched this forum you will find a lot of posts on what you are working on with Inventory in title.


Thank You so Much.....this worked and my total stock value is calculating with my 5% restoking fee included!!!!!THANK YOU!!!!

You are my hero! I have been trying to get help with that for two weeks!!!!!
Was This Post Helpful? 0
  • +
  • -

#4 StaceyE   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 30-July 08

Re: PLEASE HELP ME FIND MY ERRORS

Posted 30 July 2008 - 09:10 AM

OK so now I have started part four adding the GUI. I have it started but can't get started on making it work with my array. I am supposed to override my event handlers, but the examples my instructor gives do not help me at all, I can't even see how they relate to my code. I need to make my GUI function...so when I click on Pinnochio...It should display that info...etc. as well as being able to click the next button to navigate the selections.

If someone can help me get started on the implementation of my array i would be forever grateful, as before, I have already been graded on this portion of the assignment, I am just trying to get it right so I can try to figur out how to do part 5 & 6 on my own. *crossing fingers*

here's my code so far

/*
 * DVDJPanel.java
 *
 * Created on July 30, 2008, 11:19 AM
 */

package inventory3;
import javax.swing.JOptionPane;

/**
 *
 * @author  Stacey
 */
 class inventory3 {

	   public static void main(String[] args) {
		Inventory inventory = new Inventory();
		Movie dvd;

		dvd = new Movie("DVD1", 2356, "Pinnochio", 25, 14.99);
		inventory.add(dvd);
		dvd = new Movie("DVD2", 5684, "Shark Tale", 3, 12.00);
		inventory.add(dvd);
		dvd = new Movie("DVD3", 5564, "Flushed Away", 15, 15.75);
		inventory.add(dvd);
		dvd = new Movie("DVD4", 5562, "Shrek", 7, 9.99);
		inventory.add(dvd);

		inventory.display();
	} //end main

} // end class Inventory3


class DVD {
	private int ItemNumber;
	private String ProductName;
	private int units;
	private double unitPrice;
	private double inventoryvalue;
	private double TotalStockValue;
	
	public DVD(int item, String title, int stock, double price) {
		ItemNumber  = item;
		ProductName = title;
		units = stock;
		unitPrice = price;
	} //end four-argument constructor

	// set DVD Item
	public void setDvdItem(int item) {
		ItemNumber = item;
	} //end method  set Dvd Item

	//return DVD Item
	public int getItemNumber() {
		return ItemNumber;
	} //end method get Dvd Item

	//set DVD Title
	public void setProductName(String title) {
		ProductName = title;
	} //end method set Dvd Title

	//return Dvd Title
	public String getProductName() {
		return ProductName;
	} //end method get Dvd Title

	public void setDvdStock(int stock) {
		units = stock;
	} //end method set Dvd Stock

	//return dvd Stock
	public int getunits() {
		return units;
	} //end method get Dvd Stock

	public void setunitPrice(double price) {
		unitPrice = price;
	} //end method setdvdPrice

	//return DVD Price
	public double getunitPrice() {
		return unitPrice;
	} //end  method get Dvd Price

	//calculate inventory value
	public double inventoryvalue() {
		return unitPrice * units;
	} //end method value

	//calculate total stock value
	public double TotalStockValue(){
		return inventoryvalue += inventoryvalue;
		
	}
	@Override
	public String toString() {
		return String.format("item=%3d   title=%-20s   units=%3d   price=$%6.2f   value=$%7.2f",
							  ItemNumber, ProductName, units, unitPrice, inventoryvalue());
	}

} //end class DVD


class Movie extends DVD {
	private String movieTitle;

	public Movie(String title, int item, String dtitle, int stock, double price) {
		super(item, dtitle,  stock, price);
		movieTitle = title;
	}


	public double value() {
		double inventoryvalue = getunitPrice() * getunits();
		inventoryvalue = 1.05 * inventoryvalue;
		return inventoryvalue;
	} //end method value

	@Override
	public String toString() {
		String s = String.format("Movie title=%-12s", movieTitle);
		s = s + " " + super.toString();
		return s;
	}

} // end class Movie


class Inventory {
	private DVD[] dvds;
	private int count;
	private Object[] dvd;
	private double entireValue;

	Inventory() {
		dvds = new DVD[4];
		count = 0;
	}

	public void add(DVD dvd) {
		dvds[count] = dvd;
		++count;
		sort();
	}

	public double entireValue() {
		double value = 0;
		for (int i = 0; i < count; i++) {
		   value = value + ((Movie) dvds[i]).value();
		}
		return value;
	}

	public void sort() {
		for (int index = 1; index < count; index++) {
			DVD key = dvds[index];
			int position = index;

			//  Shift larger values to the right
			while (position > 0 && key.getProductName().compareTo(dvds[position-1].getProductName()) < 0) {
				dvds[position] = dvds[position-1];
				position--;
			}
			dvds[position] = key;
		}
	}

	public void display() {
		System.out.println("\nThe inventory contains " + count + " DVD titles.\n");
		for (int i = 0; i < count; i++)
			System.out.printf("%3d  %s\n", i, dvds[i]);
		System.out.printf("\nThe total inventory value is $%.2f\n\n", entireValue());
	}

} // end class Inventory

public class DVDJPanel extends javax.swing.JPanel {

	/** Creates new form DVDJPanel */
	public DVDJPanel() {
		initComponents();
	}

	/** This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
	// <editor-fold defaultstate="collapsed" desc="Generated Code">
	private void initComponents() {

		jToggleButton6 = new javax.swing.JToggleButton();
		jToggleButton1 = new javax.swing.JToggleButton();
		jToggleButton2 = new javax.swing.JToggleButton();
		jToggleButton3 = new javax.swing.JToggleButton();
		jToggleButton4 = new javax.swing.JToggleButton();
		jToggleButton5 = new javax.swing.JToggleButton();
		jToggleButton7 = new javax.swing.JToggleButton();
		jPanel1 = new javax.swing.JPanel();
		jScrollPane1 = new javax.swing.JScrollPane();
		jTextPane1 = new javax.swing.JTextPane();

		jToggleButton6.setText("jToggleButton6");

		jToggleButton1.setText("Pinnochio");
		jToggleButton1.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent evt) {
				jToggleButton1MouseClicked(evt);
			}
		});

		jToggleButton2.setText("Shark Tale ");
		jToggleButton2.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent evt) {
				jToggleButton2MouseClicked(evt);
			}
		});

		jToggleButton3.setText("Flushed Away");
		jToggleButton3.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent evt) {
				jToggleButton3MouseClicked(evt);
			}
		});

		jToggleButton4.setText("Shrek");
		jToggleButton4.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent evt) {
				jToggleButton4MouseClicked(evt);
			}
		});

		jToggleButton5.setText("NEXT");

		jToggleButton7.setText("Total Value + restock fee");

		jTextPane1.addAncestorListener(new javax.swing.event.AncestorListener() {
			public void ancestorMoved(javax.swing.event.AncestorEvent evt) {
			}
			public void ancestorAdded(javax.swing.event.AncestorEvent evt) {
				jTextPane1AncestorAdded(evt);
			}
			public void ancestorRemoved(javax.swing.event.AncestorEvent evt) {
			}
		});
		jScrollPane1.setViewportView(jTextPane1);

		javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
		jPanel1.setLayout(jPanel1Layout);
		jPanel1Layout.setHorizontalGroup(
			jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
			.addGap(0, 501, Short.MAX_VALUE)
			.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 501, Short.MAX_VALUE))
		);
		jPanel1Layout.setVerticalGroup(
			jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
			.addGap(0, 232, Short.MAX_VALUE)
			.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 232, Short.MAX_VALUE))
		);

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
		this.setLayout(layout);
		layout.setHorizontalGroup(
			layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
			.addGroup(layout.createSequentialGroup()
				.addContainerGap()
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
					.addGroup(layout.createSequentialGroup()
						.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
						.addContainerGap())
					.addGroup(layout.createSequentialGroup()
						.addComponent(jToggleButton1)
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
						.addComponent(jToggleButton2)
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
						.addComponent(jToggleButton3)
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
						.addComponent(jToggleButton4)
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
						.addComponent(jToggleButton7)
						.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
					.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
						.addComponent(jToggleButton5)
						.addGap(231, 231, 231))))
		);
		layout.setVerticalGroup(
			layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
			.addGroup(layout.createSequentialGroup()
				.addGap(27, 27, 27)
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
					.addComponent(jToggleButton1)
					.addComponent(jToggleButton2)
					.addComponent(jToggleButton3)
					.addComponent(jToggleButton4)
					.addComponent(jToggleButton7))
				.addGap(18, 18, 18)
				.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
				.addGap(18, 18, 18)
				.addComponent(jToggleButton5)
				.addContainerGap(19, Short.MAX_VALUE))
		);
	}// </editor-fold>

private void jToggleButton1MouseClicked(java.awt.event.MouseEvent evt) {											
// TODO add your handling code here:
}										   

private void jToggleButton2MouseClicked(java.awt.event.MouseEvent evt) {											
// TODO add your handling code here:
}										   

private void jToggleButton3MouseClicked(java.awt.event.MouseEvent evt) {											
// TODO add your handling code here:
}										   

private void jToggleButton4MouseClicked(java.awt.event.MouseEvent evt) {											
// TODO add your handling code here:
}										   

private void jTextPane1AncestorAdded(javax.swing.event.AncestorEvent evt) {
  
}


	// Variables declaration - do not modify
	private javax.swing.JPanel jPanel1;
	private javax.swing.JScrollPane jScrollPane1;
	private javax.swing.JTextPane jTextPane1;
	private javax.swing.JToggleButton jToggleButton1;
	private javax.swing.JToggleButton jToggleButton2;
	private javax.swing.JToggleButton jToggleButton3;
	private javax.swing.JToggleButton jToggleButton4;
	private javax.swing.JToggleButton jToggleButton5;
	private javax.swing.JToggleButton jToggleButton6;
	private javax.swing.JToggleButton jToggleButton7;
	// End of variables declaration

}



Again Thank you for any help I might receive!
I am reading a bunch of books...Java for Dummies, Acomplete idiot's guide to Java, Java for beginners, Java in a nutshell, and of course my text book Java how to program..(which doesn't cover half the stuff they expect from us in class)....Hopefully I will be better prepared before I have to take my next Java class...Thank goodness this one is almost over!!!!!!!!!!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1