Informatics Practicals
Informatics Practicals
Informatics Practicals
Learn to Add
AIM:
To create a GUI Application that will help KG students to add.
DESIGN:
SOURCE CODE:
For COMPUTE RESULT Button:
float num1=Float.parseFloat(tf1.getText());
float num2=Float.parseFloat(tf2.getText());
float num3=num1+num2;
tf3.setText(“”+num3);
Page 1 of 45
OUTPUT:
Page 2 of 45
PROGRAM-2
Area Calculator
AIM:
Write a program and design a GUI Application to find the area of a
circle,rectangle & square.
Design the form in such a way that only one option will be selected and its
area will be given.At run time fulfill the following:
1. If Circle option button is clicked, then only radius of the circle will be
entered.
2. If Rectangle option button is clicked, then the length & breadth will be
entered.
3. If Square option button is clicked, then the side will be entered.
4. When Exit button is clicked, then the window will be closed.
DESIGN:
Page 3 of 45
SOURCE CODE:
For Circle Radio Button:
jLabel2.enable(false);
TextB.enable(false);
TextA.enable(true);
jLabel2.setVisible(false);
TextB.setVisible(false);
jLabel2.enable(true);
TextA.setVisible(true);
TextB.setVisible(true);
TextA.enable(true);
TextB.enable(true);
jLabel2.setVisible(true);
TextB.enable(false);
Page 4 of 45
jLabel1.setText(“Enter the Side”);
TextA.enable(true);
jLabel2.setVisible(false);
TextB.setVisible(false);
double area=0
if(jr1.isSelected())
r=Float.parseFloat(TextA.getText());
area=Math.PI*r*r;
TextR.setText(“ ”+area);
else if(jr2.isSelected())
length=Float.parseFloat(TextA.getText());
breadth=Float.parseFloat(TextB.getText()):
area=length*breadth;
TextR=setText(“ “+area);
else
Page 5 of 45
{
side=Float.parseFloat(TextA.getText());
area=side*side;
TextR.setText(“ “+area);
System.exit(0);
OUTPUT:
Page 6 of 45
Page 7 of 45
PROGRAM -3
Tax Calculator
AIM:
To design a GUI Application that obtains 3 values on 3 text fields from user:
Hours Worked, Pay Rate & Tax Rate.
DESIGN:
SOURCE CODE:
For CALCULATE Button:
Int hours=Integer.parseInt(hwtf.getText());
double prate=Double.parseDouble(prtf.getText());
Page 8 of 45
double trate=Double.parseDouble(trtf.getText());
double payAmt=hours*prate;
double taxAmt=payAmt*trate;
pal.setText(“ “+payAmt);
tal.setText(“ “+taxtAmt);
OUTPUT:
Page 9 of 45
PROGRAM-4
Data Form
AIM:
Create a GUI Application that asks for some information about a student &
displays it in a ID card format
DESIGN:
SOURCE CODE:
String text1= ttf.getText();
Page 10 of 45
String text5= stf.getText();
Idta.append(“Class:”+text4+” “+text5);
OUTPUT:
Page 11 of 45
PROGRAM-5
Font Style
AIM:
To create a GUI Application to change the font style of a given statement.
DESIGN:
SOURCE CODE:
For Plain Radio Button:
tf.setFont(new Font(“Helvetica”,Font.PLAIN,18);
Page 12 of 45
For Bold Italic Button:
tf.setFont(new Font(“Helvetica”,Font.BOLD+Font.ITALIC,18);
OUTPUT:
Page 13 of 45
Page 14 of 45
PROGRAM-6
Number Palindrome
AIM:
To create a GUI Application to check whether the given number is
palindrome.
DESIGN:
SOURCE CODE:
For CHECK IN PALINDROME Button:
nt,num,orig,rem,rev=0;
num= Integer.parseInt(numTF.getText());
orig= num;
while(num!=0)
Page 15 of 45
rem=num%10;
rev= (rev*10)+rem;
num= num/10;
revTF.setText(“ “+rev);
if(rev==orig)
JOptionPane.showMessageDialog(null,”It is Palindrome.”);
else
OUTPUT:
Page 16 of 45
Page 17 of 45
PROGRAM-7
Login Page
AIM:
Write a program & design a GUI Application to create a login page.
DESIGN:
SOURCE CODE:
For SIGN IN Button:
String pwd= new String(pf.getPassword());
If(pwd.equals(“HAASHIR”))
Page 18 of 45
this.setVisible(false);
obj.setVisible(true);
else
OUTPUT:
Page 19 of 45
Page 20 of 45
PROGRAM-8
Grade Calculator
AIM:
To create a GUI Application to find the grade of a student.
DESIGN:
SOURCE CODE:
For Calculate Button:
float eng= Float.parseFloat(engtxt.getText());
Page 21 of 45
float eco= Float.parseFloat(ecotxt.getText());
ttl.setText(“ “+total);
if((per>=90)&&(per<=100))
{rslt.setText(“Outstanding”);}
else if((per>=80)&&(per<90))
{rslt.setText(“Excellent”);}
else if((per>=70)&&(per<80))
{rslt.setText(“Above Average”);}
else if((per>=60)&&(per<70))
{rslt.setText(“Average”);}
else if((per>=50)&&(per<60))
{rslt.setText(“Satisfactory”);}
else
{rslt.setText(“Fail”)}
Page 22 of 45
OUTPUT:
Page 23 of 45
PROGRAM-9
Display No. of Days
AIM:
To create a GUI Application to display the no. of days in a month.
DESIGN:
SOURCE CODE:
For HAS Button:
Int mon= Integer.parseInt(tf.getText());
Int numDays= 0;
Switch(mon)
case 1:
case 3:
case 5:
case 7:
Page 24 of 45
case 8:
case 10:
case 12:
numDays= 31;
break;
case 4:
case 6:
case 9:
case 11:
numDays= 30;
break;
case 2:
numDays= 28;
If(numDays==0);
{lbresult.setText(“Invalid”)}
else
Page 25 of 45
OUTPUT:
Page 26 of 45
PROGRAM-10
ABC Bank’s Fixed Deposit Scheme
AIM:
ABC Bank has launched its Fixed Deposit Scheme .As per this, for amounts
more than Rs.25000, it offers following rates of interests for its Fixe d Deposit
Accounts
For principal amount less than Rs.25000, it offers rate of interest as 6.0% per
annum. For time other than the specified ones, the rate of interest is 6.75%.
Page 27 of 45
DESIGN:
SOURCE CODE:
For CALCULATE Button:
double princ= Double.parseDouble(ptf.getText());
double rate= 0
if(princ<25000)
rate= 6.0
else
{switch(time)
{case 7:
rate= 7;
break;
Page 28 of 45
case 10:
rate= 8.5;
break;
case 15:
rate= 9.5;
break;
case 20:
rate= 12.0;
break;
default:
rate= 6.75;
break;}
Page 29 of 45
OUTPUT:
Page 30 of 45
PROGRAM-11
Fibonacci Series
AIM:
To create a GUI Application to find Fibonacci Series of a given number.
DESIGN:
SOURCE CODE:
For GENERATE Button:
int i, no, first=0,second=1, next;
no= Integer.parseInt(txtf.getText());
txta.append(“\t” + first);
first= second;
Page 31 of 45
second= next;
OUTPUT:
Page 32 of 45
PROGRAM-12
Enter Month, Display Days
AIM:
To create a GUI Application to give the no. of days of a given month.
DESIGN:
SOURCE CODE:
For OKAY Button:
Ingt month= Integer.parseInt(txt.getText());
Int days= 0;
String mon;
Switch(month)
{case 1:
Page 33 of 45
mon= “January”;
days= 31;
break;
case 2:
mon= “February”;
days= 28;
break;
case 3:
mon= “March”;
days= 31;
break;
case 4:
mon= “April”;
days= 30;
break;
case 5:
mon= “May”;
days= 30;
break;
case 6:
mon= “June”;
days= 30;
Page 34 of 45
break;
case 7:
mon= “July”;
days= 30;
break;
case 8:
mon= “August”;
days= 31;
break;
case 9:
mon= “September”;
days= 30;
break;
case 10:
mon= “October”;
days= 31;
break;
case 11:
mon= “November”;
days= 30;
break;
case 12:
Page 35 of 45
mon= “December”;
days= 31;
break;
default:
mon= “Invalid”;
OUTPUT:
Page 36 of 45
PROGRAM-13
Voting Eligibility
AIM:
To create a GUI Application to check if a person is eligible for voting.
DESIGN:
SOURCE CODE:
For TEST Button:
Int age= Integer.parseInt(entr.getText());
If(age>=18)
else
Page 37 of 45
OUTPUT:
Page 38 of 45
PROGRAM-14
Sum of ‘n’ Natural Numbers
AIM:
To create a GUI Application to find the sum of first ‘n’ natural numbers.
DESIGN:
SOURCE CODE:
For GENERATE Button:
Int limit= Integer.parseInt(tf.getText());
Int sum= 0;
for(int i=1;i<=limit;i++)
Page 39 of 45
ta.append(i+”\t”);
sum= sum + I;
OUTPUT:
Page 40 of 45
PROGRAM-15
Check Number is Positive, Negative or Zero
AIM:
To create a GUI Application to check whether a number is Positive, Negative
or Zero.
DESIGN:
SOURCE CODE:
For CHECK Button:
Int num= Integer.parseInt(txt.getText());
If(num>0)
else if(num<0)
else
Page 41 of 45
lbresult.setText(“The Number is Zero.”);
OUTPUT:
Page 42 of 45
Page 43 of 45
PROGRAM-16
Find the Factorial of a Number
AIM:
To create a GUI Application to find the Factorial of a given Number.
DESIGN:
SOURCE CODE:
For CALCULATE Button:
Int fact= 1;
for(int i=1;i<=limit;i++)
Fact*=I;
Page 44 of 45
}
OUTPUT:
Page 45 of 45