Sei sulla pagina 1di 25

Index for Java Programming

S.N
o

Program Description

A Java Desktop Application to display Welcome to Hello World


application in the message box.
A Java Desktop Application to enter your name and address in a message
box. Using two input boxes enter both name and address and also show in
another message window.
To perform a simple arithmetic operation(+-/*)and display the result in
message dialog or text box.
Accept cost price and sales price of product calculate the amount of profit
or loss and display the amount along with appropriate message.
A java application to calculate interest and amount . Use radio button.
Deveop a GUI application to find maximum between three numbers using
conditional operator.The operator will be used as nested manner.

2
3
4
5
6
7
8

9
10
11
12
13
14
15
16

Develop a GUI application to enter the month number & display


respective month name and days in that month.
Design a Application to demonstrate text book. User were enter
percentage marks & upon clicking the button Corresponding grade
should be display in the picture box.
Create a GUI application to change the properties of a swing
element based on the selection made by the user.
NDPL generate computerised bills for its customer every month.
Create a java application to print & sum Fibonnic series.
Create a Java Application to input any number and print its reverse using
while loop and print whether the number is palindrome or not.
Create a Java Application to calculate the bill of customer depending upon
the mode of payment.(Use Combo Box)
Create a Java application which adds player names, removes a selected
player and clear all the players name from jList control.

Create a java application to view the TEACHER table using jTable


control and java Database Connectivity (JDBC) using MySQL.
Create a java application to insert and display the record of customer
using connectivity with MySQL. Use the following structure.

Date

Signature

Q1) Create a java desktop application to display Welcome to hello world


application in the message box.

JOptionPane.showMessageDialog(this,"Welcome to hello world");

Q2) Create a java desktop application to your name & Address in the
message box. Using two input boxes enter both name and address & also
show Another message window.

String a=jTextField1.getText();
String b=jTextField2.getText();
JOptionPane.showMessageDialog(this,"Name: "+a+"\n"+"Address: "+b);

Q3) To perform Arithmetic operation & display the result in message


dialog or textbox using simple GUI application.

// ADD BUTTON
tf3.setEditable(false);
float a=Float.parseFloat(tf1.getText());
float b=Float.parseFloat(tf2.getText());
float c=a+b;
tf3.setText(String.valueOf(c));
//SUBTRACT BUTTON
tf3.setEditable(false);
float a=Float.parseFloat(tf1.getText());
float b=Float.parseFloat(tf2.getText());
float c=a-b;
tf3.setText(String.valueOf(c));

//MULTIPLY BUTTON
tf3.setEditable(false);
float a=Float.parseFloat(tf1.getText());
float b=Float.parseFloat(tf2.getText());
float c=a*b;
tf3.setText(String.valueOf(c));
//DIVIDE BUTTON
tf3.setEditable(false);
float a=Float.parseFloat(tf1.getText());
float b=Float.parseFloat(tf2.getText());
float c=a/b;
tf3.setText(String.valueOf(c));

Q4) Accept cost price & sale price of product calculate the amount of
profit or loss & display the amount along with appropiate message.

float cp=Float.parseFloat(tf1.getText());
float sp=Float.parseFloat(tf2.getText());
float total=sp-cp;
if(total>0)
c.setText("you have a profit of Rs"+total);
else if(total<0)
c.setText("you have a loss of Rs"+total);
else
c.setText("you have no profit and no loss");

Q5) Create a java application to calculate interest &amount use radio


button.

//CALCULATE BUTTON
float p=Float.parseFloat(pamt.getText());
float r=Float.parseFloat(rate.getText());
float t=Float.parseFloat(time.getText());
float interest=(p*r*t)/100;
if(intrst.isSelected())
{lbl.setText("your interest amount is "+interest);

}if(amt.isSelected())
{ float amount=interest+p;
lbl.setText("your amount is "+amount);
}

//CLEAR BUTTON
pamt.setText(" ");
rate.setText(" ");
time.setText(" ");
//EXIT BUTTON
System.exit(0);

Q6) Develop a GUI application to find maximum b/w three number


using conditional operator. The operator will be used as nested manner.

int fnum=Integer.parseInt(tf1.getText());
int snum=Integer.parseInt(tf2.getText());
int tnum=Integer.parseInt(tf3.getText());
if(fnum>snum&&fnum>tnum)
lbl.setText("First number is greater");
else if(snum>fnum&&snum>tnum)
lbl.setText("Second number is greater");
else if(tnum>fnum&&tnum>snum)
lbl.setText("third number is greater");
else if(fnum==snum&&fnum>tnum)
lbl.setText("First and second number are greater");
else if(snum==tnum&&snum>fnum)
lbl.setText("Second and third are greater");

else if(tnum==fnum&&tnum>snum)
lbl.setText("First and third number are greater");
else if(fnum==snum&&snum==tnum&&fnum==tnum)
lbl.setText("All are equal");

Q7) Develop a GUI application to enter the month number & display
respective month name and days in that month.

month.setEditable(false);
days.setEditable(false);
int a=Integer.parseInt(tf1.getText());
switch(a){
case 1:month.setText("January");
break;case 2:month.setText("February");
break;case 3:month.setText("March");
break;case 4:month.setText("April");
break;case 5:month.setText("May");
break;case 6:month.setText("June");
break;case 7:month.setText("July");
break;case 8:month.setText("August");
break;case 9:month.setText("September");

break;case 10:month.setText("October");
break;case 11:month.setText("November");
break;case 12:month.setText("December");break;
default:month.setText("please insert right number");

}if(a==1||a==3||a==5||a==7||a==8||a==10||a==12)
days.setText("31");
else if(a==4||a==6||a==9||a==11)
days.setText("30");
else if(a==2)
days.setText("28");

Q8) Design a Application to demonstrate text book. User were enter


percentage marks & upon clicking the button Corresponding grade
should be display in the picture box.

int per=Integer.parseInt(tf1.getText());
if(per>=90&&per<=100)
lbl.setText("A++");
else if(per>=80&&per<90)
lbl.setText("A+");
else if(per>=75&&per<80)
lbl.setText("A");
else if(per>=60&&per<75)
lbl.setText("B");
else if(per>=50&&per<60)
lbl.setText("C");
else if(per>=40&&per<50)

lbl.setText("D");
else if(per>=0&&per<40)
lbl.setText("E");
else
lbl.setText("please enter correct value");

Q9.Create a GUI application to change the properties of a swing


element based on the selection made by the user.

int color=cb.getSelectedIndex();
if(color==0){
lbl.setForeground(Color.red);
}if(color==1){
lbl.setForeground(Color.green);
}if(color==2){
lbl.setForeground(Color.blue);
}if(color==3){
lbl.setForeground(Color.white);
}if(color==4){
lbl.setForeground(Color.black);
}if(color==5){
lbl.setForeground(Color.yellow);}

Q10) NDPL generate computerised bills for its customer every month.

double charge=0;
int a=Integer.parseInt(tf.getText());
if(r.isSelected()){
c.setEnabled(true);
c1.setEnabled(true);
if(c.isSelected())
{charge=a*5.40;}
else if(c1.isSelected())
{ charge=a*4.92;}
}
if(r1.isSelected()){
c.setEnabled(true);

c1.setEnabled(true);
if(c.isSelected())
{charge=a*1.55;}
else if(c1.isSelected())
{charge=a*9.84;}
}
if(r2.isSelected()){
c.setEnabled(true);
c1.setEnabled(true);
if(c.isSelected())
{charge=a*5.05;}
else
if(c1.isSelected())
{charge=a*4.40;}
}
if(r3.isSelected()){
c.setEnabled(false);
c1.setEnabled(false);
if(a<=200)
charge=(a*2.45);
else if(a<=400)
charge=((a-200)*3.95)+490;
else if(a>400)
charge=((a-400)*4.65)+1280;
}

lbl.setText("The charges is : "+charge);

Q11) Create a java application to print & sum Fibonnic series.

int num=Integer.parseInt(tf1.getText());
int i,n=1,s=1;
jta.append(n+" ");
for(i=1;i<=num;i=n+s)
{jta1.append(i+" ");
n=s;
s=i;
}

Q12. Create a Java Application to input any number and print its
reverse using while loop and print whether the number is palindrome or
not.

tf2.setEditable(false);
int a=Integer.parseInt(tf1.getText());
int b=0,c=a;
while(a!=0){
b=(b*10)+(a%10);
a=a/10;
tf2.setText(" "+b);
}
if(c==b)lbl.setText("it is a palindrome ");
else
lbl.setText("It is not a palindrome ");

Q13. Create a Java Application to calculate the bill of customer


depending upon the mode of payment.(Use Combo Box)

tf2.setEditable(false);
tf3.setEditable(false);
float a=Float.parseFloat(tf1.getText());
float c=0,d;
int b=cb.getSelectedIndex();
if(b==0)
{c=(float) (a*0.1);}
if(b==1){
c= a*0.05F;
} if(b==2){
c=a*0.07F;}
tf2.setText(""+c);
d=c+a;
tf3.setText(""+d);

Q14. Create a Java application which adds player names, removes a


selected player and clear all the players name from jList control.

// Add Player
String name=tf.getText();
DefaultListModel dlm=(DefaultListModel)lst.getModel();
dlm.add(0, name);
lst.setModel(dlm);
// Remove Player
int index;
DefaultListModel dlm=(DefaultListModel)lst.getModel();
index=lst.getSelectedIndex();
dlm.remove(index);
lst.setModel(dlm);
//Clear All Names
DefaultListModel dlm=(DefaultListModel)lst.getModel();
dlm.removeAllElements();
lst.setModel(dlm);

Q 15) Create a java application to view the TEACHER table using


jTable control and java Database Connectivity (JDBC) using MySQL.

try{

Class.forName("java.sql.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost/school","root","mujeeb");

Statement stmt=null;
ResultSet rs=null;
stmt=con.createStatement();

String SQL="SELECT*fROM project";


rs=stmt.executeQuery(SQL);
int no=Integer.parseInt(tf.getText());
String name=tf1.getText();

String address=tf2.getText();
float Sal=Float.parseFloat(tf3.getText());
String dept=tf4.getText();
String date=tf5.getText();

String strSQL="INSERT INTO PROJECT(E_no,E_name,E_dob,E_Salary)VALUES ("+


(no)+",'"+(name)+"','"+(dob)+"',"+(Sal)+")";
int rowEffected=stmt.executeUpdate(strSQL);
JOptionPane.showMessageDialog(null, "Record Added Successfully");

con.close();
stmt.close();
rs.close();

}
catch(Exception e){
JOptionPane.showMessageDialog(this,e.getMessage());
}

Q 16) Create a java application to insert and display the record of


customer using connectivity with MySQL. Use the following structure.

try{
Class.forName("java.sql.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost/school","root","mujeeb");

Statement stmt=null;
ResultSet rs=null;
stmt=con.createStatement();

String SQL="SELECT*fROM cust";


rs=stmt.executeQuery(SQL);
int cno=Integer.parseInt(tf1.getText());
String name=tf2.getText();
float bill=Float.parseFloat(tf3.getText());

String strSQL="INSERT INTO cust(name,address,salary)VALUES ("+(name)+",'"+


(address)+"',"+(salary)+");";
int rowEffected=stmt.executeUpdate(strSQL);
JOptionPane.showMessageDialog(null, "Record Added Successfully");

con.close();
stmt.close();
rs.close();
}
catch(Exception e){
JOptionPane.showMessageDialog(this,e.getMessage());

Potrebbero piacerti anche