java上机实验报告.doc_第1页
java上机实验报告.doc_第2页
java上机实验报告.doc_第3页
java上机实验报告.doc_第4页
java上机实验报告.doc_第5页
已阅读5页,还剩1页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

Java与面向对象程序设计上机报告l 第一题:修改第五章中StyleOptions程序,允许用户指定字体大小,用单行文本框得到字体大小。提示:参考例题5.225.23源程序:import javax.swing.*;import java.awt.*;import java.awt.event.*;public class StyleOptionsPanel extends JPanel private JLabel saying,inputLabel,resultLabel; private JCheckBox bold, italic; private JTextField num; public StyleOptionsPanel() String numStr; inputLabel=new JLabel(Font Size:); num=new JTextField(8); num.addActionListener(new TempListener(); saying = new JLabel (Say it with style!); saying.setFont (new Font (Helvetica, Font.PLAIN, 36); bold = new JCheckBox (Bold); bold.setBackground (Color.green); italic = new JCheckBox (Italic); italic.setBackground (Color.green); StyleListener listener = new StyleListener(); bold.addItemListener (listener); italic.addItemListener (listener); add (saying); add (bold); add (italic); add(inputLabel); add(num); setBackground (Color.yellow); setPreferredSize (new Dimension(300, 100); private class TempListener implements ActionListener public void actionPerformed (ActionEvent event) int number=36; String text = num.getText(); number= Integer.parseInt (text); saying.setFont (new Font (Helvetica, Font.PLAIN, number); private class StyleListener implements ItemListener public void itemStateChanged (ItemEvent event) int style = Font.PLAIN; if (bold.isSelected() style = Font.BOLD; if (italic.isSelected() style += Font.ITALIC;saying.setFont (new Font (Helvetica, style, 36); import javax.swing.JFrame;public class StyleOptions public static void main (String args) JFrame frame = new JFrame (Style Options); frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); StyleOptionsPanel panel = new StyleOptionsPanel(); frame.getContentPane().add (panel); frame.pack(); frame.setVisible(true); 运行情况及结果截图:完成情况说明:l 第二题:PP6.1 修改第四章的Account类,使其也允许仅使用账户名和账号建立账户,并假设初始余额为0。修改Transactions类的main方法实现这个新功能。提示:参考例4.34.4源程序:import java.text.NumberFormat; class Account private final double RATE = 0.035; / interest rate of 3.5% private long acctNumber; private double balance; private String name; public Account (String owner, long account, double initial) name = owner; acctNumber = account; balance = initial; public Account (String owner, long account) name = owner; acctNumber = account; balance = 0.00; public double deposit (double amount) balance = balance + amount; return balance; public double withdraw (double amount, double fee) balance = balance - amount - fee; return balance; public double addInterest () balance += (balance * RATE); return balance; public double getBalance () return balance; public String toString () NumberFormat fmt = NumberFormat.getCurrencyInstance(); return (acctNumber + t + name + t + fmt.format(balance); public class Transactions public static void main (String args) Account acct1 = new Account (Ted Murphy, 72354, 102.56); Account acct2 = new Account (Jane Smith, 69713, 40.00); Account acct3 = new Account (Edward Demsey, 93757, 759.32); Account acct4 = new Account (jhgu, 67856); acct1.deposit (25.85); double smithBalance = acct2.deposit (500.00); System.out.println (Smith balance after deposit: + smithBalance); System.out.println (Smith balance after withdrawal: + acct2.withdraw (430.75, 1.50); acct1.addInterest(); acct2.addInterest(); acct3.addInterest(); acct4.addInterest(); System.out.println (); System.out.println (acct1); System.out.println (acct2); System.out.println (acct3); System.out.pri

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论