• Login
  • Register
  • Login Register
    Login
    Username:
    Password:
  • Home
  • Members
  • Team
  • Help
User Links
  • Login
  • Register
  • Login Register
    Login
    Username:
    Password:

    Quick Links Home Members Team Help
    Tendo City Tendo City: Metropolitan District Ramble City Graphing Compound Interest in Java

     
    • 0 Vote(s) - 0 Average
    Graphing Compound Interest in Java
    The Former DMiller
    Offline

    Super Moderator

    Posts: 1,622
    Threads: 55
    Joined: 10-01-1999
    #1
    21st April 2005, 11:39 AM
    I'm a bit rusty using Java...rusty meaning I remember almost nothing about programming in it. It's been over 4 years since I did anything other than short little Javascripts, but they aren't the same as full-fledged Java. What I need to do is write a program that will ask the user for four inputs: the principle, the interest, the unit of time, and the amount of time. It will then compute the compound interest and create a graph based on the data obtained. Any hints as to what I will need to do would be greatly appreciated. I don't think I've ever created graphs in Java so I'll have to be trying that out cold.
    <a href=http://www.gamespot.com/users/dmiller1984>My Games (GameSpot)</a>
    <a href=http://www.derekmiller.us/>My Website (In A Constant State of Construction)</a>
    [Image: scrubs.jpg]
    Reply
    Reply
    OB1
    Offline

    Posting Freak

    Posts: 21,228
    Threads: 806
    Joined: 09-11-1999
    #2
    21st April 2005, 1:51 PM
    I will ask my friend.
    Reply
    Reply
    The Former DMiller
    Offline

    Super Moderator

    Posts: 1,622
    Threads: 55
    Joined: 10-01-1999
    #3
    21st April 2005, 7:26 PM
    It's kind of a funny situation. I wrote a lesson plan for my Math and Science methods class that had the students writing a compound interest program. The teacher asked if I could bring in an example of the program because she was interested, and I was stupid and said yes, but mostly because I wanted the A. Turns out I got a 98% on it anyway, but it would look bad if I didn't bring in the program. I wish I had put in the lesson plan that I wrote it in Perl, or some other programming language I wrote in recently.
    <a href=http://www.gamespot.com/users/dmiller1984>My Games (GameSpot)</a>
    <a href=http://www.derekmiller.us/>My Website (In A Constant State of Construction)</a>
    [Image: scrubs.jpg]
    Reply
    Reply
    Laser Link
    Offline

    Moderator

    Posts: 1,352
    Threads: 54
    Joined: 11-23-1999
    #4
    22nd April 2005, 4:27 PM
    I've been playing with Swing over the last few months, and can't think of anything that lets you draw points and a graph... Let's see what Google says...

    Okay, <a href="http://www.sci.usq.edu.au/staff/leighb/graph/">here</a> is a Graph Library that somebody made. It has all the source and some examples. The documentation doesn't look all that helpful, but I just glanced at it. I bet you could hack one of the examples pretty easily, though. It uses Applets.

    That looks like the best I could find. I could do this easily in OpenGL, but I haven't really figured out how to use Java Swing to do anything outside of the built in classes. You could check out <a href="http://java.sun.com/docs/books/tutorial/uiswing/14painting/index.html">this tutorial</a> from Sun on Custom Painting. It might help.

    Maybe Obi can get you some better help, since his friend has done game programming with Java. When do you need it done by? Do you want to do it on your own, cause I could help if you want.
    Reply
    Reply
    The Former DMiller
    Offline

    Super Moderator

    Posts: 1,622
    Threads: 55
    Joined: 10-01-1999
    #5
    22nd April 2005, 4:29 PM
    I need it done by Monday. The graphing is obviously the hitch point, but I'll check out that graph library and see if I can get it to work.
    <a href=http://www.gamespot.com/users/dmiller1984>My Games (GameSpot)</a>
    <a href=http://www.derekmiller.us/>My Website (In A Constant State of Construction)</a>
    [Image: scrubs.jpg]
    Reply
    Reply
    OB1
    Offline

    Posting Freak

    Posts: 21,228
    Threads: 806
    Joined: 09-11-1999
    #6
    22nd April 2005, 4:30 PM
    Ok I asked my friend for help and here's what he said:


    Quote:this Java file will prompt the user for input from the command line, and then convert this input into an int and a double for use in computation


    See attached file.
    Reply
    Reply
    Laser Link
    Offline

    Moderator

    Posts: 1,352
    Threads: 54
    Joined: 11-23-1999
    #7
    23rd April 2005, 4:26 PM
    Well getting input from the command line isn't the hard part, it's drawing the graph of the interest that is tough because Java doesn't come with any standard classes for graphing. I wonder why that is? You would think that would be a relatively common use, especially among scientists. That's about the only thing Matlab can do well, that and gigantic matrix operations. I guess that's why my EE friends like Matlab. :)

    Here's another thought. If you can find a way of using bar graphs, you could use JLabels pretty easily. Just set them each to opaque and set Maximum, Preferred, and Minimum Size for each as well with the values from your computations (for some reason you have to usually set all three size attributes to get it to actually use that size, and even that isn't 100%. Dumb Swing.).
    Reply
    Reply
    Laser Link
    Offline

    Moderator

    Posts: 1,352
    Threads: 54
    Joined: 11-23-1999
    #8
    23rd April 2005, 4:49 PM
    You're probably way past this point already Derek, but if you haven't got around to it yet, this might save you some time.
    The first <a href="http://www.sci.usq.edu.au/staff/leighb/graph/examples/example1.html">example</a> looks like it can do what you want. Assuming I am right in what you want. :) My understanding is you want to keep track of how much interest you pay over time or something like that, so this should work okay.

    It looks like he uses that data array to store each point of the graph (I think it's a parabola):

    for(i=j=0; i<np; i++,j+=2) {
    data[j] = j-np;
    data[j+1] = 60000 * Math.pow( ((double)data[j]/(np-2) ), 2);
    }


    Sets those DataSet objects (data1 and data2) with the curve info here:

    data1 = graph.loadDataSet(data,np);

    (np is just the max size of the array, I don't know why he didn't declare it <b>final</b>)

    And finally sets the axis with the DataSets and the graph names and units.

    xaxis = graph.createAxis(Axis.BOTTOM);
    xaxis.attachDataSet(data1);
    xaxis.attachDataSet(data2);
    .
    .
    .

    Really the only thing you need to even touch is the part where he loads the data array with the data points he wants to graph. You should be able to do it pretty easily. I can't say I've done a lot with Applets (hopefully you have), so I don't know if any of that needs to be changed or if it will automatically pull up a browser and run the applet there. Sorry.

    [edit]I don't know why this board won't display all the code. It keeps cutting off the for loop.[/edit]
    Reply
    Reply
    The Former DMiller
    Offline

    Super Moderator

    Posts: 1,622
    Threads: 55
    Joined: 10-01-1999
    #9
    23rd April 2005, 9:29 PM
    That should help a lot. I've had two other projects to work on so I really haven't even scratched the surface of this program yet besides boning up on some basic Java stuff. Tomorrow I'll have the whole day to work on it, however. Thanks for helping out guys.
    <a href=http://www.gamespot.com/users/dmiller1984>My Games (GameSpot)</a>
    <a href=http://www.derekmiller.us/>My Website (In A Constant State of Construction)</a>
    [Image: scrubs.jpg]
    Reply
    Reply
    Laser Link
    Offline

    Moderator

    Posts: 1,352
    Threads: 54
    Joined: 11-23-1999
    #10
    25th April 2005, 8:08 AM
    Hey OB1, I'm sorry if I sounded like that help wasn't useful. I realize it probably came across that way, and I didn't mean for that to happen. Especially since you had to ask your friend to help us.
    Reply
    Reply
    OB1
    Offline

    Posting Freak

    Posts: 21,228
    Threads: 806
    Joined: 09-11-1999
    #11
    25th April 2005, 9:26 AM
    Haha, don't sweat it LL. I just asked him to help me with that and I didn't know how much Derek already knew about java so my friend just whipped that up real quick. We were at work, so there wasn't a whole lot of time for detailed explanations. :)
    Reply
    Reply
    « Next Oldest | Next Newest »

    Users browsing this thread: 1 Guest(s)



    • View a Printable Version
    • Subscribe to this thread
    Forum Jump:

    Toven Solutions

    Home · Members · Team · Help · Contact

    408 Chapman St. Salem, Viriginia

    +1 540 4276896

    etoven@gmail.com

    About the company Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

    Linear Mode
    Threaded Mode