Sedang Disiapkan

226424 IT Inventory final

Inventory Program Part 5

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.

I am not picky about the logo, and generic .gif image will do.

Inventory Program Part 6

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\[url removed, login to view] 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.

This is where I am at now...but need to be at the finish line by Saturday..

import [url removed, login to view]; // program uses arrays

import java.awt.*;

import java.awt.event.*;

import javax.swing.*; // Import the java swing package

import [url removed, login to view];

import [url removed, login to view];

public class Inventory5 {

// main method begins execution of java application

public static void main(String[] args) {

[url removed, login to view]("\nCheckPoint: Inventory Part 5");

[url removed, login to view]("My DVD Collection\n");

Movie dvd = null;

Inventory inventory = new Inventory();

dvd = new Movie(1, "Live Free or Die Hard", 18, [url removed, login to view], 2001);

[url removed, login to view](dvd);

[url removed, login to view](dvd);

dvd = new Movie(2, "The Patriot", 14, [url removed, login to view], 1998);

[url removed, login to view](dvd);

[url removed, login to view](dvd);

dvd = new Movie(3, "Full Metal Jacket", 1, [url removed, login to view], 1995);

[url removed, login to view](dvd);

[url removed, login to view](dvd);

dvd = new Movie(4, "Coyote Ugly", 15, [url removed, login to view], 2003);

[url removed, login to view](dvd);

[url removed, login to view](dvd);

dvd = new Movie(5, "Apocalypto", 10, [url removed, login to view], 2006);

[url removed, login to view](dvd);

[url removed, login to view](dvd);

dvd = new Movie(6, "Monster in Law", 1, [url removed, login to view], 2005);

[url removed, login to view](dvd);

[url removed, login to view]("\nEnd of DVD collection!\n");

[url removed, login to view](dvd);

[url removed, login to view]();

new InventoryGUI(inventory);

} // end main

} // end Inventory5

class DVD {

private int itemNo;

private String title;

private int inStock;

private float unitPrice;

DVD(int itemNo, String title, int inStock, float unitPrice) {

[url removed, login to view] = itemNo;

[url removed, login to view] = title;

[url removed, login to view] = inStock;

[url removed, login to view] = unitPrice;

}

public int getItemNo() { return itemNo; }

public String getTitle() { return title; }

public int getInStock() { return inStock; }

public float getUnitPrice() { return unitPrice; }

public float value() {

return inStock * unitPrice;

}

public String toString() {

return [url removed, login to view]("itemNo=%2d title=%-22s inStock=%3d price=$%[url removed, login to view] value=$%[url removed, login to view]",

itemNo, title, inStock, unitPrice, value());

}

} // end DVD

class Inventory {

// Setup an array of Movies (set it to hold 30 items)

private final int INVENTORY_SIZE = 30;

private DVD[] items;

private int numItems;

Inventory() {

items = new Movie[INVENTORY_SIZE];

numItems = 0;

}

public int getNumItems() {

return numItems;

}

public DVD getDVD(int n) {

return items[n];

}

// Adds a Movie to the array of Movies. Adds to first empty slot found.

public void addMovie(DVD item) {

items[numItems] = item;

++numItems;

}

// Loop through our array of Movies and add up the total value.

// Go item by item adding the quantity on hand x its price.

// Add that value to a running total accumulator variable.

public double value() {

double sumOfInventory = 0.0;

for (int i = 0; i < numItems; i++)

sumOfInventory += items[i].value();

return sumOfInventory;

}

// Prints the inventory list including name, quantity, price,

// and total stock value for each item.

public void printInventory() {

[url removed, login to view]("\nShelly's DVD Inventory\n");

// If no items were found, print a message saying the inventory is empty.

if (numItems <= 0) {

[url removed, login to view]("Inventory is empty at the moment.\n");

} else {

for (int i = 0; i < numItems; i++)

[url removed, login to view]("%3d %s\n", i, items[i]);

[url removed, login to view]("\nTotal value in inventory is $%,.2f\n\n", value());

}

}

} // end Inventory

// Extends DVD class from the base class DVD

class Movie extends DVD {

// Holds movie year and adds restocking fee

private int movieYear;

// Constructor, calls the constructor of Movie first

public Movie(int MovieID, String itemName, int quantityOnHand, float itemPrice, int year) {

super(MovieID, itemName, quantityOnHand, itemPrice);

// Pass on the values needed for creating the Movie class first thing

[url removed, login to view] = movieYear;

}

// To set the year manually

public void setYear(int year) {

movieYear = year;

}

// Get the year of this DVD Movie

public int getMovieYear() {

return movieYear;

}

// Overrides value() in Movie class by calling the base class version and

// adding a 5% restocking fee on top

public float value() {

return [url removed, login to view]() + restockingFee();

}

// Simply gets the base class's value, and figures out the 5% restocking fee only

public float restockingFee() {

return [url removed, login to view]() * [url removed, login to view];

}

} // end Movie

// GUI for the Inventory

// Contains an inventory of DVD's and lets the user step through them one by one

class InventoryGUI extends JFrame

{

// access inventory for DVD Collection

private Inventory theInventory;

// index in the inventory of the currently displayed DVD.

// the index starts at 0, goes to the number of DVDs in the inventory minus 1

private int index = 0;

// GUI elements to display currently selected DVD information

private final JLabel itemNumberLabel = new JLabel(" Item Number:");

private JTextField itemNumberText;

private final JLabel prodnameLabel = new JLabel(" Product Name:");

private JTextField prodnameText;

private final JLabel prodpriceLabel = new JLabel(" Price:");

private JTextField prodpriceText;

private final JLabel numinstockLabel = new JLabel(" Number in Stock:");

private JTextField numinstockText;

private final JLabel valueLabel = new JLabel(" Value:");

private JTextField valueText;

private final JLabel restockingFeeLabel = new JLabel(" Restocking Fee:");

private JTextField restockingFeeText;

private final JLabel totalValueLabel = new JLabel(" Inventory Total Value:");

private JTextField totalValueText;

private JPanel centerPanel;

private JPanel buttonPanel;

// constructor for the GUI, in charge of creating all GUI elements

InventoryGUI(Inventory inventory) {

super("Shelly's Movie Inventory");

final Dimension dim = new Dimension(140, 20);

final FlowLayout flo = new FlowLayout([url removed, login to view]);

JPanel jp;

// create the inventory object that will hold the product information

theInventory = inventory;

// setup the GUI

// product information

// setup a panel to collect all the components.

centerPanel = new JPanel();

[url removed, login to view](new BoxLayout(centerPanel, BoxLayout.Y_AXIS));

buttonPanel = new JPanel();

JButton firstButton = new JButton("First");

[url removed, login to view](new FirstButtonHandler());

[url removed, login to view](firstButton);

JButton previousButton = new JButton("Previous");

[url removed, login to view](new PreviousButtonHandler());

[url removed, login to view](previousButton);

JButton nextButton = new JButton("Next");

[url removed, login to view](new NextButtonHandler());

[url removed, login to view](nextButton);

JButton lastButton = new JButton("Last");

[url removed, login to view](new LastButtonHandler());

[url removed, login to view](lastButton);

JButton addButton = new JButton("Add");

[url removed, login to view](new AddButtonHandler());

[url removed, login to view](addButton);

JButton deleteButton = new JButton("Delete");

[url removed, login to view](new DeleteButtonHandler());

[url removed, login to view](deleteButton);

JButton modifyButton = new JButton("Modify");

[url removed, login to view](new ModifyButtonHandler());

[url removed, login to view](modifyButton);

JButton saveButton = new JButton("Save");

[url removed, login to view](new SaveButtonHandler());

[url removed, login to view](saveButton);

JButton searchButton = new JButton("Search");

[url removed, login to view](new SearchButtonHandler());

[url removed, login to view](searchButton);

[url removed, login to view](buttonPanel);

jp = new JPanel(flo);

[url removed, login to view](dim);

[url removed, login to view](itemNumberLabel);

itemNumberText = new JTextField(3);

[url removed, login to view](false);

[url removed, login to view](itemNumberText);

[url removed, login to view](jp);

jp = new JPanel(flo);

[url removed, login to view](dim);

[url removed, login to view](prodnameLabel);

prodnameText = new JTextField(17);

[url removed, login to view](false);

[url removed, login to view](prodnameText);

[url removed, login to view](jp);

jp = new JPanel(flo);

[url removed, login to view](dim);

[url removed, login to view](prodpriceLabel);

prodpriceText = new JTextField(17);

[url removed, login to view](false);

[url removed, login to view](prodpriceText);

[url removed, login to view](jp);

jp = new JPanel(flo);

[url removed, login to view](dim);

[url removed, login to view](numinstockLabel);

numinstockText = new JTextField(5);

[url removed, login to view](false);

[url removed, login to view](numinstockText);

[url removed, login to view](jp);

jp = new JPanel(flo);

[url removed, login to view](dim);

[url removed, login to view](restockingFeeLabel);

restockingFeeText = new JTextField(17);

[url removed, login to view](false);

[url removed, login to view](restockingFeeText);

[url removed, login to view](jp);

jp = new JPanel(flo);

[url removed, login to view](dim);

[url removed, login to view](valueLabel);

valueText = new JTextField(17);

[url removed, login to view](false);

[url removed, login to view](valueText);

[url removed, login to view](jp);

// add the overall inventory information to the panel

jp = new JPanel(flo);

[url removed, login to view](dim);

[url removed, login to view](totalValueLabel);

totalValueText = new JTextField(17);

[url removed, login to view](false);

[url removed, login to view](totalValueText);

[url removed, login to view](jp);

// add the panel to the GUI display

setContentPane(centerPanel);

repaintGUI();

setDefaultCloseOperation(EXIT_ON_CLOSE);

setSize(420, 480);

setResizable(false);

setLocationRelativeTo(null);

setVisible(true);

}

// (re)display the GUI with current product's information

public void repaintGUI() {

Movie temp = (Movie) [url removed, login to view](index);

if (temp != null) {

[url removed, login to view]("" + [url removed, login to view]());

[url removed, login to view]([url removed, login to view]());

[url removed, login to view]([url removed, login to view]("$%.2f", [url removed, login to view]()));

[url removed, login to view]([url removed, login to view]("$%.2f", [url removed, login to view]()));

[url removed, login to view]("" + [url removed, login to view]());

[url removed, login to view]([url removed, login to view]("$%.2f", [url removed, login to view]()));

}

[url removed, login to view]([url removed, login to view]("$%.2f", [url removed, login to view]()));

}

class FirstButtonHandler implements ActionListener {

public void actionPerformed(ActionEvent e) {

index = 0;

repaintGUI();

}

}

class PreviousButtonHandler implements ActionListener {

public void actionPerformed(ActionEvent e){

int numItems = [url removed, login to view]();

index = (--index) % numItems;

repaintGUI();

}

}

class NextButtonHandler implements ActionListener {

public void actionPerformed(ActionEvent e) {

int numItems = [url removed, login to view]();

index = (++index) % numItems;

repaintGUI();

}

}

class LastButtonHandler implements ActionListener {

public void actionPerformed(ActionEvent e) {

int numItems = [url removed, login to view]();

index = (numItems -1) % numItems;

repaintGUI();

}

}

class AddButtonHandler implements ActionListener {

public void actionPerformed(ActionEvent e){

repaintGUI();

}

}

class SaveButtonHandler implements ActionListener {

public void actionPerformed(ActionEvent e){

repaintGUI();

}

}

class ModifyButtonHandler implements ActionListener {

public void actionPerformed(ActionEvent e){

repaintGUI();

}

}

class DeleteButtonHandler implements ActionListener {

public void actionPerformed(ActionEvent e){

repaintGUI();

}

}

class SearchButtonHandler implements ActionListener {

public void actionPerformed(ActionEvent e){

repaintGUI();

}

}

} // End InventoryGUI class

Kemahiran: Semua Boleh, Java

Lihat lebih lanjut: program full movie, stock logo free, step create logo, set create logo, search system icon, search string array, print println java, perform line, object free, new company logo search, need logo creating, monster search, monster company, metal company logo, logo movies company, logo data base, int i, implements set, icon previous next, icon collection, icon add free, icon 3d, get company logo name, get company logo free, generic data access

Tentang Majikan:
( 1 ulasan ) Colorado Springs,

ID Projek: #1972662

Dianugerahkan kepada:

webprof2

Pls Chk PMB.

$50 USD dalam sehari
(114 Ulasan)
5.7