I am pretty new to Java and have a question about where to begin with my program.
The assignment is 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 the value of the entire inventory.
• Create another method to sort the array items by the name of the product.
Here is my code
I am really struggling where to start.
On the array side, would I use the array only to store the item name, or would the array need to include the other features?
I am confused since an array can only hold the same data type and don't think that the assignment is asking me to use multiple arrays.
Thanks for any pointers.
2 2061 Nepomuk 3,112
Recognized Expert Specialist
...
I am really struggling where to start.
On the array side, would I use the array only to store the item name, or would the array need to include the other features?
I am confused since an array can only hold the same data type and don't think that the assignment is asking me to use multiple arrays.
Thanks for any pointers.
You're right, an array can only hold data of the same type. However, who says that type has to be String?
First of all, think about how you would do it in the real world. There are two possibilities: Either you have an Index of all Items (e.g. Name and position) and a Collection of the items or you just have a Collection of the items themselves, including everything at once.
Each Item (it was a DVD, right?) has certain Values: a name, a language, a length... what ever is important for your tast. Then think about how you can put that information into one big lump and have an array of those "lumps".
That should be enough to bring you on the right track, I guess.
Greetings,
Nepomuk
Thanks for the pointer, you got me back on track!
You're right, an array can only hold data of the same type. However, who says that type has to be String?
First of all, think about how you would do it in the real world. There are two possibilities: Either you have an Index of all Items (e.g. Name and position) and a Collection of the items or you just have a Collection of the items themselves, including everything at once.
Each Item (it was a DVD, right?) has certain Values: a name, a language, a length... what ever is important for your tast. Then think about how you can put that information into one big lump and have an array of those "lumps".
That should be enough to bring you on the right track, I guess.
Greetings,
Nepomuk
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: kf4pfw |
last post by:
Hi:
I have a form with 4 arrays in it. Each array can contain up to 11
elements.
I am using the following code (this is for proof of concept):
<?
if($submit) {
|
by: csx |
last post by:
Hi everyone!
two quick questions relating to arrays.
Q1,
Is it possible to re-assign array elements?
int array = {{2,4}, {4,5}};
array = {2,3}
|
by: Canonical Latin |
last post by:
"Leor Zolman" <leor@bdsoft.com> wrote
> "Canonical Latin" <javaplus@hotmail.com> wrote:
>
> > ...
> >But I'm still curious as to the rational of having type
> >pointer-to-array-of-size-N-of-type-T (which is fine) and not having type
> >array-of-size-N-of-type-T (with some exceptions, which is curious).
> > So far
> >the consensus seems to be that while everyone is aware of this no one
knows
|
by: Samee Zahur |
last post by:
Back in the days of old C, only numeric literals could be used as
dimensions for statically allocated arrays - the size had to be
resolved to a constant at/before compile time. Now I'm beginning to
suspect(!) that this is no longer the case either with C or with C++ :(
Can anyone upgrade me with the present state/version of rules? (for
C++)
Exactly, by how many years am I back-dated ???
|
by: Charles Banas |
last post by:
i've got an interesting peice of code i'm maintaining, and i'd like to
get some opinions and comments on it, hopefully so i can gain some
sort of insight as to why this works.
at the top of the function (which was translated from Fortran code),
among other heinous and numerous declarations, is this bit:
static float bbuff;
static int bkey;
static int buse;
| |
by: Paul Morrison |
last post by:
Hi all,
I need to come up with some differences between arrays in Java and C, I have
searched Google and so far all I have found is the following:
Arrays in Java are reference types with automatic allocation of memory. In
C, arrays are groups of variables of the same type in adjacent memory.
Allocation for dynamic arrays is handled by the programmer.
This is an 8 mark question in an old exam paper, so I am assuming there are
|
by: Frederic Soustra |
last post by:
Hi,
I am trying to speed up some work I have to do with a 3D Matrix.
If I am not mistaken, C is row major,
hence the matrix
A of size 2 x 2 x 2
would be stored like this in memory:
A,A,A,A,A,A,A,A
?
Am I correct, I need to work on Big 3D matrices, and I know that the way
|
by: Rene Nyffenegger |
last post by:
Hello everyone.
I am not fluent in JavaScript, so I might overlook the obvious.
But in all other programming languages that I know and that
have associative arrays, or hashes, the elements in the
hash are alphabetically sorted if the key happens to
be alpha numeric. Which I believe makes sense because
it allows for fast lookup of a key.
|
by: mike3 |
last post by:
(I'm xposting this to both comp.lang.c++ and comp.os.ms-
windows.programmer.win32
since there's Windows material in here as well as questions related to
standard
C++. Not sure how that'd go over at just comp.lang.c++. If one of
these groups is
too inappropriate, just take it off from where you send your replies.)
Hi.
|
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: 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: 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: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |