• Post Reply Bookmark Topic Watch Topic
  • New Topic

need advice on assignment  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am supposed to make a LibraryCard

this is the example
Owner Library Card Details:
- - - - - - - - - - - - - - - - -
Name: Insert Name
Email: Insert Email
Books borrowed: Insert Number

and the LibraryCard Diagram is in the attachment

need some advice or help




Capture.PNG
[Thumbnail for Capture.PNG]
 
Rancher
Posts: 779
19
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't wait to start, review your notes and materials, plan what you need to do for the assignment, don't expect us to do the assignment for you.

Load the JDK locally, and I like NetBeans, you probably will too.

Learn how to use the debugger, it will be one of your best friends in program development when you need to debug.

When you have code, post some and ask for specific help, we will be glad to help you with your assignments, but I already have my programming degree from a major university and over 25 years of experience, I don't need to earn yours for you.
 
Saloon Keeper
Posts: 3330
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Show us what you've got so far. When you get stuck, ask specific questions.
 
Sheriff
Posts: 4931
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

The diagram picture you attached is your friend. There are various types of them: use case, class diagrams, activity, communication, sequence and many more. In short - all programs should start from there, as it helps to visualize program design, relations, anyway, lets get back to your question.

Here you have fragment of class diagram, this fragment basically shows you the class representation: its name, what attributes it suppose to have, and what operations it should do.

"Operations", translating from UML language, means methods in Java. So, what you have so far is:
Class name: LibraryCard
Its attributes: owner, borrowCount
Operations/methods: LibraryCard() (<- no argument constructor), checkOut(), getNumberOfBooks(), getOwnerName(), setOwner(Student) (<- accepts arguments of type Student), printCardDetails.

Next. Each attribute suppose to have a type in Java when construct your class. So you'll have to identify them. Remember how to define the class?
Work on it in order to finish all class.
Later you'll need class Student, and basically it will be similar.

I think it is enough to start, so try to work. Please let us know if need further help.
 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Les Morgan wrote:. . . Load the JDK locally, and I like NetBeans, you probably will too. . . .
Good advice,but it is probably better for newbies to use text editors; otherwise the learning curve for the IDE is too steep and they get information overload.
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why does the checkOut() method not take any parameters? Shouldn't it be checkOut(Book b) or similar?
 
Jonah Brock
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I am not sure about the my object someone from class used that.
 
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is booksBorrowed really something that you want to represent with a String? Do you count with letters or with numbers?
 
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jonah Brock wrote:need some advice or help

First: I've rearranged your code tags so that they work properly. The '[code]' tag needs to go before your code, and the '[/code]' after it; and the easiest way to do that is to select the code with your mouse and then hit the 'Code' button. you should also use the 'Preview' button to see what your post will look like before you hit 'Submit'.

However, in answer to your question, one approach that might help is outlined here.

Winston
 
Liutauras Vilda
Sheriff
Posts: 4931
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jonah Brock wrote:I am not sure about the my object someone from class used that.
Don't rush, take your time, read the link Winston posted (I just did, there are lots of useful stuff in it, also few fun parts, so you can relax at the same time) and you likely won't need to make guesses anymore.

So what you nearly have is Student class and one other, which should not be named "Librarycard" as it is now . "LibraryCard" (C upper case) should be another class on its own, similarly as you did Student class, but not testing as it is currently.
If your intense was to test your Student class, it is OK, forgivable. What is not forgivable, NON PRIVATE fields of the class.

Lines 25, 26, 27 add word private in front of each instance variable.
Line 27, it should not be a string, consider using integer (CR already mentioned that).

Methods. Group related setters and getters together.

Does your assignment tells you anything about throwing exceptions when something goes in an unexpected way? If for instance email is invalid, or booksBorrowed is negative? - IF NOT, forget about it, might you haven't reach that topic yet.
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Why does the checkOut() method not take any parameters? Shouldn't it be checkOut(Book b) or similar?

That's a really good point. I usually treat diagrams like this as talking points, something to look at, think about, discuss, and use to discover what the REAL design should be. It's a more honest and realistic way to see them rather than as set-in-stone "design specifications".

The only UML diagram that I'd really trust is one that is automatically generated from working, tested code. And even then, I would double check the code to make sure the diagram reflected it truthfully.
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See, now Campbell has me thinking about other flaws in the diagram. Why would you have borrowCount as an attribute then? Or is it just incorrect to interpret that as a private member of the class? Maybe it can be a calculated field simply returning the length of the list of borrowed books that is built up by the checkOut method. Why is there no method to record when books are returned? What happens when the Student reports a lost book?

These are all questions whose answers will almost certainly invalidate and make obsolete the given diagram. That's why I never treat them as specifications but rather straw men that I can use to discover the real specification of the design.
 
Liutauras Vilda
Sheriff
Posts: 4931
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Probably OP has to confirm, if he was given that diagram or draw himself.
 
Les Morgan
Rancher
Posts: 779
19
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just delete them, or put them back, but without the context of what was being discussed, the post make no sense nor have any validity what so ever. BTW: I did see that you didn't remove the comments that I posted those to, so I have to conclude you moved them for political reasons that they do not agree fully with the Ranch's POV.

If they are not appropriate for the discussion they were made in, then delete them.

Junilu Lacar wrote:Les Morgan,
Your post was moved to a new topic.
(This informational message will self destruct in two days)
Splitting off due to digression / OT
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!