K16T1 Nhóm 1
Bạn có muốn phản ứng với tin nhắn này? Vui lòng đăng ký diễn đàn trong một vài cú nhấp chuột hoặc đăng nhập để tiếp tục.


Hãy tưởng tượng, chúng ta đang cùng ở trên một con thuyền, tất cả đều phải cùng chèo để đưa con thuyền đến đích!
 
Trang ChínhGalleryLatest imagesTìm kiếmĐăng kýĐăng Nhập

Thông báo mới nhất, click vào để xem chi tiết: Đăng kí thành viên nhóm network!

Nhạc
Latest topics
» Assignment 02: Simple Calculating
by cambeme 18/10/2011, 23:50

» CHƯƠNG V: HỌC THUYẾT GIÁ TRỊ THẶNG DƯ - Trang 47-hết
by anhkhoamc083 5/10/2011, 08:51

» Bài tập SwingDemo
by cambeme 16/9/2011, 12:22

» ass3 cau 2
by nguyentam 29/5/2011, 10:46

» Assignment 09: Classes
by cambeme 27/5/2011, 17:57

» GROUP EXERCISE 03
by cambeme 24/5/2011, 18:23

» Bản kiểm điểm
by nhoc_vet 20/5/2011, 19:29

» Trình bày GROUP EXERCISE 02
by cambeme 20/5/2011, 00:01

» Khát là gì?
by cambeme 18/5/2011, 22:01

» Assignment 08: Methods
by cambeme 15/5/2011, 23:48

» GROUP EXERCISE 02
by cambeme 11/5/2011, 22:14

» Website nhóm 1
by cambeme 10/5/2011, 20:06

» Giao diện trang chủ
by cambeme 10/5/2011, 13:00

» Cấu hình DHCP RELAY AGENT - cấp cho 2 mạng LAN
by cambeme 9/5/2011, 23:59

» Slide 16
by cambeme 6/5/2011, 23:09

» Slide 15
by cambeme 6/5/2011, 23:08

» Slide 14
by cambeme 6/5/2011, 23:07

» Assignment 07: Control and Flow
by cambeme 6/5/2011, 22:33

» Trình bày GROUP EXERCISE 01
by cambeme 6/5/2011, 00:36

» GROUP EXERCISE 01
by cambeme 5/5/2011, 15:26

» Bai 1
by nguyentam 4/5/2011, 19:24

» cau thu 3
by cambeme 1/5/2011, 15:00

» day la bai so 2
by nguyentam 30/4/2011, 17:06

» chi tiet lam DNS
by nguyentam 30/4/2011, 16:40

» Tài liệu Windows Server 2003
by cambeme 30/4/2011, 08:40

» Phần mềm
by cambeme 29/4/2011, 12:35

» Công cụ tạo máy ảo VMware Workstation 7.1.4 Build 385546 Final
by cambeme 25/4/2011, 20:08

» Đề kiểm tra giữa kỳ Network
by cambeme 15/4/2011, 11:53

» Higher Computing Systems Networking
by cambeme 15/4/2011, 10:40

» Bài tập chương 6
by cambeme 12/4/2011, 17:41

No copy

Share | 
 

 Assignment 02: Simple Calculating

Xem chủ đề cũ hơn Xem chủ đề mới hơn Go down 
Tác giảThông điệp
cambeme
Admin
Admin
cambeme


Giới tính Giới tính : Nam
Cung : Nhân Mã
Con giáp : Mùi
Bài gửi Bài gửi : 174
Điểm Điểm : 5271
Thanks Thanks : 0
Sinh nhật Sinh nhật : 05/12/1991
Ngày gia nhập Ngày gia nhập : 25/03/2011
Tuổi Tuổi : 32
Đến từ Đến từ : Thành phố Hồ Chí minh
Nghề nghiệp/ước mơ Nghề nghiệp/ước mơ : IT
Tâm trạng Tâm trạng : Hưng phắn
Châm ngôn sống Châm ngôn sống : Không có gì quý hơn hột vịt thịt kho!
Cao nhân tắt thở vô phương trị!


Assignment 02: Simple Calculating Empty
Bài gửiTiêu đề: Assignment 02: Simple Calculating   Assignment 02: Simple Calculating I_icon_minitime18/10/2011, 23:50

Assignment 02: Simple Calculating Titleb10 18/10/2011, 23:50 » Assignment 02: Simple Calculating Assignment 02: Simple Calculating Titleb12
Bài 1:
Code:
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

/*
 * author Anh Trinh (T094054)
 */
public class cComputingSquareRoot_T094054 extends JFrame {
    // declare labels
    JLabel lblSource = new JLabel("Source:");
    JLabel lblErrors = new JLabel("Choose Errors:");
    // declare text field
    JTextField txtInput = new JTextField();
    // declare text area
    JTextArea txtResult = new JTextArea();
    // declare combo box
    JComboBox cmbChoose = new JComboBox();
    // declare buttons
    JButton btnCompute = new JButton("Compute");
    JButton btnClear = new JButton("Clear");
    JButton btnClearall = new JButton("Clear all");
    // declare scroll pane
    JScrollPane panResult = new JScrollPane(txtResult);
    // declare variable
    int i, j = 0;
    double input;
    String output;
    double d = 1.0;

    /*
    * constructor
    */
    public cComputingSquareRoot_T094054() {
        // set title
        setTitle("T094054 - Square Root");
        // set size
        setSize(400, 265);
        // set location
        setLocationRelativeTo(null);
        // reset null layout
        setLayout(null);
        // set resizable
        setResizable(false);
        // add labels to window
        add(lblSource);
        add(lblErrors);
        // add text to window
        add(txtInput);
        // add scroll bar to window
        add(panResult);
        // add buttons to window
        add(btnCompute);
        add(btnClear);
        add(btnClearall);
        // add combo box to window
        add(cmbChoose);
        // add data to combo box using for function
        for (int i = 1; i <= 8; i++) {
            cmbChoose.addItem(i);
        }// end for
            // default chosen item
        cmbChoose.setSelectedItem(2);
        // set location
        lblSource.setBounds(10, 10, 60, 20);
        txtInput.setBounds(80, 10, 150, 20);
        lblErrors.setBounds(235, 10, 90, 20);
        cmbChoose.setBounds(330, 10, 50, 20);
        btnCompute.setBounds(70, 40, 80, 25);
        btnCompute.setMargin(new Insets(1, 1, 1, 1));
        btnClear.setBounds(160, 40, 80, 25);
        btnClear.setMargin(new Insets(1, 1, 1, 1));
        btnClearall.setBounds(250, 40, 80, 25);
        btnClearall.setMargin(new Insets(1, 1, 1, 1));
        panResult.setBounds(10, 80, 375, 150);
        txtResult.setEditable(false);
        // add Action listener
        ActionListener method = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent arg0) {
                // TODO Auto-generated method stub
                // declare variable
                String sTmp = txtInput.getText().trim().toString();
                // calculate
                if (arg0.getSource() == btnCompute) {
                    // try function
                    try {
                        input = Double.parseDouble(sTmp);
                        // use if function to check the input data
                        if (input > 0) {
                            // check selected error
                            double c = cmbChoose.getSelectedIndex();
                            // use while function to calculate error which is
                            // selected
                            while (j <= c) {
                                d = d / 10;
                                j++;
                            }// end while
                                // declare variable
                            double x0 = 1;
                            double x = (1 + input) / 2;
                            // using while function to calculate square root
                            while (x - x0 > d || x - x0 < (-d)) {
                                x0 = x;
                                x = (x0 + input / x0) / 2;
                            }// end while
                            output = "Sqrt(" + sTmp + ")= " + x + "\n";
                            d = 1.0;
                            j = 0;
                        }// end if
                        else if (input < 0) {
                            output = "Invalid Input" + "\n";
                        }// end if
                        else if (input == 0) {
                            output = "Sqrt(" + sTmp + ")= " + 0 + "\n";
                        }// End if
                    }// end try
                    catch (Exception e) {
                        // TODO: handle exception
                        output = "Invalid Input" + "\n";
                    }// end catch
                    txtResult.append(output);
                }// end if
                else if (arg0.getSource() == btnClear) {
                    txtInput.setText("");
                }// end if
                else if (arg0.getSource() == btnClearall) {
                    txtInput.setText("");
                    txtResult.setText("");
                    // default chosen item
                    cmbChoose.setSelectedItem(2);
                }// end if
            }// end actionPerformed
        };// end actionListener
            // add actionListener to buttons
        btnCompute.addActionListener(method);
        btnClear.addActionListener(method);
        btnClearall.addActionListener(method);
    }// end constructor

    /**
    * @param args
    */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        // new window
        cComputingSquareRoot_T094054 window = new cComputingSquareRoot_T094054();
        // end program as closing window.
        window.setDefaultCloseOperation(EXIT_ON_CLOSE);
        // show the window
        window.setVisible(true);

    }// end main function

}// end class
Bài 2:
Code:
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

/*
 * author Anh Trinh (T094054)
 */
public class cComputingSinFunction_T094054 extends JFrame {
    // declare labels
    JLabel lblSource = new JLabel("Source:");
    JLabel lblErrors = new JLabel("Choose Errors:");
    // declare text field
    JTextField txtInput = new JTextField();
    // declare text area
    JTextArea txtResult = new JTextArea();
    // declare combo box
    JComboBox cmbChoose = new JComboBox();
    // declare buttons
    JButton btnCompute = new JButton("Compute");
    JButton btnClear = new JButton("Clear");
    JButton btnClearall = new JButton("Clear all");
    // declare scroll pane
    JScrollPane panResult = new JScrollPane(txtResult);
    // declare variable
    int i, j = 0;
    double input;
    String output;
    double d = 1.0;

