473,738 Members | 2,645 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need help on Java Inventory Program Part 5

1 New Member
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:
ProductWithLeng th inventory[] = new ProductWithLeng th[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.sho wInputDialog("O ffice 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.sho wInputDialog("P lease enter the product name:\n\n");

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

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

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

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

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

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

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

// Instantiate a ProductWithLeng th to hold this inventory item:
ProductWithLeng th p1 =
new ProductWithLeng th(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.sho wMessageDialog( null,
"No products were entered into the inventory.\n" +
"Unable to display output.",
"No Products Entered",
JOptionPane.ERR OR_MESSAGE);
}
else
{
// There are some products in inventory...

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

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

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

// Loop through inventory items and display info about each:
for (int i=0; i < numItems; i++)
{
JOptionPane.sho wMessageDialog(
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].getRestockingF ee()) + // 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.INF ORMATION_MESSAG E);
}

// Display total inventory value:
JOptionPane.sho wMessageDialog( null,
String.format(" Value of entire inventory is $%,.2f\n", Inventory.calcE ntireValue(inve ntory, numItems)),
"Total Inventory Value",
JOptionPane.INF ORMATION_MESSAG E);
}

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

} // end method main

// Trim inventory array to specified size:
public static ProductWithLeng th[] trimInventoryAr ray(ProductWith Length[] inventory, int numItems)
{
ProductWithLeng th[] returnVal = new ProductWithLeng th[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 sortInventoryBy Name(Product[] inven)
{
Arrays.sort(inv en);
}

} // end class Inventory
_______________ _______________ _______________ _______________ ______
Dec 12 '06 #1
0 7114

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

Similar topics

38
4233
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 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 the item number, the name of the product, the number of units in stock, the price of each...
3
2136
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 Product.java, when you compile it a .class is created for every class in the file Product.java if there are no errors. In this case you are getting this error because there is no class file called Product.class so you must compile the Product class...
3
3587
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 use the previos two. I've gotten all of this code oto compile but I'm still doing something wrong. I'm about to pull my hair out! When I run my CDInventoryDisplay program it comes back with this error: C:\Documents and Settings\Sam>java...
3
4747
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 even sure if the way I've written this is going to work but anyway, I keep getting a compilation error that says: C:\Documents and Settings\Sam\GUICDInventory.java:22: cannot find symbol symbol : constructor JList(CDInventory) location: class...
1
2823
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 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. the...
9
7609
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 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 output should display the value of the entire inventory. • Create a method to calculate...
11
7697
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 workplace, office supplies, music CDs, DVD movies, or software). • Create a product class that holds the item number, the name of the product, the number of units in stock, and the price of each unit. • Create a Java application that displays the...
3
4486
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 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...
2
4446
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 reading has very little in it that helps can someone take a look at this code and point me in the right direction please. Thanks for any help that is offered. //Modify the Inventory Program to use a GUI. The GUI should display the //informationone...
0
8968
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9473
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9334
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9208
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8208
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6750
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6053
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4569
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4824
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.