Library console application
Faraj — Today at 2:45 PM
I'm building this project consisting of a library app that borrows & returns books, very simple. I've been with this for 3 days and now I gave up. I decided to ask using thread instead. I'm trying to implement 2 functions that enable the user to borrow and return books. So the user should only enter a book name/ title for example "Harry Potter" and the book should be displayed followed by the rest of the information. Any hints? https://paste.mod.gg/mlprnnmurnpu/1
BlazeBin - mlprnnmurnpu
A tool for sharing your source code with the world!
13 Replies
so do you want user just input book Title and get the book details?
Exactly
I am so tired of this man
supposedly it should look like this
To borrow a book Remove a book from LibraryBooks Add it to a list called myBooks
To return a book Remove a book from a list called myBooks Add a book to Library Books
ok, i've got the idea
so what's the main concern here?
Well! I'm bad at writing logic. I've made a dictionary for the books and a user inputs + a list for the borrowed books
But I don't how to connect the all together
Basically, I need to write a logic where I could add and remove books between the dictionary and the list
A user wants to borrow a book like Harry Potter, remove it from the dictionary and add it to a myBooks list, and the opposite when returning
Do you think this a wrong way of building the project?
after looking your code, u can just use a List rather than a dictionary
may I know why were u using dictionary?
my first suggestion is create a function to iterate a list if that book is exist by getting title parameter
like TryGetBook(title, out BookClass book)
Well! I choose a dictionary just for the practicing sake. I want to learn how to use it.
oh ok all good, but for your case dictionary wont be neccessary, you can use book.id as the key
Ok! So if I use the book.id as the key, could I keep the dictionary or should I change it to a list?
list
this
u can use like this
or u can split into two
IsBookExist (return bool), GetBook(string title) return a Book obj
Ok! I haven't used this kind of code before 😆 but I can give it a try.
splitting your function is good for long term
Ok! Which function do I need to split?
.