Guest User

Untitled

a guest
Feb 20th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. package xibbar
  2.  
  3. import javax.swing.{JFrame,JLabel,JTextField,JButton,JPanel,BoxLayout}
  4. import java.awt.event.{ActionListener,ActionEvent}
  5.  
  6. object LoanProcessor {
  7. def main(args: Array[String]){
  8. val window=new MainWindow()
  9. window.show
  10. window.updateResult
  11. }
  12.  
  13. }
  14.  
  15. class MainWindow extends JFrame{
  16. this.setSize(200,200)
  17. this.setTitle("ローン計算")
  18. this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
  19. val panel=new JPanel()
  20. val amountField=new JTextField(10)
  21. val yearField=new JTextField(10)
  22. val rateField=new JTextField(10)
  23. val monthlyPayLabel=new JLabel()
  24. val yearlyPayLabel=new JLabel()
  25. val processButton=new JButton("計算")
  26. val finishButton=new JButton("終了")
  27. val boxLayout=new BoxLayout(panel,BoxLayout.Y_AXIS)
  28. this.getContentPane().add(panel)
  29. panel.setLayout(boxLayout)
  30.  
  31. panel.add(amountField)
  32. panel.add(yearField)
  33. panel.add(rateField)
  34. panel.add(monthlyPayLabel)
  35. panel.add(yearlyPayLabel)
  36. panel.add(processButton)
  37. panel.add(finishButton)
  38.  
  39. amountField.setText("4000")
  40. yearField.setText("35")
  41. rateField.setText("3.05")
  42.  
  43. processButton.addActionListener(new ActionListener(){
  44. def actionPerformed(e:ActionEvent){
  45. updateResult
  46. }
  47. }
  48. )
  49. finishButton.addActionListener(new ActionListener(){
  50. def actionPerformed(e:ActionEvent){
  51. System.exit(0)
  52. }
  53. }
  54. )
  55.  
  56. def updateResult{
  57. val amount=amountField.getText().toInt
  58. val year=yearField.getText().toInt
  59. val rate=rateField.getText().toFloat
  60. val result=processing(amount,year,rate)
  61. monthlyPayLabel.setText("毎月支払額:"+(result).toInt)
  62. yearlyPayLabel.setText("年間支払額:"+(result).toInt*12)
  63. }
  64. def processing(amount: Int, year: Int, rate: Float): Double={
  65. amount*10000*(rate/12/100)/(1-Math.pow(1+rate/12/100,-year*12))
  66. }
  67. }
Add Comment
Please, Sign In to add comment