Java package - money

good evening guys,
i am finding a piece of work extremely tough going at the moment and wondered if i could get any hints/help on where im going wrong. i am aiming to produce a package (money.java) which could be used in order to produce arithmetic calculations on sums of money.
The code i have at the moment is:
MONEY.JAVA:
package java;
public class money
     private int data1, data2;
     public money()
         data1=0;
         data2=0;
     public money(int value1, int value 2)
          data1 = value1;
          data2 = value2;
    public void addMoney(int value1, int value2)
          return value1 + value2;
     public void subtractMoney(int value1, int value2)
          return value1 - value2;
     public void divideMoney(int value1, int value2)
          return value1 / value2;
     public void multiplyMoney(int value1, int value2)
          return value1 * value2;
}MONEYTEST.JAVA
import java.money;
public class MoneyTest
    public static void main(String [] args)
         money p = new money(10,20);
         System.out.println("The total is " + p.addMoney());
}I think i may need a 'toString' method? and also, is there any way of covering errors? im sorry if these problems are trivial. I have various books, but can't seem to use them in this case.
Thank you for any feedback.
Jess

That's a class, not a pakcage.
Do you need a toString? There's already a toString defined on Object that you inherit. It's not very useful though. If you want to show something more meaningful when you do, say, System.out.println(aMoneyObject); then yes, you'll need to override toString.
http://developer.java.sun.com/developer/Books/effectivejava/Chapter3.pdf
What are data1 and data2? Those are meaningless names and you never use them.
As for handling errors,
http://java.sun.com/docs/books/tutorial/essential/exceptions/index.html
It's not clear what you're trying to accomplish, and your questions are rather vague, so it's difficult to provide useful advice.

