Hey there everyone, I am currently working on and Assignment that is due tonight and I feel like I am close but can not exactly get to the end. I would appreciate any feedback possible. Kinda stuck at the moment.
---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.
---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
That is what I must finish and I will post the code I have so far beneath this.
{package prg215inv;
/**
*
* @author Cripop
*/
public class SpecialDVD extends DVD
{
static int length() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
static Object get(int i) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
private String movieTitle;// title of the movie
//Initialize constructor
public SpecialDVD(int number, String name, int total, double price, String gen, String title)
{
super(number, name, total, price, gen);
movieTitle = title;
}
//Method calculates the value for the amount of DVDs times the price per DVD
public double getValue()
{
return dvdAmount * dvdPrice*1.05;
}
/**
* @return the movieTitle
*/
public String getMovieTitle()
{
return movieTitle;
}
/**
* @param movieTitle the movieTitle to set
*/
public void setMovieTitle(String movieTitle)
{
this.movieTitle = movieTitle;
}
}
package prg215inv;
/**
*
* @author Cripop
*/
public class DVD implements Comparable<DVD>
{
static int length() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
static Object get(int i) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
public int dvdNumber; //product number
public String dvdName; // product name
public int dvdAmount; //product in stock
public double dvdPrice; // price per unit
public String genre;// Genre of the movie
//Initialize constructor
public DVD(int number, String name, int total, double price, String gen)
{
dvdNumber = number;
dvdName = name;
dvdAmount = total;
dvdPrice = price;
genre = gen;
}
//Method sets string genre
public void setgenre(String gen)
{
genre = gen;
}
//Method returns string genre
public String getgenre()
{
return genre;
}
//Method sets dvdNumber
public void setdvdNumber(int number)
{
dvdNumber = number;
}
//Method returns dvdNumber
public int getdvdNumber()
{
return dvdNumber;
}
//Method sets dvdName
public void setdvdName(String name)
{
dvdName = name;
}
//Method returns dvdName
public String getdvdName()
{
return dvdName;
}
//Method sets dvdAmount
public void setdvdAmount(int total)
{
dvdAmount = (total = 0);
}
//Method returns dvdAmount
public int getdvdAmount()
{
return dvdAmount;
}
//Method sets dvdPrice
public void setdvdPrice(double price)
{
dvdPrice = (0);
}
//Method returns dvdPrice
public double getdvdPrice()
{
return dvdPrice;
}
//Method calculates the value for the amount of DVDs times the price per DVD
public double getValue()
{
return dvdAmount * dvdPrice;
}
//Method calculates the re-stocking fee
//Helen: added
public int compareTo(DVD o)
{
return this.getdvdName().compareToIgnoreCase(o.getdvdName());
}
}
package prg215inv;
/**
*
* @author Cripop
*/
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Arrays;
public class dvdInv
{
//Sets this the main method
public static void main(String args[])
{
//Array containing the DVDs and all information pulled from the other "class"
DVD[] object1 = new DVD[4]; //Helen: modified
object1[0] = new DVD(1734, "Rambo", 20, 19.99, "Action");
object1[1] = new DVD(1254, "Coach Carter", 15, 19.99, "Drama");
object1[2] = new DVD(1137, "Star Wars", 8, 24.99, "Sci-Fi");
//Helen: a special DVD
object1[3] = new SpecialDVD(1138, "Star Wars 5", 8, 24.99, "Sci-Fi", "Super DVD"); //Helen: added
//Print or "write" line
System.out.println("Dvds we have in Stock");
calculateInventory(object1);
}
public static void calculateInventory(DVD[] dvdList){
double totalValue = 0;
Arrays.sort(dvdList);
//For loop counter to go through the array until it has gone through every element once
for (int i = 0; i < dvdList.length; i++)
{
System.out.println(dvdList);
// All print lines pulling information from the other class and it's methods.
System.out.printf("%s %d \n", "Product number: ",
dvdList[i].getdvdNumber());
System.out.printf("%s %s \n", "Dvd Name is:",
dvdList[i].getdvdName());
System.out.printf("%s %d \n", "Amount in stock:",
dvdList[i].getdvdAmount());
System.out.printf("%s %.02f \n", "Price per dvd : $",
dvdList[i].getdvdPrice());
System.out.printf("%s %.02f \n", "Price for all in inventory : $",
dvdList[i].getValue());
System.out.printf("%s %s \n", "The Genre is:",
dvdList[i].getgenre());
totalValue += dvdList[i].getValue();
}
System.out.printf("**************The entire inventory value is %.02f********",
totalValue);
}
}
package prg215inv;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
/**
*
* @author Cripop
*/
public class Gui extends JFrame {
private DVD object1;
int currentIndex = 0;
JTextField itemnumber = new JTextField();
JTextField name = new JTextField();
JTextField amount = new JTextField();
JTextField price = new JTextField ();
JTextField valueOfEntireInventory = new JTextField();
JButton next = new JButton("Next");
JButton previous = new JButton ("Previous");
public Gui(SpecialDVD specialdvd){
super("GUI Assignment");
this.object1 = object1;
setLayout(new FlowLayout());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
previous.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
showPrior();
}
private void showPrior() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
});
next.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
showNext();
}
private void showNext() {
throw new UnsupportedOperationException("Not supported yet.");
}
});
}
}
I am having a hard part grasping the GUI part that I need to get to display the Array with. Thanks!