Need help to draw a graph from the output I get with my program please
Hi all,
I please need help with this program, I need to display the amount of money over the years (which the user has to enter via the textfields supplied)
on a graph, I'm not sure what to do further with my program, but I have created a test with a System.out.println() method just to see if I get the correct output and it looks fine.
My question is, how do I get the input that was entered by the user (the initial deposit amount as well as the number of years) and using these to draw up the graph? (I used a button for the user to click after he/she has entered both the deposit and year values to draw the graph but I don't know how to get this to work?)
Please help me.
The output that I got looked liked this: (just for a test!) - basically this kind of output must be shown on the graph...
The initial deposit made was: 200.0
After year: 1 Amount is: 210.00
After year: 2 Amount is: 220.50
After year: 3 Amount is: 231.53
After year: 4 Amount is: 243.10
After year: 5 Amount is: 255.26
After year: 6 Amount is: 268.02
After year: 7 Amount is: 281.42
After year: 8 Amount is: 295.49
After year: 9 Amount is: 310.27
After year: 10 Amount is: 325.78
After year: 11 Amount is: 342.07
After year: 12 Amount is: 359.17
After year: 13 Amount is: 377.13
After year: 14 Amount is: 395.99
After year: 15 Amount is: 415.79
After year: 16 Amount is: 436.57
After year: 17 Amount is: 458.40And here is my code that Iv'e done so far:
import javax.swing.*;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.lang.Math;
import java.text.DecimalFormat;
public class CompoundInterestProgram extends JFrame implements ActionListener {
JLabel amountLabel = new JLabel("Please enter the initial deposit amount:");
JTextField amountText = new JTextField(5);
JLabel yearsLabel = new JLabel("Please enter the numbers of years:");
JTextField yearstext = new JTextField(5);
JButton drawButton = new JButton("Draw Graph");
public CompoundInterestProgram() {
super("Compound Interest Program");
setSize(500, 500);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
amountText.addActionListener(this);
yearstext.addActionListener(this);
JPanel panel = new JPanel();
panel.setBackground(Color.white);
panel.add(amountLabel);
amountLabel.setToolTipText("Range of deposit must be 20 - 200!");
panel.add(amountText);
panel.add(yearsLabel);
yearsLabel.setToolTipText("Range of years must be 1 - 25!");
panel.add(yearstext);
panel.add(drawButton);
add(panel);
setVisible(true);
public static void main(String[] args) {
DecimalFormat dec2 = new DecimalFormat( "0.00" );
CompoundInterestProgram cip1 = new CompoundInterestProgram();
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(new GraphPanel());
f.setSize(500, 500);
f.setLocation(200,200);
f.setVisible(true);
Account a = new Account(200);
System.out.println("The initial deposit made was: " + a.getBalance() + "\n");
for (int year = 1; year <= 17; year++) {
System.out.println("After year: " + year + " \t" + "Amount is: " + dec2.format(a.getBalance() + a.calcInterest(year)));
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
class Account {
double balance = 0;
double interest = 0.05;
public Account() {
balance = 0;
interest = 0.05;
public Account(int deposit) {
balance = deposit;
interest = 0.05;
public double calcInterest(int year) {
return balance * Math.pow((1 + interest), year) - balance;
public double getBalance() {
return balance;
class GraphPanel extends JPanel {
public GraphPanel() {
public void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setColor(Color.red);
}Your help would be much appreciated.
Thanks in advance.
watertownjordan wrote:
http://www.jgraph.com/jgraph.html
The above is also good.Sorry but you need to look a bit more closely at URLs that you cite. What the OP wants is a chart (as in X against Y) not a graph (as in links and nodes) . 'jgraph' deals with links and nodes.
The best free charting library that I know of is JFreeChart from www.jfree.org.
Similar Messages
-
I Need Help Syncing All My Music From My Desktop To My IPhone 5 Helllllllllllp Please
Hi can someone help me please I have a IPhone5 64g I need help syncing all my music from my I tunes library. I have a total of 3600 songs on my I tunes library which is 26g on my desktop all the boxes are checked on each song when I hit sync im only getting 1400 songs wich is only 10g of music I want all 26g of musicon my IPhone 5 when i hit sync all my music are not syncing and I need helping syncing all my music can someone help me please?
Are you upgrading from an existing iPhone? Back up old phone, then restore new phone with the cable. I had to do this a number of time to get all my purchases across.
-
I need help to transfer my movies from I tunes to an external hard drive please
I need help to transfer my movies from I tunes to an external hard drive please
Teach a man to fish, feed them for life.
https://discussions.apple.com/message/16276201#16276201 -
Need help on drawing multiple squares on the screen
I am working on a project for aircraft seating and what i have to do is create square on the screen as seat. I got to draw 180 squares on the screen and it sounds easy but i have been stuck at it for about 10 days now my superviser doesn't know java so he can't help me on what i should do next and java superviser's told me they have no time to see me so if anyone here can help to guide me where i am goin wrong or how i should do it would be very helpful. Here is the code i have so far i think i am maybe close to gettin it working but then again i could be far off.
import java.awt.BorderLayout;
import java.awt.Graphics;
import java.awt.Dimension;
import java.awt.GridLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Seating extends JFrame {
private JPanel boardPanel;
private JPanel panel2;
private Square board[][];
public Seating() {
boardPanel = new JPanel();
boardPanel.setLayout(new GridLayout(6,30,0,0));
//create board
board = new Square[6][30];
//rows in the board
for(int row = 0; row < board.length; row++)
//column on the board
for(int column = 0; column < board[row].length; column++)
//create square
board[row][column] = new Square(' ', 3 * row + column);
//add square
boardPanel.add(board[row][column]);
panel2 = new JPanel();
panel2.add(boardPanel, BorderLayout.CENTER);
add(panel2, BorderLayout.CENTER);
setSize(2000,1500);
setVisible(true);
private class Square extends JPanel
public Dimension getPreferedSize()
return new Dimension(20,20);
public Dimension getMinimumSize()
return getPreferedSize();
public void paintComponent(Graphics g)
super.paintComponents(g);
g.drawRect(0, 0, 19, 19);
}Yeah I'd make a Seat class, subclassing JLabel, and then add some business logic to them to reflect that. For example, if they're already booked, given them a different color and disable clicks on them. If they're bookable, add a mouse click listener. Maybe I'd make different subclasses of Seat for those different roles. I'd add them all to the grid, but also add them to a Map indexed by seat name or something so I could find them and update them as needed.
-
I had to reboot my iphone. I now need to download my last back up from the cloud - how do I do this?
All of your apps should be in iTunes on the computer, simply sync them back.
If they are not, go into the purchase history and download them again. -
every time i download a file from the web (ie. a PDF file) i get "Anti-Virus Program not found " message. This has been happening since I changed anti-virus programs for CA etrust to Sophos. How do I get Firefox to recognise my new Anti-virus program?
That is a very good warning provided by the Download Statusbar extension. Something like that should been built into Firefox. I filed this Bug report a couple of years ago, about the lack of a warning like that. <br />
https://bugzilla.mozilla.org/show_bug.cgi?id=480855 <br />
I have looked everywhere that I can think of to find a list of '''IOfficeAntiVirus providers''' ''(as mentioned in the Bug report)'' that will work with Firefox, so I can't answer that for you.
You might want to ask the developer of the Download Statusbar extension about it. He might know which AV programs are compatible with the Windows API that Firefox uses for the download scan. <br />
http://dlstatusbar.proboards.com/index.cgi? <br /> -
Hi I just got a new MacBook Pro I need help transferring Bootcamp (Windows XP) from my old Macbook Pro to my new Macbook Pro Mac OS X 10.7.4 2.6 Ghz Intel Core 17. How do I make bootable clone of Bootcamp?
you can't just move XP even if you took the hard drive and have Windows boot and function.
Apparently there are Windows tools to sanitize the OS and strip all the motherboard drivers and services.
Time to get a supported OS. Don't want to pay, then use 8 for the time until it goes on sale.
There are no drivers for even Vista on 2011 and later Macs. -
I need help moving my Photoshop 7 from my old laptop to my new laptop which is running Windows 7 Enterprise. I’ve tried two routes unsuccessfully. I install the CD, it does not autoplay. I execute Autoplay.exe at the root directory, I am welcomed, I choose English, I accept the EULA, I get the Install/Explore choices window, with the Install button already selected, I click the Photoshop button, the CD spins, and nothing happens. In the 2nd attempt I execute Setup.exe in the Photoshop directory, and nothing happens at all. I’m never even offered the opportunity to enter my product code. What should I do?
There could is likely a compatibility problem between the old software and the newer operating system.
-
I need to back up and sync multiple iPhones to a single iMac. Each iPhone has a separate Apple ID and the data from each iPhone needs to be backed up separately from the others. How can I do this without getting all of the contacts, etc. mixed? Tnx
This might help: http://support.apple.com/kb/HT1495.
-
Hw can we plot a graph from the data given in a flat file
i need a program that reads a file with 2 columns:
- time in minutes for the x axis
- value (e.g. temperature, heart freq.) for the y axis
Plot the last m minutes, the y axis shall have a range from min...max.
Start with parameter values m=5, speed s=1, min=20, max=120.
After m=5 minutes, the graphical display shall plot the curve of the
last 5 minutes. In other words, you have to implement a sliding window
with a 5 minute history
The speed s is useful for testing, 1=real time, 10=10 times faster.
To implement the real time behaviour, you have to let the program wait the
time interval between two values. The time interval is not constant.
A sample file looks like this (lines 1..3 are always comments):
-------8<-------cut-here-------8<-------
Logfile of program temperature_monitor.cpp
Temp sensor #42, range 30..60 degrees Celsius
2007-06-21 20:30
0.017737 45.2
0.045122 42.7
0.073591 43.1
-------8<-------cut-here-------8<-------
You can download the test data file here:
http://alf42.dyndns.org/oost/temp_testdata_2007-06-21
An axample how the output can look like is here:
http://alf42.dyndns.org/oost/temperature_diagram_example.gifhi
i have tried the code for it and i am getting the
barcharts but not the graph as the output
Your code is rubbish. You also did not use code tags. But let's examine the rubbish points shall we?
import java.awt.*;
import javax.servlet.*;There is no need for you to import servlet here. Especially as this later appears to be an applet.
import java.lang.*;Importing java.lang is redundant.
import java.applet.*;
public class classfile{This is a poorly named class for several reasons. One it does not follow conventions, class names should begin with a capital letter. Two classfile is just a stupid name.
Also your class should most likely extend applet if indeed you mean to write an applet. This is probably pointless because you probably don't mean to write an applet, it's just that you have no clue.
>
int n=0;
String lable[];
int value[];
blic void init()
try{
n= Integer.parseInt(getParameter("column"));n is pointless since everything is hardcoded anyways for four elements
lable = new String[n] ;
value=new int[n];
lable[0]=getParameter("lable11");
lable[1]=getParameter("lable12");
lable[2]=getParameter("lable13");
lable[3]=getParameter("lable14");
value[0]=Integer.parseInt(getParamater("c1"));
value[1]=Integer.parseInt(getParamater("c2"));
value[2]=Integer.parseInt(getParamater("c3"));
value[3]=Integer.parseInt(getParamater("c4"));
catch(NullFormatException e )This is garbage.
System.out.println("Null format Exception");
public void pain(Graphics g)While I am forced to agree with the sentiment here the correct name for this method is paint.
for(int i=0;i<n;i++)
g.steColor(color.red);That is garbage for a variety of reasons.
g.drawString(lable, 20, i*50+30);
g.fillRect(50, i*50+20, value[i], 40);
So try again. Maybe learn some Java first? Just a suggestion. -
Need help in Activating office 365 from my BizSpark
I need help in Activating office 365 from my BizSpark. When I tried to activate it asks for office 365 ac id. i don't know how to sign up for that. Please provide step by step instructions for that.
thanks,
AlbinSorry, but that one doesn't sound like something for "users helping other users" -- unless someone smarter comes along here ... :-) ... I would advise going to Apple Support to have it taken care of ... or to your local Apple Store, over to the Genius Bar.
Apple Support
http://www.apple.com/support/
Apple Retail Store - Genius Bar
http://www.apple.com/retail/geniusbar/ -
I need help writing a script that finds the first instance of a paragraph style and then changes it
I need help writing a script that finds the first instance of a paragraph style and then changes it to another paragraph style. I don't necessarily need someone to write the whole thing, by biggest problem is figuring how to find just the first instance of the paragraph style. Any help would be greatly appreciated, thanks!
Hi,
Do you mean first instance of the paragraph style
- in a chosen story;
- on some chosen page in every text frames, looking from its top to the bottom;
- in a entire document, looking from its beginning to the end, including hidden layers, master pages, footnotes etc...?
If story...
You could set app.findTextPreferences.appliedParagraphStyle to your "Style".
Story.findText() gives an array of matches. 1st array's element is a 1st occurence.
so:
Story.findText()[0].appliedParagraphStyle = Style_1;
//==> this will change a paraStyle of 1st occurence of story to "Style_1".
If other cases...
You would need to be more accurate.
rgds -
lost my phone. reset my icloud password, now its asking me to sign in from the phone before i could use it on the web, and i need to access my icloud account from the web. what shall i do ?
Welcome to the Apple community.
If you are unable to remember your password, security questions, don’t have access to your rescue address or are unable to reset your password for whatever reason, your only option is to contact Apple ID Support, upon speaking to an operator you should explain that your problem is related to your Apple ID, this way you will not be charged for assistance, even if you don’t have an AppleCare plan.
The operator will take you through some steps you may have already tried, however they need to be sure they have exhausted all usual approaches before trying to reset your account, so you should try to be helpful and show patience with the procedure.
The operator will need to verify they are speaking to the account holder and may ask you some questions that only the account holder could know, and you will need to answer them if the process is to proceed.
Once the operator has verified your identity they will send a message through to your device which contains an alpha numeric code, which you will need to read back to them.
Once this has been completed they will send an email to your iCloud email address after a period of 24 hours, so you should check that mail is enabled in your devices iCloud settings.
Upon receipt of the email, use the reset link provided to reset your password, after which you should be able to make the adjustments to iCloud that you wish to do. -
i have lost my phone. reset my icloud password, now its asking me to sign in from the phone before i could use it on the web, and i need to access my icloud account from the web. what shall i do ?
Welcome to the Apple community.
If you are unable to remember your password, security questions, don’t have access to your rescue address or are unable to reset your password for whatever reason, your only option is to contact Apple ID Support, upon speaking to an operator you should explain that your problem is related to your Apple ID, this way you will not be charged for assistance, even if you don’t have an AppleCare plan.
The operator will take you through some steps you may have already tried, however they need to be sure they have exhausted all usual approaches before trying to reset your account, so you should try to be helpful and show patience with the procedure.
The operator will need to verify they are speaking to the account holder and may ask you some questions that only the account holder could know, and you will need to answer them if the process is to proceed.
Once the operator has verified your identity they will send a message through to your device which contains an alpha numeric code, which you will need to read back to them.
Once this has been completed they will send an email to your iCloud email address after a period of 24 hours, so you should check that mail is enabled in your devices iCloud settings.
Upon receipt of the email, use the reset link provided to reset your password, after which you should be able to make the adjustments to iCloud that you wish to do. -
Need help here, a friend died from mesothelioma and his family gave his ipad to us for our children. I reset the ipad in iTunes on the computer and it has find my iPhone on it , now the ipad dont start or boot up again. How do I get for that because I am not able to get a hold of him obviously?
Just had an employee terminated most acrimoniously and had an iPhone 5C that was a brick. Apple support can help remove the lock. Better hold onto your original receipt and record the Serial# ! I do not mean the MEID or IMEI but the Serial# found on the original box or Settings>General>About. In my case no receipt or Serial#. 2 hours on the phone between Apple and Verizon and got what was needed. Submitted form and got reply to allow 2-10 business days.
Here is the form I had to complete and sent to [email protected]..
ORIGINAL SALES INFORMATION:
PRODUCT PURCHASE DATE:
INVOICE/RECEIPT NUMBER:
PRODUCT SERIAL NUMBER:
PRODUCT IMEI/MEID:
PRODUCT DESCRIPTION:
BUSINESS/INSTITUTION NAME:
REQUESTOR NAME/TITLE:
PHONE NUMBER:
STREET ADDRESS:
CITY:
STATE:
POSTAL CODE:
EMAIL ADDRESS:
UNLOCK AUTHORIZATION STATEMENT: I [YOUR NAME] representing
[BUSINESS/INSTITUTION NAME] authorize Apple, Inc. to unlock the devices listed.
Best regards,
The Apple Support Team
Maybe you are looking for
-
What is the difference between upgradation and migration.
Hi Guru's what is the difference between upgradation and migration. actuallly i involved in upgradation project, here my role is 1. first i check the query's in 3.5 save the query and transport the query. and check the query in bex analyzer also. 2.
-
I can't get updates to work. it just loops forever
i have a macbook air. when i get prompted to update, it loops forever
-
using Acrobat X (10) Professional? There are no layers, attachments, signatures, or security settings on the PDF.
-
Do i need to update to ios4.3 first before ios6 for my iphone 4?
Hi, do i need to update my iphone4 to ios4.3 first before updating ios6 ? or can i skip all previous iOs version and update iOS6? pls advise. thanks Steve
-
Does Safari support the use of services as it's image src, like the following: <img border="0" class="image-table" height="512.3px" width="410.0px" src="http://bloggs.com.au/download.svc?docId=1999183509"> It works in Firefox and IE, but in Safari 5.