java programms

download java programms

of 22

Transcript of java programms

  • 7/31/2019 java programms

    1/22

    Session: 2011-12

    SUBMITTED BY: SUBMITTED TO:

    Shraddha Tiwari(20946) Mr. Basant kumar

    KNIITSULTANPUR

  • 7/31/2019 java programms

    2/22

    It has been a great experience to beIt has been a great experience to beinvolved in such PROJECT,involved in such PROJECT,

    working with classmates & gainingworking with classmates & gainingwrathful knowledge from our learnedwrathful knowledge from our learned

    teachers. We express our sincereteachers. We express our sincerethanks to thanks to MR. BASANTKUMAR without whomwithout whom

    tireless effort. The completion oftireless effort. The completion of

    Student forum would perhapsStudent forum would perhapsbeen impossible.been impossible.

    A lot of thanks to all the staffA lot of thanks to all the staffmembers whose precious guidancemembers whose precious guidance

    proved worthy in course ofproved worthy in course ofcompletion of this PROJECT reportcompletion of this PROJECT report

  • 7/31/2019 java programms

    3/22

    This is to certify that Javaprogramsembodies the originalwork done by Shraddha Tiwari

    during this project submission as apartial fulfillment of the requirement

    for the System Design Project ofdiploma in computer application

    ( DCA ) IIIrd year of Kamala NehruInstitute Of Information Technology,

    Sultanpur.

    Mr.Basant Ku.Vishwakarma

    GROUP-B

  • 7/31/2019 java programms

    4/22

    1. Design Application

    a. Calculator in Java Script

    CODES CALCULATER



  • 7/31/2019 java programms

    5/22

  • 7/31/2019 java programms

    6/22

    import java.awt.*;import java.awt.event.*;

    class cal extends Frame implements ActionListener{String s1,s2,s3,s4,s5;GridLayout gl;int c,n;

    Label l1=new Label(" My calculater ");TextField tf1=new TextField(25);

    Button b1=new Button(" 0 ");Button b2=new Button(" 1 ");Button b3=new Button(" 2 ");Button b4=new Button(" 3 ");

    Button b5=new Button(" 4 ");Button b6=new Button(" 5 ");Button b7=new Button(" 6 ");Button b8=new Button(" 7 ");Button b9=new Button(" 8 ");Button b10=new Button(" 9 ");Button b11=new Button(" + ");Button b12=new Button(" - ");Button b13=new Button(" * ");Button b14=new Button(" / ");Button b15=new Button(" = ");Button b16=new Button(" a/c ");Button b17=new Button(" exit ");

    public cal (String title){

    super(title);setLayout(new FlowLayout(FlowLayout.CENTER,200,100));add(l1);l1.setBackground(Color.yellow);

    add(tf1);add(b16);add(b2);add(b3);add(b4);add(b5);add(b6);add(b7);add(b8);add(b9);add(b10);add(b1);add(b11);add(b12);add(b13);add(b14);add(b15);add(b17);

  • 7/31/2019 java programms

    7/22

    b1.setBackground(Color.yellow);b2.setBackground(Color.yellow);b3.setBackground(Color.yellow);

    b4.setBackground(Color.yellow);b5.setBackground(Color.yellow);b6.setBackground(Color.yellow);

    b7.setBackground(Color.yellow);b8.setBackground(Color.yellow);b9.setBackground(Color.yellow);

    b10.setBackground(Color.yellow);b11.setBackground(Color.cyan);b12.setBackground(Color.cyan);

    b13.setBackground(Color.cyan);b14.setBackground(Color.cyan);b15.setBackgroun

    d(Color.pink);b16.setBackground(Color.red);b17.setBackground(Color.red);tf1.setBackground(Color.green);

    gl=new GridLayout(4,4,10,20);

    tf1.addActionListener(this);b1.addActionListener(this);b2.addActionListener(this);b3.addActionListener(this);b4.addActionListener(this);b5.addActionListener(this);b6.addActionListener(this);b7.addActionListener(this);b8.addActionListener(this);b9.addActionListener(this);b10.addActionListener(this);b11.addActionListener(this);b12.addActionListener(this);b13.addActionListener(this);

    b14.addActionListener(this);b15.addActionListener(this);b16.addActionListener(this);b17.addActionListener(this);}

    public void actionPerformed(ActionEvent e)

  • 7/31/2019 java programms

    8/22

    {if(e.getSource()==b1){s3=tf1.getText();s4="0";s5=s3+s4;tf1.setText(s5);}if(e.getSource()==b2){s3=tf1.getText();s4="1";s5=s3+s4;tf1.setText(s5);

    }if(e.getSource()==b3){s3=tf1.getText();s4="2";s5=s3+s4;tf1.setText(s5);}if(e.getSource()==b4){s3=tf1.getText();s4="3";s5=s3+s4;tf1.setText(s5);}if(e.getSource()==b5){s3=tf1.getText();s4="4";

    s5=s3+s4;tf1.setText(s5);}if(e.getSource()==b6){s3=tf1.getText();s4="5";

  • 7/31/2019 java programms

    9/22

    s5=s3+s4;tf1.setText(s5);}if(e.getSource()==b7){s3=tf1.getText();s4="6";s5=s3+s4;tf1.setText(s5);}if(e.getSource()==b8){s3=tf1.getText();s4="7";

    s5=s3+s4;tf1.setText(s5);}if(e.getSource()==b9){s3=tf1.getText();s4="8";s5=s3+s4;tf1.setText(s5);}if(e.getSource()==b10){s3=tf1.getText();s4="9";s5=s3+s4;tf1.setText(s5);}if(e.getSource()==b11){

    s1=tf1.getText();tf1.setText("");c=1;}if(e.getSource()==b12){s1=tf1.getText();

  • 7/31/2019 java programms

    10/22

    tf1.setText("");c=2;}if(e.getSource()==b13){s1=tf1.getText();tf1.setText("");c=3;}if(e.getSource()==b14){s1=tf1.getText();tf1.setText("");c=4;

    }if(e.getSource()==b15){s2=tf1.getText();if(c==1){n=Integer.parseInt(s1)+Integer.parseInt(s2);tf1.setText(String.valueOf(n));}elseif(c==2){n=Integer.parseInt(s1)-Integer.parseInt(s2);tf1.setText(String.valueOf(n));}elseif(c==3){n=Integer.parseInt(s1)*Integer.parseInt(s2);

    tf1.setText(String.valueOf(n));}elseif(c==4){n=Integer.parseInt(s1)/Integer.parseInt(s2);tf1.setText(String.valueOf(n));

  • 7/31/2019 java programms

    11/22

    }}if(e.getSource()==b16){tf1.setText("");}if(e.getSource()==b17){System.exit(0);}}

    public static void main (String[] args){

    cal ob1=new cal("Welcome ot General Math Operation");

    ob1.setSize(500,200);ob1.setVisible(true);

    }}

    OUTPUT

  • 7/31/2019 java programms

    12/22

    C).Bank Loan Interest Calculator in Java (AWT)

    import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.text.*;

    public class WageCalculator extends JFrame{

    // JLabel and JTextField for wage per hourprivate JLabel hourlyWageJLabel;private JTextField hourlyWageJTextField;

    // JLabel and JTextField for hours worked in a weekprivate JLabel hoursWorkedJLabel;private JTextField hoursWorkedJTextField;

    // JLabel and JTextField for gross wages

    private JLabel grossWagesJLabel;private JTextField grossWagesJTextField;

    // JButton to initiate wage calculationprivate JButton calculateJButton;

    // no-argument constructorpublic WageCalculator(){

    createUserInterface();}

    // create and position GUI components; register event handlerspublic void createUserInterface(){

  • 7/31/2019 java programms

    13/22

    // get content pane for attaching GUI componentsContainer contentPane = getContentPane();

    // enable explicit positioning of GUI components

    contentPane.setLayout( null );

    // set up hourlyWageJLabelhourlyWageJLabel = new JLabel();hourlyWageJLabel.setBounds( 16, 16, 90, 21 );hourlyWageJLabel.setText( "Hourly wage:" );contentPane.add( hourlyWageJLabel );

    // set up hourlyWageJTextField

    hourlyWageJTextField = new JTextField();hourlyWageJTextField.setBounds( 120, 16, 90, 21 );hourlyWageJTextField.setHorizontalAlignment(

    JTextField.RIGHT );contentPane.add( hourlyWageJTextField );

    // set up hoursWorkedJLabelhoursWorkedJLabel = new JLabel();hoursWorkedJLabel.setBounds( 16, 56, 90, 21 );

    hoursWorkedJLabel.setText( "Hours worked:" );contentPane.add( hoursWorkedJLabel );

    // set up hoursWorkedJTextFieldhoursWorkedJTextField = new JTextField();hoursWorkedJTextField.setBounds( 120, 56, 90, 21 );hoursWorkedJTextField.setHorizontalAlignment(

    JTextField.RIGHT );contentPane.add( hoursWorkedJTextField );

    // set up grossWagesJLabelgrossWagesJLabel = new JLabel();grossWagesJLabel.setBounds( 16, 96, 90, 21 );grossWagesJLabel.setText( "Gross wages:" );contentPane.add( grossWagesJLabel );

  • 7/31/2019 java programms

    14/22

    // set up grossWagesJTextFieldgrossWagesJTextField = new JTextField();grossWagesJTextField.setBounds( 120, 96, 90, 21 );

    grossWagesJTextField.setHorizontalAlignment(JTextField.RIGHT );grossWagesJTextField.setEditable( false );contentPane.add( grossWagesJTextField );

    // set up calculateJButtoncalculateJButton = new JButton();calculateJButton.setBounds( 120, 136, 90, 24 );calculateJButton.setText( "Calculate" );

    contentPane.add( calculateJButton );calculateJButton.addActionListener(

    new ActionListener() // anonymous inner class{

    // event handler called when calculateJButton clickedpublic void actionPerformed ( ActionEvent event ){

    calculateJButtonActionPerformed( event );

    }

    } // end anonymous inner class

    ); // end call to addActionListener

    // set properties of application's windowsetTitle( "Wage Calculator" ); // set title bar stringsetSize( 230, 200 ); // set window size

    setVisible( true ); // display window

    } // end method createUserInterface

    // get user input and call calculatePayprivate void calculateJButtonActionPerformed( ActionEvent event )

  • 7/31/2019 java programms

    15/22

    {// get hourly wagedouble hourlyWage =

    Double.parseDouble( hourlyWageJTextField.getText() );

    // get number of hours worked this weekdouble hoursWorked =

    Double.parseDouble( hoursWorkedJTextField.getText() );

    // gross wages for week; returned from method calculatePaydouble totalWages = calculatePay( hoursWorked, hourlyWage );

    // specify output format

    DecimalFormat dollars = new DecimalFormat( "$0.00" );

    // display gross wagesgrossWagesJTextField.setText( dollars.format( totalWages ) );

    } // end method calculateJButtonActionPerformed

    // calculate and display wages in grossWagesJTextFieldprivate double calculatePay( double hours, double wages )

    {// gross wages for week; calculated in if...else statementdouble total;

    // constant for maximum hours employee can// work before being paid for overtimefinal double HOUR_LIMIT = 40.0; // declare constant

    // determine gross wages

    if ( hours

  • 7/31/2019 java programms

    16/22

    {// wages for first 40 hours with time and a half addedtotal = ( wages * HOUR_LIMIT ) + ( hours - HOUR_LIMIT ) *

    ( 1.5 * wages );

    }

    return total;

    } // end method calculatePay

    // main methodpublic static void main( String[] args ){

    WageCalculator application = new WageCalculator();application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

    } // end method main

    } // end class WageCalculator

    OUTPUT

  • 7/31/2019 java programms

    17/22

    D).Score Grade Calculator in Java Script

    CODES

    Grade Calculator

    body {font-family: Arial, sans-serif;text-align: center;

    }

    form {width: 300px;margin: 0 auto;text-align: right;

    }.h-line {

    background-color: black;margin: 2px auto;width: 100%;height: 2px;

    }

    input {text-align: right;

    }

    Grade Calculator

    Enter only whole numbers.

    Test #1 Grade:

    Test #2 Grade:

  • 7/31/2019 java programms

    18/22

    maxlength="3">

    Final Exam Grade:

    Quiz Grade:

    Project Grade:

    Lab Grade:

    Final Grade (LetterGrade):

    function calcGrade() {

    var form = document.getElementById("form");var finalGrade = document.getElementById("final-

    grade");var input;var i = 6;var grade = [];

  • 7/31/2019 java programms

    19/22

  • 7/31/2019 java programms

    20/22

    if (grade[6] >= 90) {finalGrade.value = (grade[6] + " (A)");

    }}

    OUTPUT

  • 7/31/2019 java programms

    21/22

    E).Animation with Applet in JAVA

    CODESimport java .applet.*;

    import java.awt.*;public class animation extends Applet implements

    Runnable{

    Image img[];

    int i,j;

    int b=4;

    int a=4;

    Thread t;

    public void init(){

    img=new Image[4];

    j=0;for(i=0;i

  • 7/31/2019 java programms

    22/22

    }

    public void stop()

    {

    t=null;

    }

    }