Using a class diagram

I am having problems getting my program to work. And would be grateful of any help.
I had to follow the following class diagram:
http://i254.photobucket.com/albums/hh105/jay_pesci/screenshot.jpg
I have the following source code:
Account.java
// File: Account.java
class Account
    private double balance;
    Account( double  b ) //-double:balance
        balance = b;
    public double getBalance()
        return balance;
public void deposit(double val)
Deposit ( double d)//-double:val
     val= d;
public void withdraw()
TestAccount.java
// File: TestAccount.java
class AccountTest
   public static void main(String [] arg)
account one = new account (1300.0F); //has value
account two = new account (); // no value - balance is zeroAnd my task is:
Using the following class diagram. The method main() should instantiate two Account objects, one by use of a no-argument constructor which initialises the balance to 0.0 and another by use of a second constructor which receives 1500.00 at creation. Both objects should then make at least one call each to withdraw and deposit money using arbitrary amounts of your choice, with main() printing the balance of each to screen via calls to getBalance() using System.out following each transaction.

Ok, you described the requirements and posted some code (using the code-tag, thanks for getting that right!).
What's missing from your posting is the question.
Where do you have a problem now?
Here are some problems I see:
* you are missing the braces of main (opening brace "{" after the argument list and a closing brace "}" after the last statement
* you are missing the closing brace of the class TestAccount
* you reference a class "account" in TestAccount and the real class is called "Account" (Java is case sensitive)
* you seem to be confused regarding the declaration of deposit() (what should the line beginning with "Deposit" mean?)
I think you need to learn the basics first. Take a look at the tutorials:
http://java.sun.com/docs/books/tutorial/
When you've learned the basics (syntax, defining classes, instantiating and using objects), then the requirements aren't too hard.

Similar Messages

  • Relationships used in class diagrams

    What are the different relationship used in class diagram

    <Flame>
    Well, th emost usual relationship would be something like "parent", or occassionaly "sibling". This however does not apply if you are modelling the new Java Redneck API, where its quite normal to have relationships like "sister == mother".
    </Flame>

  • Understanding Sun Idemtity Manager using UML Class Diagrams

    If you are a Sun IdM beginner and want to quickly and logically understand the relationships between various components in Sun IDM, then you should take a look at this:
    http://objectsource.com/blogs/2010/02/understanding-sun-idm-using-uml/
    You can also download all the UML diagrams from there.
    For those of you who understand UML, you definitely know a UML class diagram is a picture worth 1000 words.
    I never remembered all of these, so I used to carry a copy of these with me to custmer requirement and design discussions.
    Whenever customer asked details that I could not recall or was not sure, I'd pull these out as a cheatsheet to confirm and further elaborate on the design approach for the Sun IdM feature implementation.
    NOTE: I am the author of that blog as well. A little background on this post -
    I wrote the blog post a few months ago and totally forgot about it.
    A few days back, I installed wordpress site stats on my blog and I was amazed to see how many people look for Google terms "Understanding Sun IdM" and end up at my blog post.
    I thought - "Hey If it was so useful to these people, then I believe it will be useful for many more" (especially developers from Java background that have turned to Sun IdM professionals)
    Hence the post here.
    A few years back, I started using Sun IdM and was absolutely unsure where to start and what relationships exist between various components. I painfully started to understand them by going through the admin console and started drawing out these diagrams. They were sitting in my vault, but I set them free a few months back.
    Had I known what I know now, I would have released it much earlier.
    Regards,
    Srikanth Shenoy
    ObjectSource - Identity Management Professionals

    playAgain() : bool
    askBet() : int
    Payout(amt: void) : void
    takeBet(amt:void) : boolThese are methods of the "Game" class, and what is inside parentheses are called parameters.
    "void" and "bool" are return types.
    public boolean playAgain()
        }In this code you have specified boolean as a return type, so you need to return a value of type bool.
    As for the void part, you don't need to return anything.
    Code should look like:
    public boolean playAgain()
             return true; //Or return false
    public void Payout ()
             int amt;
        }You need to get :int amt" in the parameters, and since its voide nothing needs to be returned.
    public void Payout (int amt)
        }

  • How to use a method in sequence diagram from a class diagram

    Hello, can someone tell me how to use the method from class diagram in sequence diagram? so far i only can add a classifier to the object lifeline but i still cannot add the method from the class...
    thx

    Now that Web Services is around, I'd look at possibly implement a Web Service call in your applet, which can then be given back any object(s) on return. Set up your server side to handle Web Service calls. In this way, you can break the applet out into an application should you want to (with very little work) and it will still function the same

  • Creating OO database objects by using class diagrams in JDeveloper

    I am new to use JDeveloper. I create UML class diagrams (using Entity Object) in JDeveloper, which has inheritances and associations, and then choose Create Database Objects... try to create oo database, but it only create some tables in the database, not any object types ... .
    What do I missed? Or I have to create those oo database objects manually?
    Thanks.

    Tony,
    You can use database object types with BC4J, but only to implement BC4J domains (these can map to object types).
    For performance reasons, it is less practical to generate a table of object types for a complete EO. Most users view the BC4J layer as the 'pure' OO model, and map to a relational datamodel for optimal performance.
    Below some steps to create a DB object type for a domain:
    You can create Oracle Object Types in the database by creating a business component domain and then forward generating the database object. Forward generation of object tables from entity objects is not supported. To forward generate an Oracle Object Type from a new domain: In the System Navigator, right click on your business component package and choose Create Domain. When the Domain Wizard opens, review the information on the Welcome page and click Next. Enter a Name and Package for the domain or accept the defaults. Select the checkbox for Domain for an Oracle Object Type. Do not select any items on the Available Types list, as you are creating a new one. Enter the name of your new type in the Selected Type field. Click Next. On the Settings page, click New. Provide a name in the New Domain Attribute box. Select the appropriate Java type a[i]Long postings are being truncated to ~1 kB at this time.

  • BC4J Audit Users Sample - How to use in a Class Diagram

    I downloaded/reviewed the BC4J sample for auditing users, and am trying to incorporate it into a Class Diagram,
    so I can explicitly show that my 'Entity' extends EntityAudit. When I create an 'EntityAuditImpl' Entity Object in the Class
    Modeller, and then try to indicate that my 'Entity' extends EntityAuditImpl, I get a null pointer exception when applying the change.
    Help! What is the proper way to express the relationship is a Class Diagram?

    Randy,
    It sounds as though you're trying to model the type of relationship where one entity object extends another one - which
    in this case isn't the right relationship. In this case only the Java classes are being extended. So if your new EO is
    called MyEO:
    EntityAuditImpl extends EntityImpl
    MyEOImpl extends EntityAuditImpl
    One way to model this relationship:
    1. Add a new entity object (MyEO) to your UML diagram
    2. On the diagram, double-click MyEO to edit your entity object
    3. In the entity object editor, select the Java page then click Extends...
    4. In the Base Classes dialog, click Browse... to the right of the Row field, and navigate to EntityAuditImpl
    5. Click OK, OK, OK to dismiss all of the dialogs.
    If you take a look at MyEOImpl.java you'll see that the class extends EntityAuditImpl.
    6. On the diagram, right-click MyEO and select Show Implementation Files. This adds MyEOImpl to the diagram.
    7. Now, right-click MyEOImpl and select Show Related Elements. This adds EntityAuditImpl to the diagram, and shows
    it as being the superclass of MyEOImpl.
    Hope this helps
    Blaise

  • Error during creating a new class diagram

    Hi everbody,
    I'm using JDeveloper 10.1.3.3.0 with ADF Faces and Toplink. I'm exposing to an error message in JDeveloper while creating a new class diagram. The error message is shown in dialog and saying "The name of the element can not be set to 'package name' as another element has got the same name in the package". I have controlled the name of the new class diagram. The name is unique in the package. Also I'm creating this new file in the package "tr.com.bilisim.class_diagram" and details part of this error message in dialog also says
    "BME-02002 : The name of the element can not be set to 'class_diagram' as another element has got the same name in the package"
    "BME-02002 : The name of the element can not be set to 'bilisim as another element has got the same name in the package"
    "BME-02002 : The name of the element can not be set to 'com' as another element has got the same name in the package"
    "BME-02002 : The name of the element can not be set to 'tr' as another element has got the same name in the package"
    As I understand from the error message, during creating a new class diagram from 'new file dialog' also tries to create the directories in relevant package (tr.com.bilisim.class_diagram).
    How can I solve this problem? Please urgent help!
    best regards...
    --baris                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    -repost
    please urgent
    --barisk                                                                                                                                                                                                                           

  • Abstract Class and polymorphism - class diagram

    Hi,
    ]Im trying to draw a class diagram for my overall system but im not too sure how to deal with classes derived from abstract classes. I'll explain my problem using the classic shape inheritance senario...
    myClass has a member of type Shape, but when the program is running shape gets instantiated to a circle, square or triangle for example -
    Shape s = new circle();
    since they are shapes. But at no stage is the class Shape instantiated.
    I then call things like s.Area();
    On my class diagram should there be any lines going from myClass directly to circle or triangle, or should a line just be joining myClass to Shape class?
    BTW - is s.Area() polymorphism?
    Thanks,
    Conor.

    Sorry, my drawing did not display very well.
    If you have MyClass, and it has a class variable of type Shape, and the class is responsible for creating MyClass, use Composition on your UML diagram to link Shape and MyClass.
    If you have MyClass, and it has a class variable of type Shape, and the class is created elsewhere, use Aggregation on your UML diagram to link Shape and MyClass.
    If you have MyClass, and it is used in method signatures, but it is not a class variable, use Depedency on your UML diagram to link Shape and MyClass. The arrow will point to Shape.
    Shape and instances of Circle, Triangle, Square, etc. will be linked using a Generalization on your UML diagram. The arrow will always point to Shape.
    Anything that is abstract (class, method, variable, etc.) should be italicized. Concrete items (same list) should be formatted normally.
    BTW, the distinction between Composition, Aggregation and Dependency will vary from project to project or class to class. It's a gray area. Just be consistent or follow whatever guidelines have been established.
    - Saish

  • Extending the UML class diagrams with JDeveloper Extensions SDK?

    Hello,
    I studied the JDeveloper Extension SDK docs, but couldn't figure out how to write extensions that support UML Diagrams.
    What I would like to do, is to pin a different data model under the class diagram view.
    Well if you can't do that. In the worst case, my extension would register with a regular class diagram and listen to its events and and refuse particular changes. It would also create or use an empty class diagram and fill in the classes and associations in it. (this is less clean but I could live with it).
    Thanks in advance for all your suggestions.
    Slawek

    By definition you can change classes through the model so I guess the problem here is that the model cannot apply updates to something that it is pointing to the the compiled version of.

  • Jato 1.2 UML Class Diagrams

    Hi All,
    I have put together some UML class diagrams for JATO 1.2. You may find them
    useful. Please let me know if you spot any errors.
    Regards,
    Dennis Parrott.
    Dennis Parrott
    Senior Consultant
    iPlanet Professional Services
    Sun Microsystems Limited
    Guillemont Park
    Camberley Mobile: +44 (0)7765 221938
    GU17 9QG Email : dparrott@i...
    iPlanet
    e-commerce solutions
    www.iplanet.com
    [Non-text portions of this message have been removed]

    Hi Dennis--
    Only we can post files for the group. We'll be happy to do so, or if you
    would rather host a public site for them, we can post a link in the group.
    (Looking forward to seeing the diagrams.)
    Todd
    ----- Original Message -----
    From: "Dennis Parrott" <dparrott@i...>
    Sent: Monday, December 17, 2001 7:41 AM
    Subject: RE: [iPlanet-JATO] Jato 1.2 UML Class Diagrams
    Note the deliberate mistake - the document was not included - actually it
    was removed - How can I publish this to the group?
    Dennis Parrott[PARA]Senior Consultant[PARA]iPlanet Professional
    Services[PARA]Sun Microsystems Limited[NL]Guillemont Park[NL]Camberley
    Mobile: +44 (0)7765 221938[NL]GU17 9QG Email :
    dparrott@i... iPlanet [PARA]e-commerce solutions
    [PARA]www.iplanet.com
    -----Original Message-----
    From: Dennis Parrott [mailto:<a href="/group/SunONE-JATO/post?protectID=114154113180127190050057203026021130134026057192209171188199">dparrott@i...</a>]
    Sent: 17 December 2001 15:35
    Subject: [iPlanet-JATO] Jato 1.2 UML Class Diagrams
    Hi All,
    I have put together some UML class diagrams for JATO 1.2. You may findthem
    useful. Please let me know if you spot any errors.
    Regards,
    Dennis Parrott.
    Dennis Parrott
    Senior Consultant
    iPlanet Professional Services
    Sun Microsystems Limited
    Guillemont Park
    Camberley Mobile: +44 (0)7765 221938
    GU17 9QG Email : dparrott@i...
    iPlanet
    e-commerce solutions
    www.iplanet.com
    [Non-text portions of this message have been removed]
    For more information about JATO, please visit:
    http://developer.iplanet.com/tech/appserver/framework/index.jsp
    Choose from 1000s of job listings!
    For more information about JATO, please visit:
    http://developer.iplanet.com/tech/appserver/framework/index.jsp

  • How to import a package in UML Class diagram

    Hi all,
    I am new to use Sun Java Studio Enterprise 8 and trying to do a project.
    In the class diagram, I have to import java.util.Observable (for my Model)and java.util.Observer classes(for my View). How can I do this?
    When I searched the forums, I saw a post and what I understood is, one should create a java package and then util package inside the java package. Now, create Observable class and drag it into util package in the Projects window.
    If I do this, the source code generator is generating a new java.util.Observable class in a new java.util.package. But, I want to use the core java.util package.
    I appreciate any help.
    regards,
    varma.

    You know man, The first time that I tried to do this, it didnt update my diagram then I read some posts and I try to update the diagram, [[rigth-click on the project's folder then you go to Tool and select Update Model from Source]], but it caused an exception then I create another project and it worked fine, so when I update my source my diagram update at the same time, I dont know why it didnt work on the other project, but I know if the project it is not synchronized with the source it will not work rigth.
    Just try to update the diagram going in to Tool select Update Model from Source, if it generets an exception, try create another project and do the same thing from the begging.
    Remember to select Tool on the menu, that is showed when you rigth-click on the folder of the project on the File Palet.
    Great Hug man.

  • How to draw class diagram in Visio 2013

    Hi All,
    Recently, I purchase a Visio 2013 Pro. I have used Visio 2010 before. In Visio 2013,
    Compared with Visio 2010, There are BIG changes in Visio 2013. I have several questions for Visio 2013.
    1. I don't know how to set in/out parameter in Visio 2013 class diagram.
    2. How to set parameter type(such as Int/String) in Visio 2013?
    3. How to add Method for a Class and set its parameters?
    And so on.
    Thank You.
    The future belongs to those who believe in the beauty of their dreams.

    Hi All,
    Recently, I purchase a Visio 2013 Pro. I have used Visio 2010 before. In Visio 2013,
    Compared with Visio 2010, There are BIG changes in Visio 2013. I have several questions for Visio 2013.
    1. I don't know how to set in/out parameter in Visio 2013 class diagram.
    2. How to set parameter type(such as Int/String) in Visio 2013?
    3. How to add Method for a Class and set its parameters?
    And so on.
    Thank You.
    The future belongs to those who believe in the beauty of their dreams.

  • JavaDoc HTML link of  classes in Java class diagram not correct

    Hi,
    I created a Java class diagram in a certain package (e.g. com.mycompany.p1) and placed some classes on this diagram from the same package and from other packages. Then I created JavaDocs. When I click on the classes in the created JavaDoc diagram, only the links of the classes in the same package as the diagram (com.mycompany.p1) wor correctly. When I click on a class outside this package I get an error message that the file is not found. It looks for the class documentation in the package of the diagram and this is obviousely wrong!
    Is there a property I missed to set or is it a bug?
    Thanks for help
    Thomas

    Hi Thomas,
    I don't use the diagrammers much, so I cannot comment on this directly; however, based on your description, it does sound like a defect. Do you have access to Oracle Support to file an SR?
    John

  • Ternary Association In a class diagram

    Hi
    Please help. I need to depict a ternary association icon between 3 Classes in my Class diagram.
    I am using Java Studio Enterprise 8's UML tool.
    The modeling palette does not make provision for this type of association.
    Is there a way to depict the ternary association icon, or is there an update for the Modeling palette in the class diagrams?
    It is the little diamond, looks the same as the decision icon.

    I filed one for neext release http://www.netbeans.org/issues/show_bug.cgi?id=79744
    It's unlikely functionality will be added in patch to jse8.

  • Practical use of UML diagramming tool....

    Hi ,
    the use of UML diagramming tool is to present the system to end user (use cases) ... like the Entity Relationship Diagram in the Oracle Designer....
    However , i 'd like to ask if the product of this tool can be used as a base to produce something else afterwards in the whole system...
    I mean that in Oacle Designer , when the analyst designs the ER Diagram and saves it to the repository... this can be used to automatically generate the tables... in the repository also and then to the database...!!!!!
    Is there analogous using UML diagramming tool....?????
    Many thanks,
    Simon

    The UML class diagram can generate Java classes and ADF Business Components.
    The Database modeler in JDeveloper can generate the database objects.
    Also when you are designing the page flow diagram you are actually building the JSF or Struts flows.
    The hands-on-lab that you can find on the right side of this page:
    http://www.oracle.com/technology/products/jdev/collateral/4gl/formsdesignerj2ee.html
    Shows off some of the model to code capabilities of JDeveloper:

Maybe you are looking for