JTextArea和NumberFOrmat的用法

利息的计算(JTextArea和NumberFOrmat的用法)

程序结果:

原文件:

//calculate copmound interest

import java.text.NumberFormat;
import java.util.Locale;

import javax.swing.JOptionPane;
import javax.swing.JTextArea;

public class Interest{
 
 
 
//main method
 public static void main(String args[]){
  
double amount,principal=100.0,rate=0.05;
  
  NumberFormat moneyFormat
=NumberFormat.getCurrencyInstance(Locale.US);
  
  JTextArea outputTextArea
=new JTextArea();
  outputTextArea.setText(
"year Amount on deposit ");
  
  
for(int year=1;year<=10;year++)
  
{
   amount
=principal*Math.pow(1.0+rate,year);
   outputTextArea.append(year
+" "+moneyFormat.format(amount)+" ");
  }

  
  JOptionPane.showMessageDialog(
null,outputTextArea,"Compound interest",JOptionPane.INFORMATION_MESSAGE);
  
  System.exit(
0);
  
 }

}


 
import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Java_3 extends JFrame implements ActionListener{ private double x=0; private double y=0; JTextField xval = new JTextField(10); JButton calcBtn = new JButton("����"); JTextArea result = new JTextArea(10,20); boolean isAngleRad=true; JButton angleUnitBtn=new JButton("��ɽǶ�"); void initFrame(){ Container content = getContentPane(); content.setLayout(new BorderLayout()); JPanel calcPanel = new JPanel(); calcPanel.setLayout(new FlowLayout()); //***************************Found********************* calcPanel.add( new JLabel("�ǵ�ֵ") ); calcPanel.add(xval); calcPanel.add(calcBtn) ; calcPanel.add(angleUnitBtn); content.add(calcPanel,"North"); calcBtn.addActionListener(this); //***************************Found********************* angleUnitBtn.addActionListener(this) ; content.add(result,"Center"); //***************************Found********************* result.setEditable(false); } public Java_3(){ super("�������Һ���"); setSize(500,200); initFrame(); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public void actionPerformed(ActionEvent e){ if (e.getSource()== calcBtn){ String str; if(isAngleRad) { x=Double.parseDouble(xval.getText()); str="cos("+x+")="; }else { x=Double.parseDouble(xval.getText())/180*3.1415926; //***************************Found********************* str="cos("+ xval.getText() +"*3.14159/180)="; }; y=Math.cos(x); result.append(str+y+'\n'); }else if(e.getSource()== angleUnitBtn){ if(isAngleRad) angleUnitBtn.setText("��ɻ���");
03-29
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值