Terminé

195580 Java home work

I have three assignment that I need to do for the last two weeks of my class this is thwe code that I have.

1) 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.

• Post as an attachment/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

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.

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.

*/

package javaapplication5;

import [url removed, login to view];

import [url removed, login to view];

import [url removed, login to view];

import [url removed, login to view];

import [url removed, login to view];

import [url removed, login to view];

import [url removed, login to view];

import [url removed, login to view];

import [url removed, login to view];

import [url removed, login to view];

import [url removed, login to view];

import [url removed, login to view];

import [url removed, login to view];

import [url removed, login to view];

import [url removed, login to view];

import [url removed, login to view];

import [url removed, login to view];

import [url removed, login to view];

import [url removed, login to view];

import [url removed, login to view];

import [url removed, login to view];

import [url removed, login to view];

/**

*

* author Owner

*/

public class Main {

/**

* param args the command line arguments

*/

public static void main(String[] args) {

// TODO code application logic here

}

//Program that displays the invantory of DVD's

// Class that represents a product in an inventory

class Product implements Comparable

{

private int itemnum; // class variable that stores Product number

private double prodprice; // class variable that stores tprice of the product

private int numinstock; // class variable that stores the number of product in stock

private String prodname; //class variable for the name of the product

public Product() // Default constructor for the Product

{

itemnum = 0;

prodprice = 0.0;

numinstock = 0;

}

// Constructor

public Product(int theItemNumber, double theProductPrice, int theNumberInStock, String theProductName) {

[url removed, login to view] = theItemNumber;

[url removed, login to view] = theProductPrice;

[url removed, login to view] = theNumberInStock;

[url removed, login to view] = theProductName;

}

public void setItemNum(int num) // Method to set the Product number

{

itemnum = num;

}

public int getitemnumber() // Method to get the Product number

{

return itemnum;

}

public void setprodprice(double prod) // Method to set the Price of the product

{

prodprice = prod;

}

public double getprodprice() // Method to get the Price of the product

{

return prodprice;

}

public void setnuminstock(int numstock) // Method to set the Price of the product

{

numinstock = numstock;

}

public int getnuminstock() // Method to get the Price of the product

{

return numinstock;

}

public void setprodname(String name) // Method to set the name of the product

{

prodname = name;

}

public String getprodname() // Method to get the name of the product

{

return prodname;

}

public double calculateValue() // Method to calculate the value of the product inventory

{

return prodprice * numinstock;

}

// the compareTo method is used to implement the Comparable interface. This enables us to sort a list of Products using [url removed, login to view]()

// this method returns -1, 0, or 1 depending on if the compared to object should appear before, the same, or after the current item

public int compareTo(T o); (Object o)

{

Product p = (Product) o;

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

}

// returns a string representation of the product

Override

public String toString()

{

return "Product Name : " + getprodname() + "\n"

+ "Product Number : " + getitemnumber() + "\n"

+ "Product Price : " + [url removed, login to view]([url removed, login to view]).format(getprodprice()) + "\n"

+ "Number in Stock : " + getnuminstock() + "\n"

+ "Value : " + [url removed, login to view]([url removed, login to view]).format(calculateValue());

}

public int compareTo(Object o) {

throw new UnsupportedOperationException("Not supported yet.");

}

}//end class Product

// Extend the Product class to represent an office supply with a manufacturer and a restocking fee

class DVD extends Product {

// Manufacturer of the DVDs being added

private String manufacturer;

// Restocking fee as percentage to add to inventory value

private double restockingFee;

// initialize an empty DVDs object

public DVD () {

super();

// the default restocking fee is 5%

[url removed, login to view] = 0.05;

}

// initialize an DVDs object with the given information

public DVD(int theItemNumber, double theProductPrice, int theNumberInStock, String theProductName, String theManufacturer) {

// call the Product constructor

super(theItemNumber, theProductPrice, theNumberInStock, theProductName);

// and fill in the extra details about an DVDs

[url removed, login to view] = theManufacturer;

// the default restocking fee is 5%

[url removed, login to view] = 0.05;

}

// getter and setter for the DVD's Manufacturer

public void setManufacturer(String theManufacturer)

{

[url removed, login to view] = theManufacturer;

}

public String getManufacturer()

{

return manufacturer;

}

// calculates the restocking fee of the DVD's based on a percentage of the value

public double getRestockingFee() // Figures restocking fee of inventory

{

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

}

// include a restocking fee in the inventory's value

Override

public double calculateValue() // Figures total inventory value including restocking fee

{

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

}

// returns a string representation of the item

Override

public String toString()

{

return "Product Name : " + getprodname() + "\n"

+ "Manufacturer : " + getManufacturer() + "\n"

+ "Product Number : " + getitemnumber() + "\n"

+ "Product Price : " + [url removed, login to view]([url removed, login to view]).format(getprodprice()) + "\n"

+ "Number in Stock : " + getnuminstock() + "\n"

+ "Restocking Fee : " + [url removed, login to view]([url removed, login to view]).format(getRestockingFee()) + "\n"

+ "Value : " + [url removed, login to view]([url removed, login to view]).format(calculateValue());

}

}

// Class that represents a collection of DVDs objects

class Inventory {

// place to store all the DVDs in the inventory

DVDs[] inventory;

// create an initially empty inventory capable of holding different DVDs

public Inventory( )

{

inventory = new DVDs [0];

}

// add the DVDs to the end of the inventory

public void addDVDs(DVDs new_DVDs)

{

// create a new array of DVDs that can hold one more than the current array of DVDs

DVDs[] new_inventory = new DVDs[[url removed, login to view]() + 1];

//copy all the old ones to the front of the new array

for (int i = 0; i < [url removed, login to view](); i++) {

new_inventory[i] = inventory[i];

}

// add the new DVDs to the end of the new array

new_inventory[[url removed, login to view]()] = new_DVDs;

// replace the old inventory with the new one

inventory = new_inventory;

}

// return the DVD's at the location index in the inventory

public DVD getDVD(int index)

{

return inventory[index];

}

// return the number of DVD's in the inventory

public int getSize()

{

return [url removed, login to view];

}

// run through all the DVD's in the inventory, and add up their value.

public double getTotalValueOfAllInventory()

{

double tot = 0.00;

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

{

tot += inventory[i].calculateValue();

}

return tot;

}

// sort the DVD in the inventory by movie title

public void sortInventory()

{

[url removed, login to view](inventory, 0, getSize());

}

}

// GUI for the Inventory

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

class InventoryGUI extends JFrame

{

// create inventory for the DVD's

private Inventory theInventory;

// index in the inventory of DVD's.

// the index starts at 0, goes to the number of Different DVD's in the inventory minus 1

private int index = 0;

// GUI elements to display currently selected DVD's 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 manufacturerLabel = new JLabel("Product Manufacturer: ");

private JTextField manufacturerText;

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 JLabel totalValueText;

// setup the buttons in the GUI

// go to the next product in the list

private Action nextAction = new AbstractAction("Next")

{

public void actionPerformed(ActionEvent evt) {

// go forward one product

index++;

// check to see if there is a next product

if ( index == [url removed, login to view]() ) {

// if we're at the last product in the list, then we can't go any further forward

// so we wrap around to the beginning

index = 0;

}

repaint();

}

public void actionPerformed(ActionEvent e) {

throw new UnsupportedOperationException("Out of stock.");

}

};

private JButton nextButton = new JButton(nextAction);

// go the previous product in the list

private Action previousAction = new AbstractAction("Previous") {

public void actionPerformed(ActionEvent evt) {

index--;

// if the user hits previous at the first product in the list, then loop back to the last product

if (index < 0) {

index = [url removed, login to view]() - 1;

}

repaint();

}

};

public JButton getFirstButton() {

return firstButton;

}

public void setFirstButton(JButton firstButton) {

[url removed, login to view] = firstButton;

}

private JButton previousButton = new JButton(previousAction);

// advance to the first product in the list

private Action firstAction = new AbstractAction("First") {

public void actionPerformed(ActionEvent evt) {

index = 0;

repaint();

}

};

private JButton firstButton = new JButton(firstAction);

// advance to the last product in the list

private Action lastAction = new AbstractAction("Last") {

public void actionPerformed(ActionEvent evt) {

index = [url removed, login to view]() - 1;

repaint();

}

};

private JButton lastButton = new JButton(lastAction);

// Add the product to the underlying inventory object

public void addDVDToInventory(OfficeSupply temp)

{

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

sortInventory();

repaint();

}

// sort the items in the underlying inventory object

public void sortInventory()

{

[url removed, login to view]();

repaint();

}

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

public InventoryGUI()

{

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

theInventory = new Inventory();

// setup the GUI

// add the next button to the top of the GUI

// setup a panel to collect all the buttons in a GridLayout with 1 row and 4 columns

JPanel buttonPanel = new JPanel(new GridLayout(1, 4, 0, 4));

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

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

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

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

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

// product information

// setup a panel to collect all the components in a GridLayout with 8 rows and 2 columns.

JPanel centerPanel = new JPanel(new GridLayout(8, 2, 0, 4));

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

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

itemNumberText = new JTextField("");

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

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

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

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

prodnameText = new JTextField("");

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

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

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

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

manufacturerText = new JTextField("");

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

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

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

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

prodpriceText = new JTextField("");

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

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

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

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

numinstockText = new JTextField("");

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

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

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

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

restockingFeeText = new JTextField("");

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

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

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

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

valueText = new JTextField("");

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

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

// add the overall inventory information to the panel

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

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

totalValueText = new JLabel("");

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

// setup the logo for the GUI

URL url = [url removed, login to view]().getResource("[url removed, login to view]");

Image img = [url removed, login to view]().getImage(url);

// scale the image so that it'll fit in the GUI

Image scaledImage = [url removed, login to view](205, 300, Image.SCALE_AREA_AVERAGING);

// create a JLabel with the image as the label's Icon

Icon logoIcon = new ImageIcon(scaledImage);

JLabel companyLogoLabel = new JLabel(logoIcon);

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

// add the logo to the GUI

getContentPane().add(companyLogoLabel, [url removed, login to view]);

// add the panel to the center of the GUI's window

getContentPane().add(centerPanel, [url removed, login to view]);

}

// Get the GUI to show up on the screen

public void showGUI() {

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

[url removed, login to view]();

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

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

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

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

repaint();

}

// repaint the GUI with current product's information

Override

public void repaint() {

DVD's temp = [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]() );

[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]() ) );

}

} // End InventoryGUI class

