aspose file tools*
The moose likes Beginning Java and the fly likes Assignment Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Assignment" Watch "Assignment" New topic
Author

Assignment

M Desmond
Greenhorn

Joined: Feb 02, 2001
Posts: 3
Hello friends
I am new at java and it is only 15 days that I statred it, I am finding it very interesting and my objective is to clear SCJP.
Anyway I need your help for an assignment in which I have to access a specific book in a library having 5 different rooms and each room having 5 different shelves and each shelve containing 50 books
I was asked to use multidimensional arrays
I know about multidimensional arrays but I am not clear about the designing this programm
Your help is appreciated
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Well you have to know where to get the book, so you will need to take in parameters of some sort. This can either be a parameter from the command line when you call your program-
java FindBook room shelf bookNum //use the args[0] value of main() to get room, args[1] to get shelf and args[2] bookNum
or you can put code in your main() method to get input from the screen using system.in

Once you know where the book is, look it up in your array, print out the name.
(Unless of course I have this whole thing backwards, and you have to search for a name and print out the location?)


"JavaRanch, where the deer and the Certified play" - David O'Meara
M Desmond
Greenhorn

Joined: Feb 02, 2001
Posts: 3
Thanks for your reply
I have to access a book by hardcoding its number in the println statement, I dont need to take input from the keyboard, therefore I think I have to make 3 multidimensional arrays like this
M Desmond
Greenhorn

Joined: Feb 02, 2001
Posts: 3
Thanks for your reply
I have to access a book by hardcoding its number in the println statement, I dont need to take input from the keyboard, therefore I think I have to make 3 multidimensional arrays like this
String [][] rooms ={{"room1"},{"room2"},{"room3"},{"room4"},{"room5"}};
String [][] shelves= {{"shelf1"},{"shelf2"},{"shelf3"},{"shelf4"},{"shelf5"}};
And Similarly for the books containing 250 total book
Now I have to access a particular book say SC2210 which is lying in room number 2 and shelf number4 .
Give me some suggestion for this
Thanks

Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Actually I was thinking that you would use ONE array with 3 dimensions.
The first dimension is the room, the second dimension is the shelf and the third dimension is the bookNumber.
to load it up you would need to use some loops.

To get a book you when you know the location of the room and shelf, since the index is one less than the room number for room 2 shelf 4 you would look in bookLocation[1][3][x]
It sort of looks like you have to search the 250 books for the one with the number you were given (since CS2210 doesn't fit my above load pattern).



Of course maybe I am oversimplifying and you have to search for the room and shelf also.

[This message has been edited by Cindy Glass (edited February 04, 2001).]
[This message has been edited by Cindy Glass (edited February 04, 2001).]
 
wood burning stoves
 
subject: Assignment