    /*
    * constructor
    */
    public cComputingSinFunction_T094054() {
        // set title
        setTitle("T094054 - Sin Function");
        // set size
        setSize(400, 265);
        // set location
        setLocationRelativeTo(null);
        // reset null layout
        setLayout(null);
        // set resizable
        setResizable(false);
        // add labels to window
        add(lblSource);
        add(lblErrors);
        // add text to window
        add(txtInput);
        // add scroll bar to window
        add(panResult);
        // add buttons to window
        add(btnCompute);
        add(btnClear);
        add(btnClearall);
        // add combo box to window
        add(cmbChoose);
        // add data to combo box using for function
        for (int i = 1; i <= 8; i++) {
            cmbChoose.addItem(i);
        }// end for
            // default chosen item
        cmbChoose.setSelectedItem(2);
        // set location
        lblSource.setBounds(10, 10, 60, 20);
        txtInput.setBounds(80, 10, 150, 20);
        lblErrors.setBounds(235, 10, 90, 20);
        cmbChoose.setBounds(330, 10, 50, 20);
        btnCompute.setBounds(70, 40, 80, 25);
        btnCompute.setMargin(new Insets(1, 1, 1, 1));
        btnClear.setBounds(160, 40, 80, 25);
        btnClear.setMargin(new Insets(1, 1, 1, 1));
        btnClearall.setBounds(250, 40, 80, 25);
        btnClearall.setMargin(new Insets(1, 1, 1, 1));
        panResult.setBounds(10, 80, 375, 150);
        txtResult.setEditable(false);
        // add Action listener
        ActionListener method = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent arg0) {
                // TODO Auto-generated method stub
                // declare variable
                String sTmp = txtInput.getText().trim().toString();
                // calculate
                if (arg0.getSource() == btnCompute) {
                    // try function
                    try {
                        input = Double.parseDouble(sTmp);
                        // check selected error
                        double c = cmbChoose.getSelectedIndex();
                        // use while function to calculate error which is
                        // selected
                        while (j <= c) {
                            d = d / 10;
                            j++;
                        }// end while
                            // declare variable
                        double x0 = 1;
                        double x = 1;
                        double y = input;
                        int k = 2;
                        // using if to check if -1< sinx <1
                        if (x >= (-1) && x <= 1) {
                            x = input;
                            // using while function to calculate sin
                            while (x - x0 > d || x - x0 < (-d)) {
                                x0 = x;
                                y = (-1) * y * (input * input) / ((k + 1) * k);
                                x = x + y;
                                k = k + 2;
                            }// end while
                            output = "Sin(" + sTmp + ")= " + x + "\n";
                            d = 1.0;
                            j = 0;
                            k = 2;
                        }// end if
                    }// end try
                    catch (Exception e) {
                        // TODO: handle exception
                        output = "Invalid Input" + "\n";
                    }// end catch
                    txtResult.append(output);
                }// end if
                else if (arg0.getSource() == btnClear) {
                    txtInput.setText("");
                }// end if
                else if (arg0.getSource() == btnClearall) {
                    txtInput.setText("");
                    txtResult.setText("");
                    // default chosen item
                    cmbChoose.setSelectedItem(2);
                }// end if
            }// end actionPerformed
        };// end actionListener
            // add actionListener to buttons
        btnCompute.addActionListener(method);
        btnClear.addActionListener(method);
        btnClearall.addActionListener(method);
    }// end constructor

    /**
    * @param args
    */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        // new window
        cComputingSinFunction_T094054 window = new cComputingSinFunction_T094054();
        // end program as closing window.
        window.setDefaultCloseOperation(EXIT_ON_CLOSE);
        // show the window
        window.setVisible(true);

    }// end main function

}// end class
Bài 3:
Code:
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

/*
 * author Anh Trinh (T094054)
 */
public class cComputingCosinFunction_T094054 extends JFrame {
    // declare labels
    JLabel lblSource = new JLabel("Source:");
    JLabel lblErrors = new JLabel("Choose Errors:");
    // declare text field
    JTextField txtInput = new JTextField();
    // declare text area
    JTextArea txtResult = new JTextArea();
    // declare combo box
    JComboBox cmbChoose = new JComboBox();
    // declare buttons
    JButton btnCompute = new JButton("Compute");
    JButton btnClear = new JButton("Clear");
    JButton btnClearall = new JButton("Clear all");
    // declare scroll pane
    JScrollPane panResult = new JScrollPane(txtResult);
    // declare variable
    int i, j = 0;
    double input;
    String output;
    double d = 1.0;