Similar Messages

  • Import Java package in JSP

    I hope this is an appropriate forum for this query.
    I want to be able to access a user-created Java package in JSP.
    I have this code:
    <%@page import="TPClass.*" %>
    <%
    xxx = TPClass
    session.setAttribute("response",xxx.GetTPResponse());
    %>
    The error display points to TPClass in the import statement with the message "TPClass not found".
    TPClass files are in the same location as the other project files.
    I have creatyed and compiled the TPClass package.
    Is there more I need to do?
    Brenton

    I think you are very new to java....
    anyway
    <%@page import="class name with full qualified package name"%>
    like
    <%@page import="com.x1.x2.TPClass"%>
    <%
    TPClass cls =new TPClass();
    //then do whatever you want...
    %>
    hope u understand now.....

  • JAVA PACKAGES and JSP

    i Have two problems one is i am designing a website which consists of a form. I am trying to write the Connectiviy and all other insert statements in seperate java packages and include them in JSP files.
    i Have two java packages one is DBUtil(having two java files both dealing with connectovity) and another one is StudentUtIl which has java files that open the connections with database connection and insert data into DB., I am having a big Problem here. How can i call the function in the other java package in the files in this java package. i have openDB()and Close() in the other Db and i want to call these functions in JAVA classes in the other package. How to include a package. Both these packages are in the same File system mounted on a Local directory

    Thank you for the reply. I am giving the code i have given the full class name . and now it is giving the following error :
    Cannot reference a non-static method connectDB() in a static context.
    I am also giving the code. Please do help me on this. i am a beginner in java.
    import java.sql.*;
    import java.util.*;
    import DButil.*;
    public class StudentManager {
    /** Creates a new instance of StudentManager */
    public StudentManager() {
    Connection conn = null;
    Statement cs = null;
    public Vector getStudent(){
    try{
    dbutil.connectDB();
    String Query = "Select St_Record, St_L_Name, St_F_Name, St_Major, St_Email_Address, St_SSN, Date, St_Company, St_Designation";
    cs = conn.createStatement();
    java.sql.ResultSet rs = cs.executeQuery(Query);
    Vector Studentvector = new Vector();
    while(rs.next()){
    Studentinfo Student = new Studentinfo();
    Student.setSt_Record(rs.getInt("St_Record"));
    Student.setSt_L_Name(rs.getString("St_L_Name"));
    Student.setSt_F_Name(rs.getString("St_F_Name"));
    Student.setSt_Major(rs.getString("St_Major"));
    Student.setSt_Email_Address(rs.getString("St_Email_Address"));
    Student.setSt_Company(rs.getString("St_Company"));
    Student.setSt_Designation(rs.getString("St_Designation"));
    Student.setDate(rs.getInt("Date"));
    Studentvector.add(Student);
    if( cs != null)
    cs.close();
    if( conn != null && !conn.isClosed())
    conn.close();
    return Studentvector;
    }catch(Exception ignore){
    return null;
    }finally {
    dbutil.closeDB();
    import java.sql.*;
    import java.util.*;
    public class dbutil {
    /** Creates a new instance of dbutil */
    public dbutil() {
    Connection conn;
    public void connectDB(){
    conn = ConnectionManager.getConnection();
    public void closeDB(){
    try{
    if(conn != null && !conn.isClosed())
    conn.close();
    }catch(Exception excep){
    The main error is occuring at the following lines connectDB() and closeDB() in the class student manager. The class dbutil is in an another package.with an another file called connectionManager which establishes the connection with DB. The dbutil has the openconnection and close connection methods. I have not yet written the insert statements in StudentManager. PLease do Help me

  • NoClassDefFound error when using custom Java package in scripting QPAC

    Hi,
    I compiled a little Java-package (.jar), which contains a class that uses
    com.adobe.workflow.datatype.form.FormDataTypeInstanceImpl.
    I put my library in the lib folder of JBoss (...\server\all\lib).
    Then I'm was trying to invoke my custom class in the scripting QPAC. But I'm constantly getting the error message
    NoClassDefFound com\adobe\workflow\datatype\form\FormDataTypeInstanceImpl. I already put
    adobe-wkf.jar (and various others) in the lib folder of JBoss. Without ever succeeding. Unfortunately.
    I'm going mad about this.
    Is there a way to address a custom package in the scripting QPAC, which uses
    FormDataTypeInstanceImpl?
    Steve

    Removing the LiceCycle jars from the lib folder did not work. I still get the same error message.
    What I wanted to do is provide some basic utilities, without having to spend a lot of time designing QPAC user interfaces.
    My utility class contains methods like this one:
    @param 
    pFormData
    @return
    @throws 
    ParserConfigurationException
    @throws 
    SAXException
    @throws 
    IOException
    public static 
    org.w3c.dom.Document formToXml
    FormDataTypeInstanceImpl pFormData
    throws 
    ParserConfigurationException, SAXException, IOException 
    byte
    data = pFormData.getXFAData
    InputStream objXMLInputStream = 
    new 
    ByteArrayInputStream
    data
    // create new Document object
    DocumentBuilderFactory objFactory = DocumentBuilderFactory.newInstance
    DocumentBuilder objBuilder = objFactory.newDocumentBuilder
    org.w3c.dom.Document objDocument = objBuilder.parse
    objXMLInputStream
    return 
    objDocument;
    Even without ever invoking the aforementioned method, I get the error
    NoClassDefFound: FormDataTypeInstanceImpl. Which is pretty weird.
    Do I have to write my own classloader?
    Steve

  • How to find classes in a java package

    i am writing a java IDE. i want to extract all class names from a java package eg. java.lang (through coding). how can i do that.
    Thanks in advance

    File file = new File("path to your jar file");
    JarFile jf = new JarFile(file);
    Enumeration e = jf.entries();
    ZipEntry ze = null;
    while(e.hasMoreElements()){
    ze = (ZipEntry) e.nextElement();
    ze.toString(); // gives you the file name
    you have to understand java.util.jar java.util.zip packages for working with jar/zip files.
    Hope this helps

  • How to import java package in form 10g

    hello
    i have make a java package but its not looking so far possible to include it in java import list, how i can import it in form 10 g

    hi,
    if classpath does not work you can try to add your jar file at this registry key :
    HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\KEY_DevSuiteHome\FORMS_BUILDER_CLASSPATH
    Engin.

  • Problem with Java-Packages in JavaFX-Scripts

    Hello!
    What I'm trying to do is using a class I've built in my project in a JavaFX-Script, my problem is that the compiler keeps telling me my package wouldn't exist.
    My filestructure is basically the following:
    src
    |-com.foo.java
    |-- MyClass.java
    |-com.foo.javafx
    |-- MyFXScript.fx
    I've tried importing the package or just writing the fully qualified classname when trying to create an instance, the messages didn't differ. I'm not at home right now so I don't remember the exact compiler-message, but it was something like "Package does not exist: com.foo.java".
    Any ideas? :-)
    Kind regards,
    Joshua
    Edited by: gnrx on Jan 12, 2009 5:55 AM

    It works on my system.
    MyClass.java
    package com.foo.java;
    public class MyClass {
        @Override
        public String toString() {
            return "My Class";
    MyFXScript.fx
    package com.foo.javafx;
    import com.foo.java.*;
    var myClass = new MyClass();
    println(myClass);standard-run:
    My Class
    browser-run:
    jws-run:
    midp-run:
    run:
    BUILD SUCCESSFUL (total time: 3 seconds)

  • Java packages and dependency

    When java was being developed, what was the philosophy behind allowing packages to be mutually dependent?

    Hello Steve,
    The Acyclic Dependencies Principle tells us that no cycles should exit in a model depicting the dependencies between packages. From what I can gather this is useful when developing large software systems, as each package becomes a viable work unit for an engineer or small group of engineers to control as a series of releases. If the ADP is not complied with, cycles may exist in the dependencies between packages. If a change is made to one of those packages within a cycle, then an ugly situation develops as the repercussions of the change are looped through the cycle back to its source and so on.
    The thing is though, during my readings I came across a statement that said Java packages were mutually dependent. I was just wanting to know why a language that utilises object oriented technology, left the practice of the ADP up to the descretion of the developer? Is the full implementation of ADP on a software system an ideal world scenario?
    Anders.

  • Java package and c++ header files

    What is the difference between importing java package and including header files in c++?

    I do not know .. have been away from C/C++ for a long time...
    As much as I remember you can only import one header file each time... also when you import a header file you can just call methods from the header file automatically ...
    However I could be very wrong on this .. really lost touch from C/C++ ...
    regards,
    Sim085

  • Error occured while running .java package in BPEL

    Hi All,
    I'm trying to run .java package which is using RIDC components (GET_FILE) option.
    I have set my local IP address in the config.cfg file also and restarted.
    Still i'm getting below error in Jdeveloper when I run the package.....
    oracle.stellent.ridc.protocol.ProtocolException: Unable to initialize connection idc://tgreenspence:4444
    *     at oracle.stellent.ridc.protocol.intradoc.socket.SocketConnectionManager.initializeConnection(SocketConnectionManager.java:35)*
    *     at oracle.stellent.ridc.protocol.intradoc.socket.SocketConnectionManager.initializeConnection(SocketConnectionManager.java:22)*
    *     at oracle.stellent.ridc.protocol.impl.SimpleConnectionPool.acquireConnection(SimpleConnectionPool.java:44)*
    *     at oracle.stellent.ridc.IdcClient.sendRequest(IdcClient.java:151)*
    *     at test.TestRIDC.TestRIDCGetFile.main(TestRIDCGetFile.java:52)*
    Caused by: oracle.stellent.ridc.protocol.ProtocolException: java.net.ConnectException: Connection timed out: connect
    *     at oracle.stellent.ridc.protocol.intradoc.socket.SocketConnection.connect(SocketConnection.java:52)*
    *     at oracle.stellent.ridc.protocol.intradoc.socket.SocketConnectionManager.initializeConnection(SocketConnectionManager.java:33)*
    *     ... 4 more*
    Caused by: java.net.ConnectException: Connection timed out: connect
    *     at java.net.PlainSocketImpl.socketConnect(Native Method)*
    *     at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)*
    *     at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)*
    *     at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)*
    *     at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)*
    at java.net.Socket.connect(Socket.java:529)
    *     at java.net.Socket.connect(Socket.java:478)*
    *     at java.net.Socket.<init>(Socket.java:375)*
    *     at java.net.Socket.<init>(Socket.java:189)*
    *     at oracle.stellent.ridc.protocol.intradoc.socket.SocketConnection.createSocket(SocketConnection.java:126)*
    *     at oracle.stellent.ridc.protocol.intradoc.socket.SocketConnection.connect(SocketConnection.java:44)*
    *     ... 5 more*
    What will be the solution ??
    Thanks,
    Nir

    take the code out of bpel. run it standalone. does it work?
    -ryan

  • Just Starting out with java packages

    Hello,
    I'm a beginner and I'm starting out with java packages.
    I wrote two simple .java files, one test program and one containing a simple class.
    Both files are compiling without errors but When I run the program I get an error NoClassDeffoundError.
    I use the import <package> statement And I think I'm using the CLASSPATH variable correctly.
    SET CLASSPATH=d:\nopol
    path for the .java containing the test class is:
    d:\nopol\utilities \myapp.
    In the test file I use "import utilities.myapp.*.
    I would be very happy if anyone could help me
    Thanks beforehand
    Nopol.

    The test file should be in d:\nopol, if it's not a part of your package utilities.myapp. Everything should be compiled from d:\nopol, the test class with "javac ClassName.java" and the class in the package with "javac utilities/myapp/ClassName.java".
    Your classpath seems fine for now, though. But yes, do add the period there, otherwise you could run into problems later.

  • Problem finding native methods in java packages

    Hi,
    I have a java class which uses some native methods written in OCamL. I wrote a C file which calls the OCamL code, and created the corresponding shared library using the jni. I then tested my java file and everything works fine, I can nicely call the OCamL functions. However, I need this java file to be included in a package, but whenever I add the line:
    package somepackage;
    on top of the java code, my java file simply doesn't seem to find the C and OCamL implementation anymore :
    javac -cp :./path/of/somepackage
    -Djava.library.path=/full/path/of/somepackage MyProgram args
    Exception in thread "main" java.lang.UnsatisfiedLinkError:functionName
    at somepackage.ClassName.functionName(NativeMethod)
    I have of course put everything (java, C, .h , libsomelibrary.so, and OCamL files) in a directory called somepackage, and written another java file which creates an instance of the first one from outside the package, imports the package, and calls its methods in main(). It just doesn't work anymore.
    I then added a simple hello-world function (not C nor OCamL code) to the java file inside the package. And when invoked from outside, it worked. Question is then... Am I forgetting something to be done, in order to get C and CamL files efectively included in the java package (same as "package somepackage;" in C or OCaml, perhaps)??? Why isn't the java file able to find them inside its very own directory (having into account that without the package definition it worked well)?
    Thanks,
    PS Im using jsdk 1.4.1 on lunyx redhat 8.0

    Did you change the name of the function in the library, too?
    If the function name was
    "Java_YourClass_functionname",
    it should be now
    "Java_path_to_your_package_YourClass_functionname".

  • Use of Java packages in Java stored procedures? (Oracle 10.2)

    Hi all-
    Does Oracle's Java stored procedures support Java packages? In all the examples I've seen, packages are never used, and when I added one to a test file, it compiled it just fine, but referencing the class from the package itself resulted in a compiling error.
    In other words, it seems to make absolutely no difference if I preface my Java class with
    package com.mycompany.whatever;
    and while I can "import com.mycompany.whatever.MyClass" in another Java file, it seems to not care at all whether I do so or not.
    Thanks for any clarification,
    Ilford

    Hi Ilford:
    Sure you can use fully package notation in your Java classes.
    Look at this Java source code:
    http://dbprism.cvs.sourceforge.net/dbprism/cms-2.1/src/com/prism/cms/core/
    All of them are Java Stored procedures.
    Best regards, Marcelo.

  • Java package to parse email

    Hi,
    I was wondering if anyone knows of a java package which does the following. Monitors an email account (could be through SMTP) and downloads email based on certain rules you can mention in the config file. For instance, if the the email comes from address [email protected] then download the attachment B.pdf to a certain folder.

    harsh884 wrote:
    May be you can use Apache common-logging.jar its API for getting logs....try the link below
    http://commons.apache.org/logging/guide.html
    Was that meant to be posted in this thread?

  • Java package compile errors

    I use a batch file to compile a java package. And I got the following errors:
    TabPages: Java: 29: Cannot solve symbol
    Symbol: class JSPFactory
    Location: package JSP
    JSPFactory = javax.Servlet.jsp.JSPFactory.getDefaulfFactory();
    Note: Some input files use or override a deprecated APT.
    Note: Recompile with -deprecation for details.
    I am using New Atlanta servletExec 3.1 and IIS server. Can anyone help me figure our the above errors? Thanks!

    if I add the "set classpath=".,C:/javax" to the begining of the batch file, will this override the classpath that I set in the Environment window? I am worried about this since we have a bunch of environment variables already been set there.
    I tried to add the ";c:\javax" at the end of the classpath on my Environment window, and rebooted the server, but still got the same error message. Did I have some syntax error? What does the dot before ";C:/javax" mean? I deleted it when I added them to the classpath.
    It will cause too much trouble to add the "javac XXX.java -classpath=".;C"/javax" to each file that needs this package because we don't have a single command for compiling a single java file. We have a huge amount of java files and we just use a single "javac -d" to compile every file under several folders. Our batch file is as follows:
    del /F/Q ..\classes
    javac -d ..\classes *.java htmltool\html\*.java ises\*.java DropDown\*.java frmselection\*.java grid\*.java treeView\*.java reportTreeMenu\*.java hs\types\*.java
    del /F ..\lib\grid.jar
    del /F ..\lib\TreeView.jar
    cd ..\classes
    jar cf ..\lib\grid.jar grid
    rmdir /S/Q grid
    jar cf ..\lib\TreeView.jar treeView
    rmdir /S/Q treeView
    cd ..\javasrc
    Another thing is that: we have exact the same classpath and batch file on another server which works fine, and its classpath doesn't include explicitly stuff like";c:\javax", but we never have prolbem compiling the java source. So do I miss something else?

Maybe you are looking for

  • Help! i just paid £6.99 for a movie app and its not working what can i do?

    Please will someone help me? i just downloaded an app called mobile cinema and it says on the app to watch all the movies you need to purchase the full app at £6.99 which i did and then when i clicked on the movies it is just taking me to the imdb we

  • Problem in RFC  call in ABAP code...Urgernt

    Hi , I am working on scenario wherein , i have created remote enabled RFC in target system SAP R/3 one . I have maintained RFC in original system where i have my calling program.This done by using sm59 transaction .When i execute my abap calling prog

  • Auto Select not working in Photoshop CS6--Why?

    I'm experiencing the auto-select in Photoshop CS6 not working when it is checked and I click on different layers. It worked fine in 5.5, but I am now using PS CS6 cloud and it works only sporadically. Any reason why? Thanks in advance! -Jane

  • Corrupt workbook when sent through email

    Hi, I have setup a precalculation server on a Windows XPSP2 PC, installed Excel 2003SP3 and SAPGUI 640p24. When calculating a workbook, it's created correctly (as I can open it on the client in the C:\Windows\temp folder), but the sent zip file with

  • JSF Design support for custom controls

    I am creating some custom JSF components, for use in my projects. They work fine, but I was not able to make them display correctly in design time (I am using Websphere).They appear like small rectangles, even when they are grids. What is the standar