I understand the concept and theory of all of this, I am just having a really hard time putting this assignment together. (Especially when my professor says " i don't know how to help you figure this out without just telling you how to do it"....Well.....since I already got my (bad) grade on the assignment what's the harm in showing me where I am wrong, or at least helping me get started so I can learn and possibly be ready for the next part of the assignment
If someone can help me get started on the implementation of my array i would be forever grateful......
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!!!!!!!!!!

New Topic/Question
This topic is locked




MultiQuote




|