You are on page 1of 42

S.

NO PARTICULARS
1.
run mode :

code for "-" button:


private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {

Double a,b,Result;

a=Double.parseDouble(jTextField1.getText());

b=Double.parseDouble(jTextField2.getText());

Result=a-b;

jTextField3.setText(Double.toString(Result));

RUn mode :
code for "*" button:

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {

Double a,b,Result;

a=Double.parseDouble(jTextField1.getText());

b=Double.parseDouble(jTextField2.getText());

Result=a*b;

jTextField3.setText(Double.toString(Result));

run mode:
code for "/" button:

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {

Double a,b,Result;

a=Double.parseDouble(jTextField1.getText());

b=Double.parseDouble(jTextField2.getText());

Result=a/b;

jTextField3.setText(Double.toString(Result));

run mode :
code for "clear" button:

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {

jTextField1.setText("");

jTextField2.setText("");

jTextField3.setText("");

Q2. Make simple decision making (if statement) application and display
relevant message using GUI application (Example- problems related to
Eligibility for a given age, Profit or Loss message for a given value.
code to check eligibility :

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

if(Integer.parseInt(jTextField1.getText())>18)

JOptionPane.showMessageDialog(null,"You are eligible to vote");

else

JOptionPane.showMessageDialog(null,"You are NOT eligible to vote");

Q3. Make simple applications using check boxes, list boxes, etc.
code for bill button:

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

int Total=0,disc=0,amount=0;

if(jList1.isSelectedIndex(0)==true)

Total=Total+200;

JOptionPane.showMessageDialog(null,"Pasta ordered Rs 200");

if(jList1.isSelectedIndex(1)==true)

Total=Total+100;

JOptionPane.showMessageDialog(null,"Noodles ordered Rs 200");

}
code to check eligibility :

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

if(Integer.parseInt(jTextField1.getText())>18)

JOptionPane.showMessageDialog(null,"You are eligible to vote");

else

JOptionPane.showMessageDialog(null,"You are NOT eligible to vote");

Q3. Make simple applications using check boxes, list boxes, etc.
}

if(jCheckBox3.isSelected())

disc=40;

amount=Total+disc;

jTextField2.setText(Integer.toString(disc));

jTextField3.setText(Integer.toString(amount));

Q4. Use of text area-append details from different text boxes.


Code for “Lets Go”

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

jTextArea1.append(jTextField1.getText());

}
Code for “Clear Line”

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {

jTextField1.setText("");

}
Code for “Space”

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {

jTextArea1.append("");

Q5. Simple Interest Calculation.


Code for “Calculate S.Interest”

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

double Principal,SInterest; int Rate,Time;

Principal=Double.parseDouble(jTextField1.getText());

Rate=Integer.parseInt(jTextField2.getText());

Time=Integer.parseInt(jTextField3.getText());

SInterest=(Principal*Rate*Time)/100;

jTextField4.setText(Double.toString(SInterest));

Code for “Clear Button”

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {


Code for “Lets Go”

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

jTextArea1.append(jTextField1.getText());

}
Code for “Clear Line”

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {

jTextField1.setText("");

}
Code for “Space”

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {

jTextArea1.append("");

Q5. Simple Interest Calculation.


code for result button :

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

double Num1,Num2;

Num1=Double.parseDouble(jTextField1.getText());

Num2=Double.parseDouble(jTextField2.getText());

if(Num1>Num2)

JOptionPane.showMessageDialog(this,"Num1 is Greater");

else

JOptionPane.showMessageDialog(this,"NUm2 is Greater");

Q7. To find total, percentage and grades of five subjects.


Code for “Calculate S.Interest”

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

double Principal,SInterest; int Rate,Time;

Principal=Double.parseDouble(jTextField1.getText());

Rate=Integer.parseInt(jTextField2.getText());

Time=Integer.parseInt(jTextField3.getText());

SInterest=(Principal*Rate*Time)/100;

jTextField4.setText(Double.toString(SInterest));

Code for “Clear Button”

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {


jTextField1.setText("");

jTextField2.setText("");

jTextField3.setText("");

jTextField4.setText("");

}
run mode :

Q6. To find Greater among 2 numbers / 3 numbers.


code for result button :

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

double Num1,Num2;

Num1=Double.parseDouble(jTextField1.getText());

Num2=Double.parseDouble(jTextField2.getText());

if(Num1>Num2)

JOptionPane.showMessageDialog(this,"Num1 is Greater");

else

JOptionPane.showMessageDialog(this,"NUm2 is Greater");

Q7. To find total, percentage and grades of five subjects.


private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

double Finalamt=0;

double Billamt=Double.parseDouble(jTextField1.getText());

switch(jComboBox1.getSelectedIndex())

case 0: Finalamt=Billamt;//No Discount for new customer

break;

case 1: Finalamt=0.90*Billamt;//10% Discount for silver

break;

case 2: Finalamt=0.80*Billamt;//20% Discount for gold

break;

case 3: Finalamt=0.70*Billamt;//30% Discount for platinum

break;

default: Finalamt=Billamt;
}

jTextField2.setText(Double.toString(Finalamt));

Q10. Use of math methods.


private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

double a,b,c;

a=Double.parseDouble(jTextField1.getText());

b=Double.parseDouble(jTextField2.getText());

c=Math.pow(a,b);

jTextField3.setText(Double.toString(c));

Q11. To count number of vowels in a given string.


private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

String S= jTextField1.getText();

int x=S.length();

int vowel=0;

for(int i=0; i<x; i++)

String a=S.substring(i,i+1);

a=a.toLowerCase();

if(a.equals("a")||a.equals("e")||a.equals("i")||a.equals("o")||a.equals("u"))

vowel++;

Q12. Use of string method.


private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

String a=jTextField1.getText();

int x=a.length();

jTextField2.setText(Integer.toString(x));

String b=a.toLowerCase();

jTextField3.setText(b);

String c=a.toUpperCase();

jTextField4.setText(c);

Q13. To check if entered character is a vowel.


private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

String a=jTextField1.getText();

a=a.toLowerCase();

if(a.equals("a")||a.equals("e")||a.equals("i")||a.equals("o")||a.equals("u"))

JOptionPane.showMessageDialog(this,"YES");

else

JOptionPane.showMessageDialog(this,"NO");

Q14. To display Number of characters in a word.


private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

String a=jTextField1.getText();

int x=a.length();

jTextField2.setText(Integer.toString(x));

Q15. To check if number is odd or even.


private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

int a=Integer.parseInt(jTextField1.getText());

if((a%2)==0)

System.out.print("The Number is EVEN");

else

System.out.print("The Number is ODD");

The Number is EVEN

Q16. To check if a number is Palindrome.


private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

int a,b,c=0;

a=Integer.parseInt(jTextField1.getText());

int d=a;

while(a>0)

b=a%10;

a=a/10;

c=c*10+b;

if(c==d)

System.out.print("YES");

else

System.out.print("NO");

Q17. To check if a string is Palindrome.


private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

String a=jTextField1.getText();

int x=a.length();

jTextField2.setText(Integer.toString(x));

Q15. To check if number is odd or even.


1.

submit

int eno=Integer.parseInt(jTextField3.getText());

String month=jTextField4.getText();

int leave =Integer.parseInt(jTextField1.getText());

float overtime=Float.parseFloat(jTextField2.getText());

String year=jTextField5.getText();

overtime=overtime*200;
try

{ Class.forName("java.sql.Driver");

Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/employee","root","1
234");

Statement stmt = con.createStatement();

String query= "INSERT INTO work_details


VALUES('"+leave+"','"+overtime+"','"+eno+"','"+month+"','"+year+"');";

JOptionPane.showMessageDialog(this,query);

stmt.executeUpdate(query);

catch(Exception e)

{ JOptionPane.showMessageDialog(this,e.getMessage());

2.
show
String month=jTextField1.getText();

DefaultTableModel model=(DefaultTableModel)jTable1.getModel();

try

Class.forName("java.sql.Driver");

Connection con =
(Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/anurag"
,"root","1234");

Statement stmt = (Statement) con.createStatement();


String query= "SELECT * from sal where month='"+month+"';";

ResultSet rs= stmt.executeQuery(query);

while(rs.next())

String eno= rs.getString("eno");

String basic= rs.getString("basic");

String red = rs.getString("reductions");

String inc = rs.getString("incentive");

String sal = rs.getString("salary");

model.addRow(new Object[] {eno,basic,red,inc,sal});

catch(Exception e)

JOptionPane.showMessageDialog(this,e.getMessage());

}
1. Command for creating a database.

2. Command for using the database.


3. Command for creating a table.

4. Command for showing the structure of table.

5. Command to show tables present in database.

6. Command for inserting data into a table.


7. Command to view the contents of the table.

8. Command to retrieve data.

9. Command for using keyword DISTINCT.


10. Command for using WHERE clause.

11. Command for using ORDER BY clause.

12. Command for using UPDATE .

13. Command for using ALTER (to modify structure of table).


14. Command for using LIKE operator.

15. Command for using aggregate functions.

16. Command for using GROUP BY.

17. Command for using HAVING clause.


18. Command for using Group by with order by.

19. Command for using group by and having clause with where clause.
20. Command for equi-join of tables.

21. Command to retrieve data from two tables.

22. Command for using group by clause in join.


23. Command for using group by and order by clause in equi-join.

24. Command for using where clause and group by.

25. Command for adding primary key.

26. Command to delete a column.

27. Command to remove primary key.


28. Command to increase marks.

29. Command to change data type of an existing column.

30. Command to a delete table.

You might also like