0% found this document useful (0 votes)
6 views20 pages

Java Programs for Tax, Salary, and Patterns

Uploaded by

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

Java Programs for Tax, Salary, and Patterns

Uploaded by

chowdareddy984
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1.

Program to find the tax bill amount

import [Link].*;
public class taximeter
{
int taxino,km,bill;
String name;
taximeter()
{
taxino = 0;
bill = 0;
km = 0;
name="";
}
void input()
{
Scanner sc = new Scanner ([Link]);
[Link]("ENTER THE PASSENGERS NAME");
name = [Link]();
[Link]("ENTER THE TAXI NUMBER");
taxino = [Link]();
[Link]("ENTER THE NUMBER OF KILOMETERS TRAVELLED");
km = [Link]();
}
void calculate()
{
if (km <=1)
bill=100;
if (km>1&&km<6)
bill = 150;
if (km>6&&km<=12)
bill = 200;
if(km>12&&km<=18)
bill = 300;
if (km>18)
bill = 500;
}
void display()
{
[Link]("Taxino\tName\tKilometers Travelled\tBill Amount");
[Link](taxino+"\t"+name+"\t"+km+"km\t\t\tRs"+bill);
}
public static void main (String args[])
{
taximeter ob = new taximeter();
[Link]();
[Link]();
[Link]();
}
}
OUTPUT
ENTER THE PASSENGERS NAME
CHINMAY
ENTER THE TAXI NUMBER
42
ENTER THE NUMBER OF KILOMETERS TRAVELLED
15
Taxino Name Kilometers Travelled Bill Amount
42 CHINMAY 15km Rs300
1
2. Program to calculate area,perimeter and volume of shape

import [Link].*;
public class calculate
{
public static void main(String args[])
{
Scanner sc = new Scanner([Link]);
double r;
int l,b,h;
double p=0,p1=0;
int q=0,q1=0,ra=0,ra1=0,t=0,v=0,c=0;
float t1=0;
[Link]("Enter the values of r");
r = [Link]();
[Link]("Enter the values of l");
l = [Link]();
[Link]("Enter the values of b");
b = [Link]();
[Link]("Enter the values of h");
h = [Link]();
calculate ob=new calculate();
p = [Link](r);
p1 = [Link](r);
q = [Link](l);
q1 = [Link](l);
ra = [Link](l,b);
ra1 = [Link](l,b);
t = [Link](b,h);
t1 = [Link](l,b,h);
v = [Link](l,b,h);
c = [Link](l);
[Link]("Area of the circle "+p);
[Link]("Perimter of the circle "+p1);
[Link]("Area of the square "+q);
[Link]("Perimter of the circle "+q1);
[Link]("Area of the rectangle "+ra);
[Link]("Perimter of the rectangle "+ra1);
[Link]("Area of the triangle "+t);
[Link]("Perimter of the triangle "+t1);
[Link]("Volume of cuboid "+v);
[Link]("Volume of cube "+c);
}
double area(double r)
{
return (3.14*r*r);
}
double perimter(double r)
{
return(3.14*r*2);
}
int area (int l)
{
return(l*l);
}
int perimeter(int l)
{
return(4*l);
}
2
int area(int l, int b)
{
return(l*b);
}
int perimter(int l, int b)
{
return(2*(l+b));
}
float area(float b,float h)
{
return((1/2)*b*h);
}
float perimeter(int l,int b,int h)
{
return(l+b+h);
}
int volume(int l,int b,int h)
{
return(l*b*h);
}
int volume(int l)
{
return(l*l*l);
}
}

OUTPUT
Enter the values of r
10
Enter the values of l
7
Enter the values of b
8
Enter the values of h
5
Area of the circle 314.0
Perimter of the circle 62.800000000000004
Area of the square 49
Perimter of the circle 28
Area of the rectangle 56
Perimter of the rectangle 30
Area of the triangle 40
Perimter of the triangle 20.0
Volume of cuboid 280
Volume of cube 343

3
3. Program to display various patterns

import java .util.*;


public class pattern_full
{
public static void main (String args[])
{
Scanner sc=new Scanner([Link]);
int m=5;
for(int i=1;i<=5;i++)
{
for(int j=1;j<=m;j++)
[Link](" ");
for(int k=1;k<=i;k++)
[Link](" a");
[Link]();
m=m-1;
}
m=2;
for(int i=4;i>=1;i--)
{
for(int j=1;j<=m;j++)
[Link](" ");
for(int k=1;k<=i;k++)
[Link](" a");
[Link]();
m=m+1;
}
int p=0;
[Link]("the pattern of pascal's triangle is ");
m=4;
for(int i=1;i<4;i++)
{
for(int j=1;j<m;j++)
[Link](" ");
for(int k=1;k<=i;k++)
[Link](k+"");
for (int k=i-1;k>=1;k--)
[Link](k+"");
[Link]();
m=m-1;
}
m=1;
for(int i=4;i>=1;i--)
{
for(int j=1;j<m;j++)
[Link](" ");
for(int k=1;k<=i;k++)
[Link](k+"");
for(int k=i-1;k>=1;k--)
[Link](k+"");
[Link]();
m=m+1;
}
[Link]("enter the number of alphabets required");
int n=[Link]();
int c=1;
char ch='a';
for(int i=1;i<=n;i++)
4
[Link](ch++);
--ch ;
for(int i=1;i<n;i++)
[Link](--ch);
[Link]( );
for(int i=n-1;i>=1;i--)
{
ch='a';
for(int j=1;j<=i;j++)
[Link](ch++);
for(int k=1;k<=c;k++)
[Link](" ");
for(int j=1;j<=i;j++)
[Link](--ch);
[Link]();
c=c+2;
}
c=c-4;
for(int i=2;i<n;i++)
{
ch='a';
for(int j=1;j<=i;j++)
[Link](ch++);
for(int k=1;k<=c;k++)
[Link](" ");
for(int j=1;j<=i;j++)
[Link](--ch);
[Link]();
c=c-2;
}
ch='a';
for(int i=1;i<=n;i++)
[Link](ch++);
--ch;
for(int i=1;i<=n;i++)
[Link](--ch);
[Link]();
}
}

OUTPUT

a
a a
a a a
a a a a
a a a a a
a a a a
a a a
a a
a
the pattern of pascal's triangle is
1
121
12321
1234321
12321
121
1
enter the number of alphabets required
5
5
abcdedcba
abcd dcba
abc cba
ab ba
a a
ab ba
abc cba
abcd dcba
abcdedcba`

6
4. Program to perform selection sort and binary search

import [Link].*;
class sort_search
{
public static void main(String args[])
{
Scanner sc = new Scanner([Link]);
int k=0,p=0,ns,lb=0,ub=9,min,t;
int m[]=new int[10];
[Link]("Enter the integer numbers for the array");
for(int i=0;i<10;i++)
m[i]=[Link]();
[Link]("Enter the numbers to be searched");
ns =[Link]();
for(int i=0;i<10;i++)
{
min=i;
for(int j=i+1;j<10;j++)
{
if(m[j]<m[min])
min=j;
}
t=m[i];
m[i]=m[min];
m[min]=t;
}
[Link]("The numbers arranged in ascending order are");
for(int i=0;i<10;i++)
[Link](m[i]);
while (lb<=ub)
{
p=(lb+ub)/2;
if(m[p]<ns)
lb=p+1;
if(m[p]>ns)
ub=p-1;
if(m[p]==ns)
{
k=1;
break;
}
}
if(k==1)
[Link]("The search is successful and the number is
present");
else
[Link]("The search is not successful and the number is not
present");
}
}

OUTPUT
Enter the integer numbers for the array
5
20
7
18
1
7
3
9
8
21
35
Enter the numbers to be searched
20
The numbers arranged in ascending order are
1
3
5
7
8
9
18
20
21
35
The search is successful and the number is present

8
5 Program to check whether a number is an automorphic or not using function
concept

import [Link].*;
public class morphic
{
int digits(int m)
{
int p,c=0,r;
double k=0;
p=m*m;
while(m!=0)
{
m=m/10;
c=c+1;
}
k=p%([Link](10,c));
r=(int)k;
return(r);
}
public static void main(String args[])
{
Scanner sc = new Scanner([Link]);
int n,b;
morphic ob =new morphic();
[Link]("Enter Your Number");
n=[Link]();
b=[Link](n);
if(n==b)
[Link](n+" is an Automorphic Number");
else
[Link](n+" is not an Automorphic Number");
}
}

OUTPUT
Enter Your Number
20
20 is not an Automorphic Number

9
6 Program to convert the word in piglatin form and display the output

import [Link].*;
public class piglatin
{
int i,p;
String wd,st1,st2;
char chr;
public static void main (String args[])
{
piglatin ob = new piglatin();
[Link]();
[Link]();
}
piglatin()
{
wd = "";
}
void input()
{
Scanner sc = new Scanner([Link]);
[Link]("Enter the string");
wd = [Link]();
wd = [Link]();
}
void display()
{
p=[Link]();
for(i=0;i<p;i++)
{
chr=[Link](i);
if(chr=='a'||chr=='e'||chr=='i'||chr=='o'||chr=='u')
break;
}
st1=([Link](i,p));
st2=[Link](0,i);
[Link]("The piglatin form of word is "+st1+st2+"ay");
}
}

OUTPUT
Enter the string
CHINMAY
The piglatin form of word is inmaychay

10
7 Program to calculate the net and gross salary of an employee

import [Link].*;
public class employee
{
public static void main(String args[])
{
int basic;
double DA=0,HRA=0,PF=0,NET=0,GROSS=0;
String name = "";
Scanner sc = new Scanner([Link]);
[Link]("A PROGRAM TO CALCULATE NET AND GROSS SALARY OF AN
EMPLOYEE");
[Link]("ENTER THE NAME OF AN EMPLOYEE");
name = [Link]();
[Link]("ENTER THE BASIC PAY OF THE EMPLOYEE");
basic = [Link]();
DA=((25*basic)/100);
HRA=((15*basic)/100);
PF=((8.33*100)/100);
NET=basic+DA+HRA;
[Link]("NET SALARY OF AN EMPLOYEE IS "+NET);
GROSS =NET-PF;
[Link]("GROSS SALARY OF AN EMPLOYEE IS "+ GROSS);
}
}

OUTPUT
A PROGRAM TO CALCULATE NET AND GROSS SALARY OF AN EMPLOYEE
ENTER THE NAME OF AN EMPLOYEE
CHINMAY
ENTER THE BASIC PAY OF THE EMPLOYEE
25000
NET SALARY OF AN EMPLOYEE IS 35000.0
GROSS SALARY OF AN EMPLOYEE IS 34991.67

11
8 Program to search and sort an element using selection sort and bubble sort

import [Link].*;
public class search_sort
{
public static void main (String args[])
{
int k=0,min;
String t,st;
Scanner sc = new Scanner([Link]);
String m[]=new String[10];
[Link]("ENTER ANY 10 NAMES AS STRING");
for(int i=0;i<10;i++)
m[i] =[Link]();
[Link]("ENTER THE STRINGS TO BE SEARCHED");
st=[Link]();
for (int i=0;i<10;i++)
{
if(m[i].compareTo(st)==0)
k=1;
}
if(k==1)
[Link]("SEARCH IS SUCCESSFUL");
else
[Link]("SEARCH IS UNSUCCESSFUL");
for(int i=0;i<9;i++)
{
min=i;
for(int j=(i+1);j<10;j++)
{
if((m[j].compareTo(m[min])<0))
{
t=m[i];
m[i]=m[j];
m[j]=t;
}
}
}
[Link]("The names arranged in ascending order ");
for(int i=0;i<10;i++)
[Link](m[i]);
}
}

OUTPUT
ENTER ANY 10 NAMES AS STRING
CHINMAY
RAHUL
CHARAN
KARTHIK
HEMANTH
TEJUS
CHANDU
CHIRANTH
PREETHAM
ABUBAKAR
ENTER THE STRINGS TO BE SEARCHED
RAHUL
SEARCH IS SUCCESSFUL
12
The names arranged in ascending order
ABUBAKAR
CHANDU
CHARAN
CHINMAY
CHIRANTH
HEMANTH
KARTHIK
PREETHAM
RAHUL
TEJUS

13
9 Program to calculate the electricity bill by reading the number of units
consumed

import [Link].*;
public class bill
{
public static void main (String args[])
{
int v,c=0;
float a=0;
Scanner sc = new Scanner([Link]);
[Link]("A PROGRAM TO CALCULATE ELECTRICITY BILL");
[Link]("ENTER THE UNITS CONSUMED");
int u = [Link]();
if(u<=100)
{
c=(u*80)/100;
a=c+50;
}
else if((u>100)&&(u<=200))
{
c=(100*80/100)+((u-100*1));
a=c+50;
}
else if(u>200)
{
c=(100*80/100)+(100*1)+(((u-200*125)/100));
a=c+50;
}
[Link]("THE UNITS CONSUMED = "+u);
[Link]("THE CHARGE ="+c);
[Link]("THE ADDITIONAL CHARGE =50");
[Link]("THE AMOUNT TO BE PAID = "+a);
[Link]("THANK YOU");
}
}

OUTPUT
A PROGRAM TO CALCULATE ELECTRICITY BILL
ENTER THE UNITS CONSUMED
200
THE UNITS CONSUMED = 200
THE CHARGE =180
THE ADDITIONAL CHARGE =50
THE AMOUNT TO BE PAID = 230.0
THANK YOU

14
10 Program to display first ten numbers first ten numbers of the Fibonacci
series

import [Link].*;
public class fibonacci
{
public static void main (String args[])
{
int a,b,c=0,n=0;
Scanner sc = new Scanner([Link]);
[Link]("The program is to generate 10 values of fibonacci");
[Link]("Enter the values for a");
a =[Link]();
[Link]("Enter the values for b");
b =[Link]();
[Link]("The fibonacci series are");
[Link](a);
[Link](b);
do
{
c=a+b;
[Link](c);
a=b;
b=c;
n=n+1;
}
while(n<8);
[Link]("THANK YOU");
}
}

OUTPUT
The program is to generate 10 values of fibonacci
Enter the values for a
20
Enter the values for b
5
The fibonacci series are
20
5
25
30
55
85
140
225
365
590
THANK YOU

15
11 Program to find different type of numbers

import [Link].*;
public class numbers
{
public static void main (String args[])
{
Scanner sc=new Scanner([Link]);
int n,ch=0;
[Link]("Enter your choice \n [Link] \n [Link]
Number \n [Link] \n [Link] number");
ch=[Link]();
[Link]("Enter the value for n");
n = [Link]();
switch(ch)
{
case 1:
int rev=0,pp;
pp=n;
do
{
int digit = n%10;
rev = rev*10+digit;
n=n/10;
}
while(n!=0);
if(rev==pp)
[Link](pp+" is a palindrome number");
else
[Link](pp+" is not a palindrome number");
break;
case 2:
int a,s=0;
for(a=1;a<n;a++)
{
if (n % a == 0)
s= s+a;
}
if(s==n)
[Link](n+" is a perfect number");
else
[Link](n+" is not a perfect number");
break;
case 3:
int num;
s=0;
num=n;
while(n>0)
{
a=n%10;
s=s+a*a*a;
n=n/10;
}
if(num ==s)
[Link]("The number "+num+" is an armstrong number");
else
[Link]("The number "+num+" is not an armstrong
number");
break;
16
case 4:
int b,c=0;
for(b=1;b<=n;b++)
{
if(n%b==0)
c=c+1;
}
if(c==2)
[Link](n+" is a prime number");
else
[Link](n+" is not a prime number");
break;
default:
[Link]("Wrong choice");
}
}
}

OUTPUT
Enter your choice
[Link]
[Link] Number
[Link]
[Link] number
4
Enter the value for n
7
7 is a prime number

17
12 Program to find the sum of different series

import [Link].*;
public class SERIES
{
public static void main (String args[])
{
Scanner sc = new Scanner ([Link]);
[Link]("THIS PROGRAM IS TO FIND THE SUM OF DIFFERENT
SERIES");
[Link]("[Link] type of series:1+2+3+4...............+n");
[Link]("[Link] type of series:1+a+a raised to the power
2+........a raised to the power n");
[Link]("[Link] type of
series:1+(1*2)+(1*2*3)+...........(1*2*3*+n.........*n)");
[Link]("[Link] type of
series:1+1/2!+1/3!+1/4!.............+1/n!");
[Link]("ENTER YOUR CHOICE ACCORDINGLY");
int ch;
ch =[Link]();
switch(ch)
{
case 1:
int n;
double s=0;
[Link]("Enter the values for n");
n=[Link]();
for(int i=1;i<=n;i=i+1)
s=s+i;
[Link]("The sum of 1 to "+n+" is ");
[Link](s);
break;
case 2:
int a;
s=1;
[Link]("Enter the values for a");
a=[Link]();
[Link]("Enter the power of n");
n=[Link]();
for(int i=1;i<=n;i++)
s=s+[Link](a,i);
[Link]("The sum of series = "+s);
break;
case 3:
int p;s=0;p=1;
[Link]("Enter the values for n");
n=[Link]();
for(a=1;a<=n;a++)
{
p=p*a;
s=s+p;
}
[Link]("The sum of series = "+s);
break;
case 4:
int b;s=0;float f;
[Link]("Enter the values for n");
n=[Link]();
for(a=1;a<=n;a++)
18
{
f=1;
for(b=1;b<=n;b++)
f=f*b;
s=s+1/f;
}
[Link]("[Link] type of
series:1+1/2!+1/3!+1/4!.............+1/n! "+s);
break;
default:
[Link]("WRONG CHOICE(^0 0^)");
}
}
}

OUTPUT
THIS PROGRAM IS TO FIND THE SUM OF DIFFERENT SERIES
[Link] type of series:1+2+3+4...............+n
[Link] type of series:1+a+a raised to the power 2+........a raised to the
power n
[Link] type of series:1+(1*2)+(1*2*3)+...........(1*2*3*+n.........*n)
[Link] type of series:1+1/2!+1/3!+1/4!.............+1/n!
ENTER YOUR CHOICE ACCORDINGLY
3
Enter the values for n
20
The sum of series = 4.563008025E9

19
13 Program to find number of characters or length,vowels and words in a string

import [Link].*;
public class xyz
{
public static void main(String args[])
{
Scanner sc = new Scanner([Link]);
int l=0,c=0,w=1,v=0,i;
String a;
char b;
[Link]("ENTER THE STRING");
a =[Link]();
l=[Link]();
[Link]("THE LENGTH OF THE STRING IS "+l);
for(i=0;i<l;i++)
{
b=([Link](i));

if((b=='a')||(b=='e')||(b=='i')||(b=='o')||(b=='u')||(b=='A')||(b=='E')||(b=='I
')||(b=='O')||(b=='U'))
v=v+1;
}
[Link]("NUMBER OF VOWELS PRESENT IN THE STTRING = "+v);
for(i=0;i<l;i++)
{
b=[Link](i);
if(b==' ')
w=w+1;
}
[Link]("NUMBER OF WORDS PRESENT IN THE STRING = "+w);
[Link]("THE NUMBER OF CHARACTERS PRESENT IN THE STRING =
"+(l-(w-1)));
}
}

OUTPUT
ENTER THE STRING
CHINMAY
THE LENGTH OF THE STRING IS 7
NUMBER OF VOWELS PRESENT IN THE STTRING = 2
NUMBER OF WORDS PRESENT IN THE STRING = 1
THE NUMBER OF CHARACTERS PRESENT IN THE STRING = 7

20

You might also like