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: -
class CDData {
-
String[] cdName;
-
int[] cdQuantity;
-
int[] cdNumber;
-
double[] invTotalValue;
-
double T;
-
}
-
This is the Main class:
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
3 1684
In my zealousness to present clean, nice looking code, I managed to remove.
class CDData is actually: -
class CDData {
-
String[] cdName;
-
int[] cdQuantity;
-
int[] cdNumber;
-
float[] cdPrice;
-
double[] invTotalValue;
-
double T;
-
}
-
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.
Thanks! I really apreciate your help.
I just added the line: - 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
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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...
|
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...
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
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...
|
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...
| |
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...
|
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,...
|
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...
|
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...
|
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();...
|
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...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |