Informatics Practicals

Download as pdf or txt
Download as pdf or txt
You are on page 1of 45

PROGRAM-1

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);

jLabel1.setText(“Enter the Radius”);

TextA.enable(true);

jLabel2.setVisible(false);

TextB.setVisible(false);

For Rectangle Radio Button:


jLabel1.enable(true);

jLabel2.enable(true);

TextA.setVisible(true);

TextB.setVisible(true);

jLabel1.setText(“Enter the Length”);

jLabel2.setText(“Enter the Breadth);

TextA.enable(true);

TextB.enable(true);

jLabel2.setVisible(true);

For Square Radio Button:


jLabel2.enable(false);

TextB.enable(false);

Page 4 of 45
jLabel1.setText(“Enter the Side”);

TextA.enable(true);

jLabel2.setVisible(false);

TextB.setVisible(false);

For FIND AREA Button:


float r=0,length,breadth,side;

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);

For EXIT Button:

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.

It should then compute & display Payment Amount(Hours Worked*Pay Rate)


& Tax Payable(Payment Amount*Tax Rate) in labels.

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();

String text2= fntf.getText();

String text3= lntf.getText();

String text4= ctf.getText();

Page 10 of 45
String text5= stf.getText();

Idta.append(“\n” + ”STUDENT’S DETAILS:”+ “\n”);

Idta.append(“Name:” + text1 +” “+text2+” “+text3+”\n”);

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);

For Bold Radio Button:


tf.setFont(new Font(“Helvetica”,Font.BOLD,18);

For Italic Radio Button:


tf.setFont(new Font(“Helvetica”,Font.ITALIC,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

JOptionPane.showMessageDialog(null,”It is not Palindrome.”);

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());

String user= tf.getText();

If(pwd.equals(“HAASHIR”))

JOptionPane.showMessageDialog(null,”You have Logged in Successfully”);

ALERT obj= new ALERT();

Page 18 of 45
this.setVisible(false);

obj.setVisible(true);

else

{ JOptionPane.showMessageDialog(null,user+”is an Invalid User”);

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());

float bus= Float.parseFloat(bustxt.getText());

float accnts= Float.parseFloat(accntstxt.getText());

Page 21 of 45
float eco= Float.parseFloat(ecotxt.getText());

float info= Float.parseFloat(infotxt.getText());

float total= eng+bus+accnts+eco+info;

ttl.setText(“ “+total);

float per= total/6;

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

lbresult.setText(“ “ +numDays+ “Days”);

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

Time(in years) Rate of Interest(%


per annum)
7 7.0
10 8.5
15 9.5
20 12.5

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%.

As per Bank’s FD Scheme, create a GUI Application that obtains principal


amount and time from the user and then determines how much final amount
user will be receiving at the end of the time. Total amount is calculated with
compound interest amount as per following formula:

Total Amount = Principal Amount (1+Rate%/100)time

Page 27 of 45
DESIGN:

SOURCE CODE:
For CALCULATE Button:
double princ= Double.parseDouble(ptf.getText());

int time= Integer.parseInt(ttf.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());

for(i= 0; i<no; i++)

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”;

lbresult.setText(“Your Choice is” + mon +”/”+days+ “ “+ “Days”);

For EXIT Button:


System.exit(0);

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)

{lbresult.getText(“The Person is Eligible for Voting.”);}

else

{lbresult.setText(“The Person is Not Eligible for Voting.”);}

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;

ta.append(“The First” + limit + “Natural Numbers are:\n”);

for(int i=1;i<=limit;i++)

Page 39 of 45
ta.append(i+”\t”);

sum= sum + I;

ta.append(“\n Sum of the First” + limit+ “Natural Numbers are\n” + sum);

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)

{lbresult.setText(“The Number” + num + “is Positive.”);

else if(num<0)

lbresult.setText(“The Number” + num + “is Negative.”);

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;

Int limit= Integer.parseInt(ltf.getText());

for(int i=1;i<=limit;i++)

Fact*=I;

Page 44 of 45
}

lbresult.(“Factorial is” + fact + “.”);

OUTPUT:

Page 45 of 45

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy