Hello everyone and thanks in advance for your help. I am having trouble with a piece of java code for class and have asked the insructor for help and he has only helped in confusing me further. The assignment was due Sunday and I have been in the hospital since last Wed. I get no credit if it is not turned in by tomorrow and I need credit for this assignment to maintain my GPA.This is an inventory program and I am not sure if it was the meds I was on that made me lose the grasp on the assignment or the fact I just hate GUIs and programming them. (I never learned) Here is the assignment from the class syllabus: • "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."
The additional attribute is the DVD title. I chose to use a DVD inventory of only 4 DVDs the instructor has accepted this so here is my code. It is copied straight out of Netbeans IDE 6.8. I did exactly what the instructor asked me to do which was add the API and compile it. I also added the compiled .java file to this post. I can not get it to work correctly. PLease help. Again thank you for your help.
package InventoryProgram3;
/**
*
* @author Ardus
*/
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
public class Main {
public static void main(String args []) {
Inventory invent = new Inventory();// tells the program to enter the information for each dvd into the inventory array for future use
Movie dvd;
dvd = new Movie("Movie1", 1, "Batman", 5, 14.95);
invent.add(dvd);
dvd = new Movie("Movie2", 2, "Wanted", 10, 19.99);
invent.add(dvd);
dvd = new Movie("Movie3", 3, "Star Wars Collection I-VI", 6, 49.99);
invent.add(dvd);
dvd = new Movie("Movie4", 4, "Death Race", 3, 19.99);
invent.add(dvd);
invent.display();
} //end main
} // end class Inventory3
class DVD {
private int dvdItem;
private String dvdTitle;//title of dvd
private int dvdStock;//number in stock
private double dvdPrice;//price per dvd
public DVD(int item, String title, int stock, double price) {
dvdItem = item;
dvdTitle = title;//title of dvd
dvdStock = stock;// number in stock
dvdPrice = price;// price per dvd
} //end four-argument constructor
// set DVD Item
public void setDvdItem(int item) {
dvdItem = item;
} //end method set Dvd Item
//return DVD Item
public int getDvdItem() {
return dvdItem;
} //end method get Dvd Item
//set DVD Title
public void setDvdTitle(String title) {
dvdTitle = title;
} //end method set Dvd Title
//return Dvd Title
public String getDvdTitle() {
return dvdTitle;
} //end method get Dvd Title
public void setDvdStock(int stock) {
dvdStock = stock;
} //end method set Dvd Stock
//return dvd Stock
public int getDvdStock() {
return dvdStock;
} //end method get Dvd Stock
public void setDvdPrice(double price) {
dvdPrice = price;
} //end method setdvdPrice
//return DVD Price
public double getDvdPrice() {
return dvdPrice;
} //end method get Dvd Price
//calculate inventory value
public double value() {
return dvdPrice * dvdStock;
} //end method value
public String toString() {
return String.format("item=%3d title=%-20s units=%3d price=$%6.2f value=$%7.2f",
dvdItem, dvdTitle, dvdStock, dvdPrice, value());
}
} //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 value = getDvdPrice() * getDvdStock();
value = 1.05 * value; //5% restocking fee automatically calculated
return value;
} //end method value
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;
Inventory() {
dvds = new DVD[10];
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.getDvdTitle().compareTo(dvds[position-1].getDvdTitle()) < 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
class GUI extends JFrame {
/*Following Decalres Labels ,TextBoxes,Buttons and Panels that are used in the gui
*
*
*
*
*
*/
private JLabel item;
private JLabel title;
private JLabel stock;
private JLabel price;
private JLabel entireValue;
javax.swing.JTextArea ta = new javax.swing.JTextArea(10,20);
{
ta.append("\nThe inventory contains " + count + " DVDs\n");
}
for (int i = 0; i < count; i++)
ta.append("%3d %s\n", i, dvds[i]);
ta.append("\nThe total inventory value is $%.2f\n\n", entireValue());
javax.swing.JFrame frame = new javax.swing.JFrame();
frame.getContentPane().add(new javax.swing.JScrollPane(ta));
frame.pack();
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
}