java上機實驗報告.doc_第1頁
java上機實驗報告.doc_第2頁
java上機實驗報告.doc_第3頁
java上機實驗報告.doc_第4頁
java上機實驗報告.doc_第5頁
已閱讀5頁,還剩1頁未讀 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

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方法實現(xiàn)這個新功能。提示:參考例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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論