第2章:财务应用程序:计算利息 【对话框输出】

来源:互联网 发布:淘宝卖家怎么关闭交易 编辑:程序博客网 时间:2024/04/30 16:00
/** * 财务应用程序:计算利息。 * 读取收支余额和年百分率(yearRate),显示两个版本下月利息。 * 利息额(interest) = 收支余额(balance) * (年利率 / 1200)。 * 下面是一个运行示例: * —————————————————————————————————————————————————————————————— * | Enter balance and interest rate (e.g., 3 for 3%): 1000 3.5 | * | The interest is 2.91667                                    | * —————————————————————————————————————————————————————————————— */package Test;import javax.swing.JOptionPane;public class T212InputDialog {public static void main(String[] args) {String balanceString = JOptionPane.showInputDialog("Enter balance and interest rate (e.g., 3 for 3%): ");double balance = Double.parseDouble(balanceString);String yearRateString = JOptionPane.showInputDialog("Enter balance and interest rate (e.g., 3 for 3%): ");double yearRate = Double.parseDouble(yearRateString);double interest = balance * (yearRate / 1200);String ouput = "The interest is " + interest;JOptionPane.showMessageDialog(null, ouput);}}

原创粉丝点击