GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes Need Help with Java...Just 1 line... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Need Help with Java...Just 1 line..." Watch "Need Help with Java...Just 1 line..." New topic
Author

Need Help with Java...Just 1 line...

Leeee Ming
Greenhorn

Joined: May 24, 2004
Posts: 12
I am doing a small java program and i am almost 99% done and i'm stuck at a particular part, since not sure how to code....

Here is the scenario of my School Work...

Mr. Tan, a Networking facilitator purchased 15 network routers. These network equipments will be loaned to students during their class. Besides these routers, there are other equipments that he has purchased. Mr. Tan would like to devise a system to keep track of these assets.


He has designed an asset code to be tagged to each asset. The asset code is a string of 12 characters consisting of alphanumeric characters.

99 � 99999 � AAA
Category Serial Department
Number Code

The 2-digit asset category identifies the type of asset. There are currently 2 categories of assets. They are 01 for tools & Consumables and 02 for network devices. The 5-digit serial number uniquely identifies each piece of asset under a category.

Mr. Tan approached you for help to develop a Java asset tracking program. He would like the design of the program to be modular with appropriate classes defined to store and track different assets


This is the above mentioned problem....




My java codes which i have written have the following methods :

Create a new Asset

View all the Assetcodes

View all assets...

View no of assets

view asset by Category...

"Most Important" = Need to use the Java Iterator to process the entire list of assets so as to search for duplicate asset codes...

This is where i am stuck..


Thanks a LOT in Advance
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
0) Rewrite your code to use a class Asset which you keep in a List instead of separate Lists of every field.
1) Create a new empty HashMap.
2) Create a new empty List to hold the duplicates
2) iterate over the List, retrieving assets.
2a) if the assetcode of the current asset doesn't exist as a key in the HashMap, add a new element to it with the assetcode as key and the asset as value.
2b) else add the asset to the List of duplicates

If you construct your Asset and Assets classes correctly, the search for duplicates becomes as simple as:


At the end 'duplicates' will contain all duplicate Assets so you can do something with them.


42
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Leeee Ming, it would be nice if you were to edit your post to break those really long lines, in order to alleviate viewers' needs to scroll horizontally.

Moving this to the Intermediate forum...
[ July 13, 2004: Message edited by: Dirk Schreckmann ]

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
GeeCON Prague 2014
 
subject: Need Help with Java...Just 1 line...