The Artima Developer Community
Sponsored Link

Java Answers Forum
pls help me to convert this prog into GUI

2 replies on 1 page. Most recent reply: Dec 18, 2005 11:01 PM by Sharad Thakur

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
imti chowdhury

Posts: 3
Nickname: imti733
Registered: Dec, 2005

pls help me to convert this prog into GUI Posted: Dec 16, 2005 4:23 AM
Reply to this message Reply
Advertisement
hi there
could u pls tell me how to allow the user to loop back and
enter new data or quit besides changing this prog into a GUI???

pls I need ur help
thx in advance


imti


import java.io.*;
import java.text.DecimalFormat; //to limit the digit after Decimal

public class Sun{

public static void main (String args[]) throws IOException{//main Funtion starts


DecimalFormat decimalAmount = new DecimalFormat("#,##0.00"); // we choose to take upto two Decimal

/* In java console input is accomplished by reading from System.in
to obtain a character based stream we wrap System.in in a BuferReader object
*/

BufferedReader br = new BufferedReader (new InputStreamReader(System.in));

String str;

int term;

double loanAmount,rate=0.0,i1,i2,i3,i4,interest,monthlyPayment=0.0,principalPaid=0.0;






System.out.print("Loan Amount is : ");//input loan amount
str = br.readLine();

loanAmount = Double.parseDouble(str);

System.out.print("Term for mortgage is : ");//input term
str = br.readLine();

term = Integer.parseInt(str);


System.out.print("Interest rate is : ");//input interest rate
str = br.readLine();
rate=Double.parseDouble(str);





//Calculation

interest=(loanAmount*rate)/1200;

i1=(1 + (rate/1200)); //i1,i2,13,14 are used to simplify the formula
i2=-(term*12);
i3=Math.pow(i1,i2);
i4=1-i3;
monthlyPayment=interest/i4;
principalPaid=monthlyPayment-interest;
System.out.print("Loan amount: " +decimalAmount.format(loanAmount)+ "\n");
System.out.println("Monthly payment is: " +decimalAmount.format(monthlyPayment));
System.out.println("");
System.out.print("Month\tInterest Paid\tLoan Balance \n");

term=term*12; //multiply the input year with 12 so that we would get the corresponding months


while (term != 0)

{
interest=(loanAmount*rate)/1200;
principalPaid=monthlyPayment-interest;
loanAmount=loanAmount-principalPaid;
System.out.println(term + "\t" + decimalAmount.format(interest) +"\t\t" + decimalAmount.format(loanAmount));
term--;

if (term % 12 == 0) //year by year display
{
try
{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Press enter to list upcoming 12 payment details");
in.read();
}
catch (IOException e) {}
}

}





}

}


Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: pls help me to convert this prog into GUI Posted: Dec 18, 2005 10:18 PM
Reply to this message Reply
Could you please repost your code indented surrounded by the
Java Tags.

http://www.artima.com/forums/howtopost.html

You may also want to google a Swing Tutorial. Just glancing
over your program you might want to concentrate particularly
on JTextField, JButton and possibly JTextArea. You may also
want to look at LayoutManagers (in this case probably
GridLayout and BorderLayout).

Sharad Thakur

Posts: 7
Nickname: javasir
Registered: Sep, 2005

Re: pls help me to convert this prog into GUI Posted: Dec 18, 2005 11:01 PM
Reply to this message Reply
Hi,

you can infact put all you calculations into a Method and call that Method in an infinite loop ,
after each processing ask the use to enter Q for quit and in the method make a check each time you proceed and if user enters Q then exit the system.

Hope you got my point buddy

Flat View: This topic has 2 replies on 1 page
Topic: JAVASERVERFACES Previous Topic   Next Topic Topic: JAR Question

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use