// Program that displays the value of products in the inventory.

class DVDInventoryPart5

{

private static Object myItem;

public static void main( String args[] ) throws IOException

{

// create Scanner to obtain input from command window

BufferedReader input = new BufferedReader(new InputStreamReader([url removed, login to view]) );

//Instantiate a GUI Inventory object

InventoryGUI myInventoryGUI = new InventoryGUI();

// change this to false to do command line input

if ( true ) {

[url removed, login to view]'sToInventory( new DVD's( 1, 19.99, 3, "A-C", "D-F") );

[url removed, login to view]'s( new DVD's( 2, 19.99, 2, "H-K", "L-O") );

[url removed, login to view]'s( new DVD's( 3, 19.99, 1, "P-R", "S-T") );

[url removed, login to view]'s( new DVD's( 4, 19.99, 10, "U-W", "X-Z") );

} else {

//Print out a screen title

[url removed, login to view]("Inventory Program\n\n");

// we're going to keep asking for user input until the user enters stop for an item name

while(true) {

//Instantiate a new DVD object each time we could get input from the user

DVD's myItem = new DVD's();

[url removed, login to view]( "Enter the name of product or the word stop: " ); // prompt for input

myItem .setproduct name([url removed, login to view]());// read item name or stop

// if the user entered stop for the item name, then quit the loop

if ( [url removed, login to view]().equalsIgnoreCase("stop") ) {

break;

}

//Enter Item number

[url removed, login to view]( "Enter the Item number: " ); // prompt for input

int itemNumber = [url removed, login to view]([url removed, login to view]()).intValue();

[url removed, login to view](itemNumber);// read item number

// while loop to repeat the entry of the item number until a positive value is entered

while ([url removed, login to view]()<=0.0)

{

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

[url removed, login to view]("Please enter a positive Item Number:");

[url removed, login to view]([url removed, login to view]([url removed, login to view]()).intValue()); // read Item number

}

// Enter Number of Items in Stock

[url removed, login to view]("Enter number of Items in Stock: ");

[url removed, login to view]([url removed, login to view]([url removed, login to view]()).intValue()); // read Number of Items in Stock

// while loop to repeat the entry of Items in stock until a positive value is entered

while ([url removed, login to view]() <= 0.0)

{

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

[url removed, login to view]("Please enter a positive Number in Stock unless out of stock:");

[url removed, login to view] instock([url removed, login to view]([url removed, login to view]()).intValue()); // read Item number

}

// Enter price of the Item

[url removed, login to view]( "Enter the price of the item: " ); // prompt for input

[url removed, login to view]([url removed, login to view]([url removed, login to view]()).doubleValue()); // Read price of the DVD

// while loop to repeat the entry of Items in stock until a positive value is entered

while ([url removed, login to view]()<=0.0)

{

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

[url removed, login to view]("Please enter a positive Item Price:");

[url removed, login to view]([url removed, login to view]([url removed, login to view]()).doubleValue()); // read Item Price

}

// Enter manufacturer of the Item

[url removed, login to view]( "Enter the manufacturer of the item: " ); // prompt for input

[url removed, login to view]([url removed, login to view]()); // Read manufacturer name of the DVD

[url removed, login to view]();

// add the newly created object to the existing inventory

[url removed, login to view]'sToInventory(myItem);

} // end while

}

// Now that all the DVD's have been added to the inventory object myInventory, sort them by their name

[url removed, login to view]();

// Display the inventory of DVD's on the screen, one DVD at a time

[url removed, login to view]();

} // end method main

} // end class InventoryPart5

}

Compétences : Tout va bien, Java

en voir plus : work out of the home, work out of home, work out from home, work home data entry no fee, work from no home system, work from home work at home, work from home with at&t, work from home west, work from home tools, work from home temp, work from home program, work from home on line, work from home office setup, work from home no fee, work from home net, work from home java, work from home image, work from home editor, work from home directory, work from home data entry no fee

Concernant l'employeur :
( 1 commentaire )

Nº du projet : #1941801

Décerné à:

kudretserin

Hi, I am Sun Certified Java Programmer and would like to help you to do your assignment. I did this kind of job before for other students and they got very good grade. You can take a look at my reviews. I have a wor Plus

%selectedBids___i_sum_sub_4% %project_currencyDetails_sign_sub_5% USD en 1 jour
(112 Commentaires)
5.2