    /*
    * constructor
    */
    public cComputingCosinFunction_T094054() {
        // set title
        setTitle("T094054 - Cosin Function");
        // set size
        setSize(400, 265);
        // set location
        setLocationRelativeTo(null);
        // reset null layout
        setLayout(null);
        // set resizable
        setResizable(false);
        // add labels to window
        add(lblSource);
        add(lblErrors);
        // add text to window
        add(txtInput);
        // add scroll bar to window
        add(panResult);
        // add buttons to window
        add(btnCompute);
        add(btnClear);
        add(btnClearall);
        // add combo box to window
        add(cmbChoose);
        // add data to combo box using for function
        for (int i = 1; i <= 8; i++) {
            cmbChoose.addItem(i);
        }// end for
            // default chosen item
        cmbChoose.setSelectedItem(2);
        // set location
        lblSource.setBounds(10, 10, 60, 20);
        txtInput.setBounds(80, 10, 150, 20);
        lblErrors.setBounds(235, 10, 90, 20);
        cmbChoose.setBounds(330, 10, 50, 20);
        btnCompute.setBounds(70, 40, 80, 25);
        btnCompute.setMargin(new Insets(1, 1, 1, 1));
        btnClear.setBounds(160, 40, 80, 25);
        btnClear.setMargin(new Insets(1, 1, 1, 1));
        btnClearall.setBounds(250, 40, 80, 25);
        btnClearall.setMargin(new Insets(1, 1, 1, 1));
        panResult.setBounds(10, 80, 375, 150);
        txtResult.setEditable(false);
        // add Action listener
        ActionListener method = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent arg0) {
                // TODO Auto-generated method stub
                // declare variable
                String sTmp = txtInput.getText().trim().toString();
                // calculate
                if (arg0.getSource() == btnCompute) {
                    // try function
                    try {
                        input = Double.parseDouble(sTmp);
                        // check selected error
                        double c = cmbChoose.getSelectedIndex();
                        // use while function to calculate error which is
                        // selected
                        while (j <= c) {
                            d = d / 10;
                            j++;
                        }// end while
                            // declare variable
                        double x0 = 0;
                        double x = 1;
                        double y = 1;
                        int k = 1;
                        // using if to check if -1< cosinx <1
                        if (x >= (-1) && x <= 1) {
                            // using while function to calculate cosin
                            while (x - x0 > d || x - x0 < (-d)) {
                                x0 = x;
                                y = (-1) * y * (input * input) / ((k + 1) * k);
                                x = x + y;
                                k = k + 2;
                            }// End while
                            output = "Cos(" + sTmp + ")= " + x + "\n";
                            d = 1.0;
                            j = 0;
                            k = 2;
                        }// end if
                    }// end try
                    catch (Exception e) {
                        // TODO: handle exception
                        output = "Invalid Input" + "\n";
                    }// end catch
                    txtResult.append(output);
                }// end if
                else if (arg0.getSource() == btnClear) {
                    txtInput.setText("");
                }// end if
                else if (arg0.getSource() == btnClearall) {
                    txtInput.setText("");
                    txtResult.setText("");
                    // default chosen item
                    cmbChoose.setSelectedItem(2);
                }// end if
            }// end actionPerformed
        };// end actionListener
            // add actionListener to buttons
        btnCompute.addActionListener(method);
        btnClear.addActionListener(method);
        btnClearall.addActionListener(method);
    }// end constructor

    /**
    * @param args
    */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        // new window
        cComputingCosinFunction_T094054 window = new cComputingCosinFunction_T094054();
        // end program as closing window.
        window.setDefaultCloseOperation(EXIT_ON_CLOSE);
        // show the window
        window.setVisible(true);

    }// end main function

}// end class



Assignment 02: Simple Calculating Border11 Assignment 02: Simple Calculating Border14
Về Đầu Trang Go down
https://nhom1.forum-viet.com
 

Assignment 02: Simple Calculating

Xem chủ đề cũ hơn Xem chủ đề mới hơn Về Đầu Trang 

 Similar topics

-
» Assignment 04 – Simple Loop
» Assignment 02 – Simple Computing and Converter
» Assignment 05 – Imazing
» Assignment 08: Methods
» Assignment 09: Classes
Trang 1 trong tổng số 1 trang

Permissions in this forum:Bạn không có quyền trả lời bài viết
K16T1 Nhóm 1 :: Các môn học :: Năm 2 :: Java 2-
Chuyển đến 
Đầu trang
Giữa trang
Cuối trang
Free forum | ©phpBB | Free forum support | Báo cáo lạm dụng | Thảo luận mới nhất