1. PROGRAM FILE
Particulars of the student
Name: Nidhi Gupta
Roll No. :
Class: XII Commerce A
Particulars of the Supervisor
Name: Monika Sharma
Designation: Sardar Patel Public Senior Secondary
School
2. ACKNOWLEDGEMENT
It is with great pleasure that I find myself
penning down these lines to express my
sincere thanks to various people who helped
me a long way in completing this project.
The harmonious climate in our school provided
proper guide for preparing the project. It was
a privilege to have been guided by Mrs. Monika
Sharma.
Thanks to all my classmates who helped me
during the development of this project with
their constructive criticism and advice.
NEW DELHI Nidhi Gupta
Roll no.
3. NETBEANS PROGRAMS
1. Write a Java desktop application to find the sum of two
numbers using Java method.
Ans.
Coding :
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
public void Sum_Num()
{
int a, b, sum = 0;
a = Integer.parseInt(jTextField1.getText());
b = Integer.parseInt(jTextField2.getText());
4. sum = a + b ;
jTextField3.setText(" " + sum);
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
Sum_Num();
}
Result :
2. Create an application to enter your name and age in
separate JTextField controls and display both name and
age in a JLabel control.The display will perform when
youy press aJButton control.Notice that theJButton will
perform its action event operation.
Ans.
5. Coding :
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String name = jTextField1.getText();
int age = Integer.parseInt(jTextField2.getText());
jLabel3.setText("Name is: " + name + " and Age is:" + age);
}
Result :
6. 3. Create a java Desktop Application which adds sevral
employee’s name , removes a selected name and clear
all the employee’s names from a JComboBox control.
Ans.
7. Coding :
private void btnCloseActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
private void btnCAddActionPerformed(java.awt.event.ActionEvent evt) {
//Creating a String object Ename
String Ename = txtEname.getText();
//Creating a ComboBoxModel object cModel to perform
//DefaultComboBoxModel method operations
DefaultComboBoxModel cModel =
(DefaultComboBoxModel) jComboBox1.getModel();
//Method to add elements into jComboBox1 control
cModel.addElement(Ename);
//Sets the data model for jComboBox1 control
jComboBox1.setModel(cModel);
9. 4. Create a java desktop application to perform a
concatenation opretion for the two JTextField
components on the window.get First name and Last
name in it. On clicking Click to Concatenate button a
message should appear by joining First name + Last
name.
Ans.
11. 5. Write a program to perform the closing window
operation with different buttons.
Ans.
12. Coding :
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
jLabel2.setText("Red light is on, please relax");
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
jLabel2.setText("Yellow light is on, please stop");
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
jLabel2.setText("Green ligh is on, please go");
}
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
jLabel2.setText("You perform demo buttons.");
System.exit(0);
}
Result :
13. 6. Create a Jav Desktop Application to enter your friends
rollno,name,address,section and grade. Using
aJButton’s click evant handler, display the details of
inputs into aJTextArea control.
Ans.
Coding :
15. 7. Demonstrate global scope variable in Java GUI
application.
Ans.
Coding :
@SuppressWarnings("unchecked")
public int i;
void Scope2()
{
i = 20;
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
Scope2();
int i = 40;
jTextArea1.append(i + "n");
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
16. }
Result :
8. Demonstrating if Statement to add contents into a
JTextArea component.
Ans.
17. Coding :
private void bntExitActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
private void btnResultActionPerformed(java.awt.event.ActionEvent evt) {
int num;//Variable to hold input value.
double square;//Variable to hold square value.
num = Integer.parseInt(txtNum.getText());
if(num < 120)
{
square = num*num;
//jTextArea component appending text into its area
// /n is used as escape sequence andpointer transfer into next line
jTextArea1.append("The square of" + num + square + "n");
}
if (num >= 120)
{
jTextArea1.append("***Square is not allowed for numbers over120***n");
jTextArea1.append("Run this program again and try a smaller value.n");
}
jTextArea1.append("Thank you for requesting squares."
}
Result :
18. 9. Develop a GUI application to demonstrate the
JCheckBox By inputing your name in a JTextField
control and set different font, style, size and color into
name using JCheckBox control.
Ans.
21. 10. Write a GUI application to display the JList control
value an oter controls like JLabel,jTextField and
JTextArea.Perform the opreation with aJbutton
ActionPerformed procedure.
Ans.
Coding :
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String pName = (String) jList1.getSelectedValue();
jLabel1.setText("You selected" + pName);
jTextField1.setText(pName);
jTextArea1.append(pName);
}
22. Result :
11. Design a GUI application to input different numbers
through keyboard using showInputdialog method and
find maximum number between n numbers.
Ans.
23. Coding :
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
int max = 0, i = 1, num, n;
String str = JOptionPane.showInputDialog("Enter total number number you want find maximum...");
n = Integer.parseInt(str);
while(i <= n){
str =JOptionPane.showInputDialog("Enter number",i);
jTextArea1.append(s tr + "n");
num =Integer.parseInt(str);
if (num > max)
max = num;
i++;
}
jTextField1.setText(Integer.toString(max));
}
Result :
24. 12. Create an application using JButton component to
print “Hello NetBeans Programmer” in a message box
.note that the message box can be created with the
showMessageDialog() method.This method is the
instance of Java JOptionPane class.So before using this
method add the following line at the top of source:
Import javax.swing.JOptionPane;
Ans.
25. Coding :
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
JOptionPane.showMessageDialog(this,"Hello NetBeans Programmer");
}
Result :
13. Develop a Java desktop application to demonstrate
JOptionPane dialog boxwith differentmessages and
opton button.
Ans.
30. 15. Create a Java desktop application to perform a
password entry system and also see the entry in a
message window.
Ans.
31. Coding :
private void jPasswordField1ActionPerformed(java.awt.event.ActionEvent evt) {
//Extract a password string into String passW
String passW = new String(jPasswordField1.getPassword());
JOptionPane.showMessageDialog(this,passW);
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
Result :
32. 16. Develop a Java DesktopApplication to display a
message “Hello! I am a Java NetBeans IDE
Programmer.”using two commandbuttons Print and Exit.
Ans.
Coding :
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
jLabel1.setText("Hello I am a java programmer.");
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
Result :
33. 17. Design a GUI application to input any number and
print them in reverse order using while
statement.Whereas the input number must be positive
otherwise display a message containing (“The number
must be positive”).
Ans.
Coding :
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String str;
int value, rDigit;
value = 0;
while(value <= 0) {
value = Integer.parseInt(jButton1.getText());
if(value <= 0) {
JOptionPane.showMessageDialog(this,"The number must be positive");
34. break;
}
}
str = "";
while(value!=0){
rDigit = value%10;
str = str + Integer.toString(rDigit);
value = value /10;
}
jButton1.setText(str);
}
Result :
18. Create a GUI application to calculate the simple
interest .Using four JLabel, four JTextField and two
JButton control s input the principal amount, interest
rate and time period.Find the interest amount using
Calculate button.
Ans.
35. Coding :
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
double Principal = Double.parseDouble(jTextField1.getText());
double Rate = Double.parseDouble(jTextField2.getText());
double Time = Double.parseDouble(jTextField3.getText());
double SI =(Principal*Rate*Time)/100;
jTextField4.setText(""+ SI);
}
Result :
36. 19. Create GUI Desktop Application to find sum of two
numbers using showInputDialog() method.
Ans.
Coding :
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
37. int Fnumber,Snumber,sum;
String num1, num2;
num1 = JOptionPane.showInputDialog("Enter number");
num2 = JOptionPane.showInputDialog("Enter number");
Fnumber = Integer.parseInt(num1);
Snumber = Integer.parseInt(num2);
sum = Fnumber = Snumber;
JOptionPane.showMessageDialog(null,"The sum of two number is" + sum);
}
Result :
38. 20. Develop a java Desktop Application to Verify
wherther the swapped ATM card accepted password or
not.
Ans.
Coding :
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
39. private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String iPass = "mohan 123";
String Epass = new String (jPasswordField1.getPassword());
if(Epass.equals(iPass)){
jTextField3.setText("You are a valid ATM holder");
}else
jTextField3.setText("You don't have an account in SBI");
}
Result :
40. MYSQL COMMAND QUERIES
1. Write a query to display the TNO, TNAME and salary
from TEACHER table.
Ans.
2. Write a query to display teacher name and salary for all
teacher whose salary is greater than equal to 20000.
Ans.
3. Write a query to display the teacher name either
‘Rakesh Sharma’ or ‘Jugal Mittal’.
Ans.
41. 4. Write a query to display the teacher information whose
salary is not more than 15000.
Ans.
5. Write a query to display distinct department no.
(dept_no) from TEACHER table.
Ans.
6. Write a query to display the teacher no and teacher
name whose salary is not in between 15000 and 20000.
Ans.
42. 7. Write a query to display TNO,TNAME and SALARY
whose salary is more than 18000 using colulmn alias.
Ans.
8. Write a query to display TNO, TNAME and SALARY
whose salary is more than 18000 using column alias.
Ans.
9. Write a query to display TNO, TNAME and ANNUAL
salary of all TEACHERS.
43. Ans.
10. Write a query to retrive the first five rows of the
table TEACHER.
Ans.