473,385 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Need help on Java Inventory Program Part 5

I'm taking a beginning Java course and I'm stuck in week eight of a nine week course. If anyone could help me I would greatly appreciate it. This assignment was due yesterday and each day I go past the due date 10% of the grade is taken off. I think I'm coming down with the flu and my brain is just not processing this assignment.

Here is the assignment:

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.

// Week Seven: Inventory.java
// CheckPoint: Inventory Program Part 5
// Author: Glinda Ellisor
// December 10, 2006

/*

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 tiem should display. Add a company logo to the GUI using Java graphics classes.

*/

import java.util.*;
import javax.swing.*;
import java.awt.event.*;
import java.text.*;

public class Inventory
{
// This constant is the max # of inventory items:
public static final int maxItems = 10000;

// main() method begins execution of a Java application:
public static void main( String args[] )
{
// This flag will control whether we exit the loop below:
boolean stop = false;

// This array will hold the entire inventory:
ProductWithLength inventory[] = new ProductWithLength[maxItems];

// This counter will count the number of items in the inventory:
int numItems = 0;

// Loop until user indicates to exit the app:
while (!stop)
{
// Show title, and read product number and store in memory:
String itemNumber =
JOptionPane.showInputDialog("Office Supply Inventory Program.\n\n " +
"Please enter a new product number or press Cancel to end this program: "
);

// Check for user clicking Cancel:
if (itemNumber == null)
{
// User clicked Cancel, set flag so we'll exit:
stop = true;
}
else
{
// User did not click Cancel, so continue reading info for this iteration...

float unitAmount = -1; // Number of units
String unitAmountStr = ""; // String representation of # of units
float price = -1; // Price of unit
String priceStr = ""; // String representation of price
float value; // Value of units multiplied by price
int length = -1; // Length of product
String lengthStr = ""; // String representation of length

// Prompt for and read product name:
String productName =
JOptionPane.showInputDialog("Please enter the product name:\n\n");

// Prompt for and read number of units, until a positive
// value is entered:
while (unitAmount <= 0)
{
unitAmountStr = JOptionPane.showInputDialog(
"Please enter the number of units (value must be greater than 0):\n\n");

try
{
unitAmount = Float.parseFloat(unitAmountStr);
}
catch(Exception ex)
{
}
}

// Prompt for and read price per unit, until a positive
// value is entered:
while (price <= 0)
{
priceStr = JOptionPane.showInputDialog(
"Please enter the price per unit (value must be greater than 0):\n\n");

try
{
price = Float.parseFloat(priceStr);
}
catch(Exception ex)
{
}
}

// Prompt for and read length, until a positive
// value is entered:
while (length <= 0)
{
lengthStr = JOptionPane.showInputDialog(
"Please enter the length per unit (value must be greater than 0):\n\n");

try
{
length = Integer.parseInt(lengthStr);
}
catch(Exception ex)
{
}
}

// Now we know units, price and length are positive values.

// Instantiate a ProductWithLength to hold this inventory item:
ProductWithLength p1 =
new ProductWithLength(itemNumber, productName, unitAmount, price, length);

// Add this Product to the inventory array:
inventory[numItems] = p1;

// Increment item counter:
numItems++;
}
}

// User has indicated to exit application...

// Check for empty inventory:
if (numItems == 0)
{
// No products in inventory...
JOptionPane.showMessageDialog(null,
"No products were entered into the inventory.\n" +
"Unable to display output.",
"No Products Entered",
JOptionPane.ERROR_MESSAGE);
}
else
{
// There are some products in inventory...

// Trim the inventory array of all but actual Product objects:
inventory = trimInventoryArray(inventory, numItems);

// Sort the inventory array by product name:
sortInventoryByName(inventory);

// Display output for entire inventory...
JOptionPane.showMessageDialog(null,
"Thank you for your input.\n" +
"Please press OK for inventory display.",
"Stop Request Received",
JOptionPane.INFORMATION_MESSAGE);

// Loop through inventory items and display info about each:
for (int i=0; i < numItems; i++)
{
JOptionPane.showMessageDialog(
null,
// Product info:
"Product Number: " + inventory[i].getitemNumber() + "\n" + // product #
"Product Name: " + inventory[i].getproductName() + "\n" + // product name
"Units in stock: " + inventory[i].getunitAmount() + "\n" + // # units
"Length: " + inventory[i].getLength() + "\n" + // length
String.format("Price of each unit: $%,.2f\n", inventory[i].getunitPrice()) + // unit price
String.format("Restocking fee: $%,.2f\n", inventory[i].getRestockingFee()) + // restocking fee
String.format("Inventory value is $%,.2f\n", inventory[i].calculateValue()), // inventory value
"Item #" + (i+1) + " of " + numItems, // this is the window title
JOptionPane.INFORMATION_MESSAGE);
}

// Display total inventory value:
JOptionPane.showMessageDialog(null,
String.format("Value of entire inventory is $%,.2f\n", Inventory.calcEntireValue(inventory, numItems)),
"Total Inventory Value",
JOptionPane.INFORMATION_MESSAGE);
}

// Display ending message:
JOptionPane.showMessageDialog(null,
"Thank you for using the Office Supply Inventory Program!",
"Adios!",
JOptionPane.PLAIN_MESSAGE);

} // end method main

// Trim inventory array to specified size:
public static ProductWithLength[] trimInventoryArray(ProductWithLength[] inventory, int numItems)
{
ProductWithLength[] returnVal = new ProductWithLength[numItems];

for (int i=0; i < numItems; i++)
{
returnVal[i] = inventory[i];
}

return returnVal;
}

// Calculate the value of the entire inventory.
public static float calcEntireValue(Product[] inven, int numItems)
{
float value = 0;

// Loop through products and add their values to the total:
for (int i=0; i < numItems; i++)
{
value += inven[i].calculateValue();
}

return value;
}

// Sort the inventory array by product name:
public static void sortInventoryByName(Product[] inven)
{
Arrays.sort(inven);
}

} // end class Inventory
__________________________________________________ ________________
Dec 12 '06 #1
0 7086

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

Similar topics

38
by: JenniferT | last post by:
OK, so I'm very new to Java programming and I've been able to squeek by so far, but I'm completely stuck on this assignment. Here is the assignment that is due this week - • Modify the Inventory...
3
by: ITQUEST | last post by:
The moderator posted this in another thread: (I am starting a new one not to confuse the other subject at hand) ".java classes are compiled to into .class files. If you have a .java file called...
3
sammyboy78
by: sammyboy78 | last post by:
Hello again, This time I'm creating a program that creates an array of CD objects and then displays the information. I've created a CD class, a CDInventory class and then a CDInventoryDisplay to...
3
sammyboy78
by: sammyboy78 | last post by:
I'm trying to display an array of objects using a GUI. My instructions are that the CD class and it's sublcass don't need to change I just need to modify class CDInventory to include the GUI. I'm not...
1
by: twin2003 | last post by:
need help with inventory part 5 here is what I have to do 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...
9
by: xxplod | last post by:
I am suppose to modify the Inventory Program so the application can handle multiple items. Use an array to store the items. The output should display the information one product at a time, including...
11
by: hamiltongreg | last post by:
I am new to Java and am having problems getting my program to compile correctly. My assignment is as follows; Choose a product that lends itself to an inventory (for example, products at your...
3
by: 100grand | last post by:
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...
2
by: blitz1989 | last post by:
Hello all, I'm new to this forum and Java and having a alot of problems understanding this language. I am working on an invetory program part 4. The assignment requirements are listed but the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.