473,804 Members | 3,312 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Inventory Woes

MonolithTMA
5 New Member
Greetings all,

I am new here, and aside from my introductory post, this will be my first.

I am working on an Inventory program for a class I am taking. I've searched the forums here and have seen other people working on the same or similar projects, but the problem I run into is that in Java, there seems to be more than one way to skin a cat. (No cats were harmed in the writing of this post.)

I am able to enter multiple items and their values, and I can get the total for each item. The part I am at now is trying to add the multiple items in my array together. I've read through several chapters on arrays in several books. I've scoured the web. yet it seems I can't find it. I know I'm probably missing something simple. Any help would be appreciated. I will include my code below.

This is the class that defines the data:

Expand|Select|Wrap|Line Numbers
  1. class CDData {
  2.     String[] cdName;
  3.     int[] cdQuantity;
  4.     int[] cdNumber;
  5.     double[] invTotalValue;
  6.     double T;
  7. }
  8.  
This is the Main class:

Expand|Select|Wrap|Line Numbers
  1. import java.util.*; // Initialize scanner for user input
  2.  
  3. public class CDInventory {
  4.  
  5.     /** Creates a new instance of CDInventory*/
  6.     public CDInventory() {
  7.     }
  8.  
  9.  
  10.     public static void main(String[] args) {
  11.  
  12.         CDData onlyCDData = new CDData();
  13.  
  14.         System.out.println(""); // blank line
  15.         System.out.println("\t************************");
  16.         System.out.println("\t** Audio CD Inventory **"); // Display Title
  17.         System.out.println("\t************************");
  18.         System.out.println(); // blank line
  19.  
  20.         // Begin Input Section
  21.  
  22.         /*Ask how many CDs to input. This will give us the itteration for our Array loop. */
  23.  
  24.         boolean stop = false;
  25.         while (!stop) {
  26.             Scanner input = new Scanner( System.in ); // Load Scanner for input
  27.             System.out.println("How many audio CDs would you like to enter today? Enter 0 to quit."); // Request amount of CDs to enter.
  28.  
  29.  
  30.             int count; // enteredAmount
  31.             count = input.nextInt(); // Input amount of CDs to enter.
  32.  
  33.             /* Check for 0 */
  34.  
  35.             if ( count == 0 ) {
  36.                 System.out.println("Thank you. The program has now ended");
  37.                 System.out.println(); // blank line
  38.                 stop = true;
  39.             } else {
  40.  
  41.                 /*The amount of CDs has been decided, now we begin to gather data from the user, specific to each CD. */
  42.  
  43.  
  44.                 for (int i=0; i < count; i++) {
  45.                     /*CD Name input. */
  46.  
  47.                     onlyCDData.cdName = new String[count];
  48.                     System.out.println(); // blank line
  49.                     System.out.println("Please input new CD Name:");
  50.                     System.out.println(); // blank line
  51.                     onlyCDData.cdName[i] = input.next(); // Input CD Name
  52.                     System.out.println(); // blank line
  53.  
  54.                     /*CD number input. */
  55.  
  56.                     onlyCDData.cdNumber = new int[count];
  57.                     System.out.println("Please input the CD number:");
  58.                     System.out.println(); // blank line
  59.                     onlyCDData.cdNumber[i] = input.nextInt(); // Input CD Number.
  60.  
  61.                     /*CD quantity input. */
  62.  
  63.                     onlyCDData.cdQuantity = new int[count];
  64.                     System.out.println(); // blank line
  65.                     System.out.println("Please input the CD quantity:");
  66.                     System.out.println(); // blank line
  67.                     onlyCDData.cdQuantity[i] = input.nextInt(); // Input CD quantity
  68.  
  69.                     /*CD quantity can't be a negative number. */
  70.  
  71.                     while (onlyCDData.cdQuantity[i] < 0) {
  72.                         System.out.println("Sorry, the quantity must be a positive number.");
  73.                         System.out.println("Please input the CD quantity:");
  74.                         System.out.println(); // blank line
  75.                         onlyCDData.cdQuantity[i] = input.nextInt(); // Input CD quantity
  76.                     }
  77.  
  78.                     /*CD price input. */
  79.  
  80.                     onlyCDData.cdPrice = new float[count];
  81.                     System.out.println(); // blank line
  82.                     System.out.println("Please enter the CD price:");
  83.                     System.out.println(); // blank line
  84.                     onlyCDData.cdPrice[i] = input.nextFloat(); // Input CD price
  85.                     System.out.println(); // blank line
  86.  
  87.                     /*CD price can't be a negative number or zero. */
  88.  
  89.                     while (onlyCDData.cdPrice[i] <= 0) {
  90.                         System.out.println("Sorry, the CD price must be a positive number.");
  91.                         System.out.println("Please enter the CD price:");
  92.                         System.out.println(); // blank line
  93.                         onlyCDData.cdPrice[i] = input.nextFloat(); // Input CD price
  94.                     }
  95.  
  96.                     // End Input Section
  97.  
  98.                     // Calculate and Dis-play
  99.                     onlyCDData.invTotalValue = new double[count];
  100.                     onlyCDData.invTotalValue[i] = (double) onlyCDData.cdQuantity[i] * onlyCDData.cdPrice[i];
  101.  
  102.                     System.out.println("- - - - - - - - - -");
  103.                     System.out.println(); // blank line
  104.                     System.out.printf( "CD Number " );
  105.                     System.out.print( onlyCDData.cdNumber[i] );
  106.                     System.out.printf( " is titled:" );
  107.                     System.out.printf( " " );
  108.                     System.out.printf( onlyCDData.cdName[i] );
  109.                     System.out.printf( ". " );
  110.                     System.out.print( "There are " );
  111.                     System.out.print( onlyCDData.cdQuantity[i] );
  112.                     System.out.printf( " " );
  113.                     System.out.printf( "In stock." );
  114.                     System.out.printf( " " );
  115.                     System.out.printf( onlyCDData.cdName[i] );
  116.                     System.out.printf( "'s total inventory value is: $%,.2f\n", onlyCDData.invTotalValue[i]);
  117.                     System.out.println(); // blank line
  118.  
  119.                     if(i == count - 1) {
  120.                         //This is where I want to add all the intTotalValue's together to make up T., but I have no idea what to do.
  121.                         //onlyCDData.T = All of the onlyCDData.invTotalValue added together.
  122.                         System.out.printf( "The total inventory value of all CDs combined is: $%,.2f\n", onlyCDData.T);
  123.                         System.out.println("Thank you. The program has now ended");
  124.                         System.exit(0);
  125.                     }
  126.                 }
  127.             }
  128.         }
  129.     }
  130. }
  131.  
Now, as it is written, it works, but the last two comments indicate the part I can't figure out. Again, any help would be greatly appreciated.

Thanks in advance!

Best regards,
Mike
Jan 28 '07 #1
3 1684
MonolithTMA
5 New Member
In my zealousness to present clean, nice looking code, I managed to remove.

Expand|Select|Wrap|Line Numbers
  1. float[] cdPrice;
class CDData is actually:

Expand|Select|Wrap|Line Numbers
  1. class CDData {
  2.     String[] cdName;
  3.     int[] cdQuantity;
  4.     int[] cdNumber;
  5.     float[] cdPrice;
  6.     double[] invTotalValue;
  7.     double T;
  8. }
  9.  
Jan 28 '07 #2
Ganon11
3,652 Recognized Expert Specialist
You may want to consider using an array of CDData objects. Instead of using arrays for each value of CDs, you could have each CDData object hold the value on one CD - its name, amount, price, etc. Then, when you needed to total up the values, you would just traverse your array of CDData objects and add the corresponding element.

If you have to use the CDData class as it is now, then simply start another loop (from 0 < count) and add that invTotalValue to your overall total.
Jan 28 '07 #3
MonolithTMA
5 New Member
Thanks! I really apreciate your help.

I just added the line:

Expand|Select|Wrap|Line Numbers
  1. onlyCDData.T = (onlyCDData.T + onlyCDData.invTotalValue[i]);
and that did it!

I knew it was something simple.

So, I could make the entire class an array? That makes sense. Time to do some more reading now.

Thanks again!

Best regards,
Mike
Jan 28 '07 #4

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

Similar topics

5
3438
by: gregork | last post by:
I have painstakingly created an excel 2000 workbook for the very complex recipes I have to formulate. I have 2 sheets- 1 for configuring the recipe and 1 that is like an inventory of all the raw materials and their specifications. I have many lookup formulas on sheet1 that lookup the specs on the inventory. The problem is sheet 1 works really well but sheet 2 is not really performing as an inventory database like I want it to. The...
13
4004
by: royaltiger | last post by:
I am trying to copy the inventory database in Building Access Applications by John L Viescas but when i try to run the database i get an error in the orders form when i click on the allocate button "Unexpected Error":3251 operation is not supported for this type of object.The demo cd has two databases, one is called inventory and the other just has the tables for the design called inventory data. When you run inventory the database works...
109
25902
by: zaidalin79 | last post by:
I have a java class that goes for another week or so, and I am going to fail if I can't figure out this simple program. I can't get anything to compile to at least get a few points... Here are the assignments... 4. CheckPoint: Inventory Program Part 1 • Resource: Java: How to Program • Due Date: Day 5 forum • Choose a product that lends itself to an inventory (for example, products at your workplace, office supplies, music CDs, DVD...
0
7118
by: south622 | last post by:
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...
9
7614
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...
3
7013
by: cblank | last post by:
I need some help if someone could help me. I know everyone is asking for help in java. But for some reason I'm the same as everyone else when it comes to programming in java. I have an inventory program that I have built so far with no problem. But I cannot figure out how to turn it into a GUI application. This is what I'm trying to get it to do. Modify the Inventory Program to use a GUI. The GUI should display the information one product...
2
2545
by: pinkf24 | last post by:
I cannot figure out how to add the following: 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...
1
2665
by: jcato77 | last post by:
I need help with a class project I'm working on, Below is my assignment and the code I have currently created. Assignment: Modify the Inventory Program by creating a subclass of the product class that uses one additional unique feature of the product you chose (for the DVDs subclass, you could use movie title, for example). In the subclass, create a method to calculate the value of the inventory of a product with the same name as the method...
3
4490
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...
0
9705
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
10564
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
10320
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...
1
10308
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9134
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
7609
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
6846
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
5513
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
5645
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.