Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old June 3rd, 2007, 11:47 AM
cupOfJava2007 cupOfJava2007 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2007
Posts: 2 cupOfJava2007 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 48 m 45 sec
Reputation Power: 0
Need Some Help

hey guys im having some trouble. the program is a credit plan for purchases. It is suppose to take in the purchase price of a computer and then output in a textArea a table including the month, current balance of that month, interest charged, principal, the monthly payment due, and the user's new balance of that month. there is a 10 percent down payment and an annual interest rate of 12 percent( i was thinking once month=12 i could somehow make the interest rate 12 percent havent figured this out yet though). It is suppose to keep on doing this until the balance of the month is 0. I have a do while loop for this and figured out some algorithms for this program

when the purchase price is entered all the ouput is correct now except i have two problems.
one like i said above is trying to figure out how to charge an interest of 12 percent anually the other is when the program runs through it doesnt finish when newBalance is zero it ends in the negatives

Code:
import javax.swing.*;
import BreezySwing.*;
 
public class GUICreditPlan extends GBFrame {
 
private JLabel purchasePriceLabel;
private DoubleField purchasePriceField;
private JButton calculateButton;
private JTextArea output;
private double purchasePrice;
private double downPayment;
private double currentBalance;
private int iterations = 1;
private int month;
private double interest = 0;
private double principal;
private double paymentDue;
private double newBalance;
 
public GUICreditPlan()
{
String header = Format.justify('l',"Month", 7) +
Format.justify('r',"Current Balance", 16) +
Format.justify('r',"Interest", 10) +
Format.justify('r',"Principal", 11) +
Format.justify('r',"Payment Due", 14) +
Format.justify('r',"New Balance", 14) + "\n"; 
 
purchasePriceLabel = addLabel ("Purchase Price", 1,1,1,1);
purchasePriceField = addDoubleField(0.0, 1,2,1,1);
calculateButton = addButton ("Calculate", 2,1,2,1);
output = addTextArea (header , 3,1,5,6);
 
output.setEnabled(false);
 
}
 
public void buttonClicked(JButton buttonObj)
{
purchasePrice = purchasePriceField.getNumber();
downPayment = (purchasePrice * .1); 
currentBalance = purchasePrice - downPayment;
 
do 
{
 
paymentDue = ((purchasePrice - downPayment) * .05); 
interest = currentBalance * .01; 
principal = currentBalance - (paymentDue - interest);
newBalance = (currentBalance + interest) - paymentDue;
 
month = iterations; 
displayNumbers (month, currentBalance, interest, principal, paymentDue, newBalance);
currentBalance = (currentBalance + interest) - paymentDue;
 
iterations++; 
 
}
while(currentBalance>0);
 
}
 
private void displayNumbers(int month, double currentBalance, double interest, double principal, double paymentDue,double newBalance)
{
String numberLine = Format.justify('l',month, 7) +
Format.justify('r',currentBalance, 16,2) +
Format.justify('r',interest, 10,2) +
Format.justify('r',principal, 11,2) +
Format.justify('r',paymentDue, 14,2) +
Format.justify('r',newBalance, 14,2) + "\n";
output.append (numberLine + "\n");
}
 
public static void main(String[] args)
{
GUICreditPlan theGUI = new GUICreditPlan();
theGUI.setSize(600,300);
theGUI.setTitle("Credit Plan for the TidBit Computer Store");
theGUI.setVisible(true);
}
}


heres the output with a 10,000 purchase price:
Code:
 
Month   Current Balance  Interest  Principal   Payment Due   New Balance
1               9000.00     90.00    8640.00        450.00       8640.00
 
2               8640.00     86.40    8276.40        450.00       8276.40
 
3               8276.40     82.76    7909.16        450.00       7909.16
 
4               7909.16     79.09    7538.26        450.00       7538.26
 
5               7538.26     75.38    7163.64        450.00       7163.64
 
6               7163.64     71.64    6785.27        450.00       6785.27
 
7               6785.27     67.85    6403.13        450.00       6403.13
 
8               6403.13     64.03    6017.16        450.00       6017.16
 
9               6017.16     60.17    5627.33        450.00       5627.33
 
10              5627.33     56.27    5233.60        450.00       5233.60
 
11              5233.60     52.34    4835.94        450.00       4835.94
 
12              4835.94     48.36    4434.30        450.00       4434.30
 
13              4434.30     44.34    4028.64        450.00       4028.64
 
14              4028.64     40.29    3618.93        450.00       3618.93
 
15              3618.93     36.19    3205.12        450.00       3205.12
 
16              3205.12     32.05    2787.17        450.00       2787.17
 
17              2787.17     27.87    2365.04        450.00       2365.04
 
18              2365.04     23.65    1938.69        450.00       1938.69
 
19              1938.69     19.39    1508.08        450.00       1508.08
 
20              1508.08     15.08    1073.16        450.00       1073.16
 
21              1073.16     10.73     633.89        450.00        633.89
 
22               633.89      6.34     190.23        450.00        190.23
 
23               190.23      1.90    -257.87        450.00       -257.87


Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > Need Some Help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT