0% found this document useful (0 votes)
177 views10 pages

Java Programs by JaTIN Sharma

There are 6 Java programs that i have created using NetBeans IDE which include the ones which have come in CBSE computer practical examinations.

Uploaded by

Jatin Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
177 views10 pages

Java Programs by JaTIN Sharma

There are 6 Java programs that i have created using NetBeans IDE which include the ones which have come in CBSE computer practical examinations.

Uploaded by

Jatin Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Java Programs By JaTIN

Sharma

1. Customer Billing
This is a customer billing system as shown below. The
shop accepts payement in three modes- Cash, Debit Card,
Credit Cards. The discount given as per mode of payment
is as followsMode of Payment
Cash
Debit Card
Credit Card

Discount
12%
8%
5%

List of products in Combo Box isProducts


Kurta
T-Shirt
Jacket

Unit Price
950
750
2500

As the user selects an item from the Combo Box, its price
is displayed in jTextField2.
If the Member check box is checked then the customer
gets an additional discount of 5% on the net payable
amount.

CODING FOR CALCULATE BUTTON


double d = 0,netd,ad = 0,total,discount,net;
int price = 0,quantity;
if(cash.isSelected())
{
d=.12;
}
if(DC.isSelected())
{
d=.08;
}
if(CC.isSelected())
{
d=.05;
}
if(jComboBox1.getSelectedIndex()==0)
{
price= 750;
}
if(jComboBox1.getSelectedIndex()==1)
{
price= 950;
}
if(jComboBox1.getSelectedIndex()==2)
{

price= 2500;
}
if(jCheckBox1.isSelected())
{
ad=.05;
}
netd=d+ad;
quantity=Integer.parseInt(jTextField2.getText());
total=price*quantity;
discount=total*netd;
net=total-discount;
totT.setText(""+total);
disT.setText(""+ discount);
netT.setText(""+net);

CODING IN jComboBox1ActionPerformed
if(jComboBox1.getSelectedIndex()==0)
{
jTextField3.setText("Rs. 750");
}
if(jComboBox1.getSelectedIndex()==1)
{
jTextField3.setText("Rs. 950");
}
if(jComboBox1.getSelectedIndex()==2)
{
jTextField3.setText("Rs. 2500");
}

CODING FOR EXIT BUTTON


System.exit(8);

CODING FOR CLEAR BUTTON


jTextField2.setText("");
jTextField3.setText("");
totT.setText("");
disT.setText("");
netT.setText("");

2. Find, Replace, Delete

A program to find, replace, delete a words from a


paragraph.

CODING FOR FIND AND REPLACE BUTTON


String etxt=jTextArea1.getText();
String find=jTextField1.getText();
String replace=jTextField2.getText();
String mtxt="";
mtxt=etxt.replaceAll(find, replace);
jTextArea2.setText(mtxt);

CODING FOR DELETE BUTTON


String etxt=jTextArea1.getText();
String find=jTextField1.getText();
String replace=jTextField2.getText();
String mtxt="";
mtxt=etxt.replaceAll(find, replace);
jTextArea2.setText(mtxt);
String dtxt=jTextField3.getText();
mtxt=mtxt.replaceAll(dtxt, "");
jTextArea2.setText(mtxt);

CODING FOR TRANSFER BUTTON


String str2=jTextArea2.getText();
String str1=jTextArea1.getText();
jTextArea1.setText(str2);
jTextArea2.setText("");

CODING FOR 1ST CLEAR BUTTON


String str2=jTextArea2.getText();
String str1=jTextArea1.getText();
jTextArea1.setText(str2);
jTextArea2.setText("");

CODING FOR 2ND CLEAR BUTTON


jTextField1.setText("");
jTextField2.setText("");

CODING 3RD CLEAR BUTTON


jTextArea2.setText("");

CODING FOR 4TH CLEAR BUTTON


String str2=jTextArea2.getText();
String str1=jTextArea1.getText();
jTextArea1.setText(str2);
jTextArea2.setText("");

CODING FOR CLEAR ALL BUTTON


jTextArea1.setText("");
jTextArea2.setText("");
jTextField1.setText("");
jTextField2.setText("");

3. Colour Demonstration
A program in which the colour of appropriate control of
button, label and text field changes depending upon users
choice when the user selects a colour from a list.

First we import the Color class of java.awt. , i.e., in the


source editor, at the top of all code, we typeimport java.awt.Color;
Now,
CODING IN valueChanged() event handler of ListSelection
event of jList1
int i = jList1.getSelectedIndex();
Color x=Color.WHITE;
switch(i)
{
case 0:x=Color.RED;
break;
case 1:x=Color.GREEN;
break;
case 2:x=Color.BLUE;
break;
case 3:x=Color.MAGENTA;
break;
case 4:x=Color.CYAN;
break;
case 5:x=Color.YELLOW;
break;
case 6:x=Color.GRAY;
break;
}
if(jCheckBox1.isSelected())
{

jLabel4.setBackground(x);
}
if(jCheckBox2.isSelected())
{
jButton1.setBackground(x);
}
if(jCheckBox3.isSelected())
{
jTextField1.setBackground(x);
}

4. Extracting surname
A program that extracts surname from the entered name.

CODING FOR EXTRACT BUTTON


String name=jTextField1.getText();
int i,p;
String lname="";
for(i=1;i<name.length();i++)
{
char s=name.charAt(i);
if(s==' ')
{
break;
}
}
p=i;
for(int k=p+1;k<name.length();k++)
{
char ch=name.charAt(k);

lname=lname+ch;
}
jTextField2.setText(lname);

CODING FOR CLEAR BUTTON


jTextField1.setText("");
jTextField2.setText("");

5. Counting Character
A program to count the occurrence of a particular string in
a string.

CODING FOR COUNT BUTTON


String word=jTextField1.getText();
char c= jTextField3.getText().charAt(0);
int i,count=0;
for(i=0;i<word.length();i++)
{
char ch =word.charAt(i);
if(ch==c)
{
count +=1;
}
}
jTextField2.setText(count+"");

CODING FOR CLEAR BUTTON

jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");

6. Changing case
A program to change case of a string to upper between
two specified indices of that string

CODE FOR CLICK BUTTON


String word=jTextField1.getText();
int a=Integer.parseInt(jTextField2.getText());
int b=Integer.parseInt(jTextField3.getText());
int i,x,l=word.length();
String str1="",str2="",str3="";
for(i=0;i<a;i++)
{
char c1=word.charAt(i);
str1=str1+c1;
}
for(i=a;i<=b;i++)
{
char c2=word.charAt(i);
str2=(str2+c2).toUpperCase();
}
for(i=b+1;i<l;i++)
{
char c3=word.charAt(i);
str3=str3+c3;
}

jTextField4.setText(str1+str2+str3);

CODE FOR CLEAR BUTTON


jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
jTextField4.setText("");

You might also like