Since you have a constructor that takes in all arguments you could just make the no argument constructor use that constructor with "" as the argument for each position. That is -. Rather than making a readEntry method to read an Entry you could override the object's toString method in a similar fashion.
This would give you more flexibility in future e. Since the value entries keeps a count of all the Entry objects made you could make it a static variable in the Entry class. A getter method like getEntries usually returns the thing that you claim it is getting.
Since you are just returning the length of the contents array size would be a better name for that method. The remove method was tricky to follow at first. You have a loop independent conditional in the loop. This suggests that the conditional shouldn't be in the loop in the first place otherwise you're doing unnecessary checks on a method that runs through the length of the contents array anyway.
Furthermore, it seems to be doing the same assignment as the first statement in you method. I can't tell why. If you re doing that to make a blank entry at the end in the case that the last element is deleted then put it just above the line where you decrement entries. On that note, I think making contents an ArrayList would have saved you a lot of the work you're doing in the removal process. Also it would be more practical to either split edit into different edit functions editEmail , editName etc.
It seems more likely that you'd only want to edit a few details at a time for a contact people don't usually change their names. The sort method is quadratic and seems to be doing a lot of work that you could do with java Collections. You could rewrite to look like this:.
The AddressBook2 class is a lot of boilerplate code so it's fine for the most part. I would personally split long print functions into different void functions.
Otherwise this is good if done only after a moth of Java. Side note The link you provided was to the wrong project, but they are right next to each other. I scanned through the website that you are learning from, and the project Address book is found in the ArrayList section but there is no reference to the ArrayList type.
Not to be harsh, but if I was the teacher I would be requesting a re-write. Using inner classes can very rarely be useful. This is not one of those cases. Entry has a proper place in the project as you use it as a data model.
The Book class itself will become very easy and clean when you switch to ArrayList. For instance if you decided to use lambdas and kept using the number to sort your entries your code would look something like this in your switch. However passing in an integer to the sort method is not very clear. What I mean is that, without looking at your code can you tell me what number is needed to sort by for each property in Entry? Nor would I want to. Even if you were to put a good comment that described very clearly what each number represented, it's still not clean.
Enough on that. Even if it was used, this would be a bad place for it. You are referencing theStudents[studentIndex] twice in that statement, to get to the same student instance's borrowedBooks and bookCount fields. Instead, imagine finding the student, and telling that student to add the book to its list. Sign up to join this community.
The best answers are voted up and rise to the top. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams?
Learn more. A student library program in Java Ask Question. Asked 3 years, 2 months ago. Active 1 year ago. Viewed 32k times. Update Book Quantity.
Search a Book with its Serial number. Search Books With Author Name. Show all Books and their related Information. Registering a Student. Show All Registered Students. You can also see the Books which a Student has Checked Out only while checking in Note: At the time it can store only 50 books for simplicity in program. I have created this program to the best of my ability.
I'm a beginner, so I couldn't do more. Improve this question. Kh Ahmed Kh Ahmed 1 1 gold badge 2 2 silver badges 8 8 bronze badges. Add a comment. Active Oldest Votes. What is that magic number 50? Can we get rid of it? You can get rid of flag , and use the findBySerialNo we created above MIT License. Branches Tags. Could not load branches. Could not load tags. Latest commit.
Git stats 7 commits. Failed to load latest commit information.
0コメント