• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Java program based in UML class diagram

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know how to do the operation or the third partition of the UML class diagram.
our teacher haven't taught us this yet but he already gave us the activity.
Please please help. this isn't the only activity they gave us and its all due in the same day.
this is the operation part:

+ stetItemName(String newItemName): void
+ setTotalCost(int quantity, double price): void
+ getItemName(): String
+ getTotalCost(): double
+ readInput(): void
+ writeOutput(): void



 
Marshal
Posts: 74004
332
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can't see any relation between that code and the question you posted. It must be in different code. One thing I can see is far too much code in the main() method.
 
Angle Kuniyoshi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i also don't know how to do with this
 
Campbell Ritchie
Marshal
Posts: 74004
332
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Haevn't you been taught the structure of a class, how it contains fields, methods, and constructors? The UML diagram tells you which methods your class should have.
 
Angle Kuniyoshi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry but i dont think he taught us that last school year
 
Angle Kuniyoshi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:I can't see any relation between that code and the question you posted. It must be in different code. One thing I can see is far too much code in the main() method.



Im sorry im so dumb but what do you mean by this
 
Saloon Keeper
Posts: 8578
71
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In UML these things are defined for a particular Class. What is the Class your UML shows? Why does it not appear in your code?
 
Angle Kuniyoshi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It doesnt because i dont know how to do it. im sorry
It says here that the writeOutput() should display this:
You are purchasing 3 shoes at 1999.50 each.
 
Carey Brown
Saloon Keeper
Posts: 8578
71
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can surmise from the names of the methods that the class name is probably "Item". At any rate, this would be good enough to use for now until you find out what that proper class name is.

So it sounds like you need to create an "Item" class and within implement each of those methods.

Note that implementing a method and calling a method are two different things. You were in the process of calling the methods in your main() method.

You also seem to have requirements you're not showing us. Where did you find out that:

It says here that the writeOutput() should display this:
You are purchasing 3 shoes at 1999.50 each.

 
Carey Brown
Saloon Keeper
Posts: 8578
71
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We normally frown on screen snapshots here but it might be useful if you could post a screen snapshot of your UML diagram.
 
Angle Kuniyoshi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is actually the activity. i dont know if i should post this or not but im just really desperate. im so sorry. please help me.

how do i code the void ones?

Exercise2  |
__________________________________________________|
- itemName: String  |
- itemPrice: double  |
- itemQuantity: int  |
- amountDue: double  |
__________________________________________________|
+ stetItemName(String newItemName): void  |
+ setTotalCost(int quantity, double price): void  |
+ getItemName(): String  |
+ getTotalCost(): double  |
+ readInput(): void  |
+ writeOutput(): void  |
__________________________________________________|

Note: The readinput() method will be used to accept user input through the Scanner class. This is
done by:
a. Writing import java.util.*; on top of the code, before the line for the class name
b. Instantiating an object of the Scanner class, Scanner s = new Scanner (System.in);
C. Storing the input to the variable name based on data type
For String: s.nextLine()
For int: s.nextInt()
For double: s.nextDouble()
The writeOutput() method will be used to display an output similar to the sample below.

You are purchasing 3 bag(s) at 1999.5 each.


Sample output:

Enter the name of the item you are purchasing.
bag
Enter the quantity and price separated by a space.
3 2000.50
You are purchasing 3 bag(s) at 2000.5 each.
Amount due is 6001.50
 
Carey Brown
Saloon Keeper
Posts: 8578
71
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
 
Carey Brown
Saloon Keeper
Posts: 8578
71
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Show us what you have so far for your Item class.
 
Angle Kuniyoshi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Carey Brown
Saloon Keeper
Posts: 8578
71
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
 
Saloon Keeper
Posts: 24295
167
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
UML was an absolute "must have" back around the beginning of the Millennium, but I'm not sure how popular it is any more. UML diagrams are great if you want to wallpaper a cubicle with acres of printout, but they don't illustrate relative importance of the objects that they define and they don't have any indication as to what the object methods and properties they illustrate are actually good for aside from whatever you can infer from their names.

So what we have is that you've been given the template for an un-named Java class (or classes)  and it sounds like there were additional specs we haven't seen. So we can supply suggestions, but not very good ones. For that we need more information.
 
Angle Kuniyoshi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry but what item class?
 
Carey Brown
Saloon Keeper
Posts: 8578
71
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm guessing that this is the UML for a class called "Item" because it has things in it like "itemName", etc..


Lines 2-5 specify the fields you need to provide and lines 7-12 specify the methods you need to provide.

 
Angle Kuniyoshi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
where should i put that here

 
Carey Brown
Saloon Keeper
Posts: 8578
71
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What you have in main() should go into one of the methods as specified in your requirements, not main(). Whether you keep a Main class or just add a main() method to your Item class is up to you, but I don't think you should start there. Fill out the Item class according to your UML and requirements.
 
Saloon Keeper
Posts: 1277
38
Eclipse IDE Postgres Database C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:UML was an absolute "must have" back around the beginning of the Millennium, but I'm not sure how popular it is any more. UML diagrams are great if you want to wallpaper a cubicle with acres of printout, but they don't illustrate relative importance of the objects that they define and they don't have any indication as to what the object methods and properties they illustrate are actually good for aside from whatever you can infer from their names.

So what we have is that you've been given the template for an un-named Java class (or classes)  and it sounds like there were additional specs we haven't seen. So we can supply suggestions, but not very good ones. For that we need more information.



OP: I agree, you need to share some more information for people to effectively help you.  EDIT -- Carey has provided some great feedback and direction.

Not for the OP, but regarding the Utility or Lack Thereof of UML Usage...
I mostly agree, but the excellent book by the excellent Martin Fowler, hopefully this link is okay or I will correct it:
https://www.amazon.com/UML-Distilled-Standard-Modeling-Language/dp/0321193687/

bends over backwards and then completes the backflip to stand upright again to say that if approached as some kind of High Ceremony Religion, UML can be worse than useless.

If it is used selectively and thoughtfully in the ways and places that it clarifies understanding, including what is helpful to this end and excluding what is not and just clutters, it can be a great tool to help show organizations and relationships, and give visuals of various kinds of selected details that don't jump out as well from code.

One would hope that the world took this to heart, since his book had those pretty glowing three-dimensional designs projecting out of the cover into a strip, but perhaps not everyone got the message.

Regardless, if the OP has this assignment due, hopefully they won't interpret the criticism as a recommendation to tell their instructor that they are dumb and wasting the time of the students, but just as a "okay, learn this and pass your course, but UML isn't as useful as we once thought, unless applied selectively where it actually aids understanding."

Now, from the feeling I get of "those places" and "you" (Tim H.), there exist few to no places that overemphasize production and maintenance of "correct UML diagrams" all over a project, "just because" that you would want to work at, or want to keep working at once you got there.  I would take over-adherence to "UML For Everything" as a sign that I was at someplace Big and Stodgy that emphasizes Bureaucracy (not the excellent Douglas Adams game!) over making good things, but there are many other things I would consider worse about a culture.  If none of those other bad things applied, I might well choose to work there and they might choose to hire me, and I would break out my book with the shiny, flashy, pretty 3-d cover and write and maintain UML for them as part of my job.

I tend to agree with Martin Fowler that those who insist on using UML everywhere, always, to document every square inch of their project are Bureaucratic Process Geeks.  Those that eschew it always, never using any of the diagram types even when one would actually quite well illustrate some aspect of the system that is hard to glean from the code, would be thought of as people who "Throw Out Babies With Bathwater" because used in the right places at the right times, with the right details included and the right ones excluded, they are downright nifty.

That book is also very short, something he is very proud of.  There existed too many Long Books filled with too many details, and no Short Books, that taught you how it can actually improve your life.

My allusions to it are almost as long as his book.

Lastly, UML because it is "Just One Thing" is infinitely preferable to the Giant Zoo of different Notations that existed before it.  Then every different Bureaucratic Team was using visualizations that were different from the last place you worked, and the one before, and the next place you'd go to.  I feel less urge to avoid places that Love UML than similar places in the past where you had to keep learning different ways to show the same thing, instead of (hopefully) spending the time to show the relevant things that Aid Comprehension after determining which they were.
 
Campbell Ritchie
Marshal
Posts: 74004
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:. . . I'm not sure how popular it is any more. . . .

Does anybody miss it?
 
Tim Holloway
Saloon Keeper
Posts: 24295
167
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jesse Silverman wrote:... if approached as some kind of High Ceremony Religion, UML can be worse than useless.


It appears that in my hometown a rather large and famous corporation had an ambitious project in the works right when UML was at its peak. They had a 2-year deadline. Apparently they spent about 18 months of it drawing UML Actor diagrams, realized time was running out, panicked and hacked it out instead. Sounds like Fred Brooks account of the IBM OS/360 project.

Jesse Silverman wrote:...
If it is used selectively and thoughtfully in the ways and places that it clarifies understanding, including what is helpful to this end and excluding what is not and just clutters, it can be a great tool to help show organizations and relationships, and give visuals of various kinds of selected details that don't jump out as well from code.


The problem was, it wasn't used selectively and thoughtfully. Rational Rose was designed to be a full-lifecycle tool where first you designed the classes, then you filled in the code based on stubs that were generated from the UML, Then as maintenance was done on the system, changes to the code were reverse-engineered to create update UML.
In other words, Yet Another Silver Bullet.

Because EVERYTHING was diagrammed, you had forests rather than trees, and yes, it did make excellent cubicle wallpaper. Sometimes it could extend all the way down a row of cubicle exteriors. Every component of the system, no matter how trivial was part of this process and, as I said, there was no way to highlight the major stuff relative to the minor stuff.

And, incidentally, Rational was pretty expensive as software design systems go. Buying a personal copy for home use was something one would think long and hard about.

The is, incidentally, an open-source UML tool designed by tigris (who also brought you the SVN plugin for IDEs, I believe). It's called ArgoUML and it's written in Java. A commercial version was known as Poseidon. I've actually used it mostly for swimlane diagrams, not for flow charting or class mapping.

What I miss most is IBM's HIPO diagrams. HIPO (Hierarchy plus Input/Process/Output) was used extensively in their program product logic manuals, especially for the OS components and it had 2 parts: a hierarchy diagram that showed the calling relations between proceduress and the IPO diagram that showed chronologically an abstraction of the flow of control and data movement for a system. It was designed pre-OOP, so it's not as useful these days. But then again, neither are flowcharts.

Flowcharts, in fact, are something I almost never use except when I'm illustrating high-level processing for system documents, where instead of a fancy flowcharting app I generally use a structured drawing program. OOP means that a lot of the traditional clarification tools are not necessary. Flowcharts in particular, since any method long enough to need charting is too long for OOP. And the built-in outlining and cross-referencing tools in modern IDEs mean that you can have an up-to-date view of how things are put together without getting graphical about it.
 
Marshal
Posts: 16591
277
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have the books and even the old IBM certification for it but in the 20 or so years since, I have never used the diagrams in any significant or meaningful way. You can get a lot of billable time making the diagrams though, that's for sure but that's just a really techie way to twiddle your thumbs. Sorry if that sounds cynical because it is. Plus the way students are shown how UML diagrams are used (including OP's example) is totally divorced from the reality of good, pragmatic practice.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic