By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,833 Members | 2,067 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,833 IT Pros & Developers. It's quick & easy.

I need to create a GUI for my Inventory Program

P: 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.

Here is my Inventory program from 1 to 3:
package inventory_part1java;

// Inventory_Part1.java
// Inventory_Part1 program reads user information for a product, display its properties and its inventory

import java.text.DecimalFormat; // program uses class DecimalFormat
import java.util.Scanner; // program uses class Scanner

public class InventoryPart1 {


public static void main(String[] args) {
// create a tool that insure the specified format for a double number, when displayed
DecimalFormat doubleFormat = new DecimalFormat( "0.00" );

// create Scanner to obtain input from command window
Scanner input = new Scanner( System.in );

int number; // stores the user DVD number
String name; // stores the user DVD name
int units; // stores the user DVDs number of units
double price; // stores the user DVD price

System.out.print( "1 " ); // prompt
System.out.flush(); //empties buffer before you input text.
number = input.nextInt(); // read product number
while ( number < 0 ) //starts while loop to make sure a positive number is entered.
{
System.out.print( "1 " ); //prompt
number = input.nextInt(); // read product number
}

System.out.print( "Hustle and Flow. " ); // prompt
System.out.flush(); //empties buffer before you input text.
input.nextLine(); //prompt user for input
name = input.nextLine(); // read product name

System.out.print( "2 " ); // prompt
System.out.flush(); //empties buffer before you input text.
units = input.nextInt(); // read product number of units
while ( units < 0 ) //starts while loop to make sure a positivSystem.out.print( "1 " ); // prompt
System.out.flush(); //empties buffer before you input text.
number = input.nextInt(); // read product number
while ( number < 0 ) //starts while loop to make sure a positive number is entered.
{
System.out.print( "1 " ); //prompt
number = input.nextInt(); // read product number
}

System.out.print( "Hustle and Flow. " ); // prompt
System.out.flush(); //empties buffer before you input text.
input.nextLine(); //prompt user for input
name = input.nextLine(); // read product name

System.out.print( "2 " ); // prompt
System.out.flush(); //empties buffer before you input text.
units = input.nextInt(); // read product number of units
while ( units < 0 ) //starts while loop to make sure a pose number is entered.
{
System.out.print( "2 units " ); //prompt
units = input.nextInt(); // read product number of units
}

System.out.print( "$13.49" ); // prompt
System.out.flush(); //empties buffer before you input text.
price = input.nextDouble(); // read product price
while ( price < 0 ) //starts while loop to make sure a positive number is entered.
{
System.out.print( "$13.49 " ); //prompt
price = input.nextDouble(); // read product price
}

// close the reading session
input.close();

// create a Product object with the user input
Product product = new Product(number, name, units, price);

// display the product's properties and its inventory

// display the product's properties and its inventory
System.out.println(product.toString() + " has inventory value = $" +
doubleFormat.format(product.inventory()) + "3");
}

}

package inventory_part3java;

// Inventory_Part3.java
// Inventory_Part3 creates an array of DVD products, ...
// displays the information and inventory for each product, sorted by title, and the entire inventory.
import java.text.DecimalFormat; // program uses class DecimalFormat
public class Inventory_Part3 {


public static void main(String[] args) {
// create a tool that insure the specified format for a double number, when displayed
DecimalFormat doubleFormat = new DecimalFormat( "0.00" );

// create an array of products with the specified length
Sub[] subs = new Sub[6];
subs[0] = new Sub(1, "DVD", 10, 10.99, "Hustle and Flow");
subs[1] = new Sub(2, "DVD", 12, 49.99, "The Best Man");
subs[2] = new Sub(3, "DVD", 30, 12.99, "Original Gangsters");
subs[3] = new Sub(4, "DVD", 16, 19.99, "Exit Wounds");
subs[4] = new Sub(5, "DVD", 19, 11.99, "Cradle to the Grave");
subs[5] = new Sub(6, "DVD", 18, 19.77, "Little Nicky");

// sort the array by name, calling the sortByName method
sortByName(subs);

// display the properties and the value of inventory for each product of the sorted array
// loop to control number of products
for (int index = 0; index < subs.length; index++)
{
System.out.println(subs[index].toString() + " Inventory Value: $" +
doubleFormat.format(subs[index].inventory()) + ".");
} // end loop to control number of products

// display the value of the entire inventory
System.out.println("\nEntire Inventory Value: $" + doubleFormat.format(entireInventory(subs)));

} // end method main

// sort an array of products send as parameter, by product's name, using Bubble Sort
public static void sortByName(Sub[] subs)
{
// loop to control number of passes
for ( int pass = 1; pass < subs.length; pass++ )
{
// loop to control number of comparisons
for ( int index = 0; index < subs.length - 1; index++ )
{
// compare side-by-side products and swap them if ...
// first product's name is greater than second product's name
if ( subs[index].getName().compareToIgnoreCase(subs[index + 1].getName()) > 0)
swap( index, index + 1, subs );
} // end loop to control comparisons
} // end loop to control passes
} // end method sortByName

// swap two products specified by their indexes in the products array, send as well as a parameter
public static void swap(int first, int second, Product[] products)
{
Product hold; // temporary holding area for swap

hold = products[ first ];
products[ first ] = products[ second ];
products[ second ] = hold;
} // end method swap

// calculate the entire inventory for the array of products send as parameter
// make it static so that it can be called from the main method, which is static too
public static double entireInventory(Sub[] subs)
{
// a temporary double variable that the method will return
// after each product's inventory is added to it
double entireInventory = 0;
// loop to control number of products
for (int index = 0; index < subs.length; index++)
{
// add each inventory to the entire inventory
entireInventory = entireInventory + subs[index].inventory();
} // end loop to control number of products
return entireInventory;
} // end method entireInventory

} // end class Inventory_Part3


I need help ASAP and be specific. Thanks
Apr 19 '08 #1
Share this Question
Share on Google+
3 Replies


Expert 100+
P: 849
We're not going to do your homework for you. Go read a Swing tutorial (Google it) and try to do it yourself, then come back with specific problems.
Apr 19 '08 #2

100+
P: 539
And don't forget to enclose your codes with codetag.

regards,
sukatoa
Apr 20 '08 #3

Expert 10K+
P: 11,448
@100grrand: I hope you realize what you have just done: you've shown (part of)
your assignement text and asked for help. Help for what? You haven't done
anything (yet); do you want us to do *your* work while it's *your* assignment?

If so I consider that cheating.

kind regards,

Jos (moderator)
Apr 20 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.