Thursday, 4 August 2011

PROGRAMS 6


     Program to input a number                
                and print  it in  words

ALGORITHM
Step1-Start
Step2-Input the number in amt (Integer Type)
Step3-We have taken the Integer variable i.e.z&g
Step4-We have taken the String array i.e.
          String x1[]={“,” “ONE”, “TWO”, “THREE”, “FOUR” , “FIVE” ,   
            “SIX” , “SEVEN” , “EIGHT” ,“NINE”}.
          String x[]={“ ,”, “TEN”, “ELEVEN”, “TWELVE”, “THIRTEEN” ,
            “FOURTEEN”, “FIFTEEN”, “SIXTEEN” , “SEVENTEEN” ,                                                                                                                                                                          
            “EIGHTEEN”, “NINTEEN”};
          String x2[]={“,” “TWENTY”, “THIRTY”,“FOURTY” , “FIFTY” ,    
            “SIXTY” , “SEVENTY” , “EIGHTY” , “NINTY”};
Step5-We have taken the remainder of inputted number amt in z and the 
          quotient of the Inputted Step number in g.
Step6- We have check the condition i.e. (g!=1).If this condition found    
           true then Go to Step7 otherwise Go to Step7-Print the Sting array
           i.e.(x2[g-1]+ “”+x1[z])
Step8-Print the String array i.e.(x[amt-9]);
Step9-End
                          PROGRAM
import java.io.*;
class eng
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new



InputStreamReader(System.in));
String x3;
System.out.println("Enter any Number(less than 99)");
int amt=Integer.parseInt(br.readLine());
int a,b,c,y,z,g;
String[]={"","Ten","Eleven","Twelve","Thirteen","Fourteen","Fifteen",
"Sixteen","Seventeen","Eighteen","Nineteen"};
String x1[]={" " ,"One","Two","Three","Four","Five","Six","Seven","Eight","Nine"};
String x2[]={"","Twenty","Thirty","Fourty","Fifty","Sixty","Seventy","Eighty","Ninety"};
z=amt%10;
g=amt/10;
if(g!=1)
System.out.println(x2[g-1]+" "+x1[z]);
else
System.out.println(x[amt-9]);
    System.out.println("----------*----------*---------- ");
    System.out.println("----------*----------*---------- ");
}
}

 




























Define a class 'APSeries' with following specification
Class Name : APSeries
Data Member :
a - To store first term
d - To store common difference
Member Function :
APSeries()                  - To initialize value of a and d with 0
APSeries(double a,double d) - To initialize value of a and d with
parametric a and d
nTHTerm(int n)         - To return nTH term of series
Sum(int n)                  - To return sum of series till n terms
showSeries(int n)       - To display n terms of series with sum

ALGORITHM
Step1- START
Step2-We have initialize double type variable i.e. a and d
Step3-We have made non –parameterized constructor by which we have
           assign 0 to ‘a’and‘d’.
Step4- We have made a parameterized constructor .Parameters are double a, double d. We have assign a to this. a i.e. object class and d to this .d
Step5-We have made a return type function i.e. nTHTerm. Parameter  is  int n.We have return the nth  term  of A.P series in this function
Step6- We have made another return type function i.e. Sum and int ‘n’ is
         the parameter. In this function we have return the sum of A.P series
Step7- We have made a function i.e. Show Series and parameter is int
          n(Integer Type). In this we have print the nth term of series as well    
          as  Sum of AP series.
Step8- We have made main function of this class and print the A.P. series of  required term.
Step9-End 
                                               
                        PROGRAM
import java.io.*;
class APSeries
{
private double a,d;
APSeries()
{
a = d = 0;
}
APSeries(double a,double d)
{
this.a = a;
this.d = d;
}
double nTHTerm(int n)
{
return (a+(n-1)*d);
}
double Sum(int n)
{
return (n*(a+nTHTerm(n))/2);
}
void showSeries(int n)
{


 System.out.println("FIRST TERM OF THE SERIES IS  "+a);
 System.out.println("COMMON DIFFERENCE OF THE SERIES IS  "+d);
System.out.println("Hence the series is ");
for(int i=1;i<=n;i++)
{
System.out.println(nTHTerm(i)+" ");
}
System.out.println("It's Sum will be : "+Sum(n));
System.out.println("------------------------*-------------------------*---------------------------");   
}
}
class testap
{
public static void main(String args[]) throws Exception
{
APSeries a = new APSeries(1,2);
a.showSeries(5);
}
}














































      Program to calculate the
                                       income   tax.

ALGORITHM
Step1-Start
Step2-enter your name, sex, monthly income, investment in LIC , investmentin NSC, investment in UTI and other monthly investment in function  get data.
Step3-calculate the yearly investment
Step4-We have calculated Income Tax according to given slab in the
          function income tax.
Step5-We have check whether the sex given is female and if this condition found true then we have calculated Income tax according to given slab in the function display
Step6-We have made main function and through the object we have called  the function  made above and we able to calculate income tax.
Step7-End
                           PROGRAM

import java.io.*;
class taxC
{
private String name; private char sex;
private int mi,yi,tax; int lic,uti,nsc,oth;
public void getdata()throws Exception
{
DataInputStream d=new DataInputStream(System.in);
System.out.println(" Please enter your name ");
name=d.readLine();
System.out.println(" Please enter your sex");
sex=d.readLine().charAt(0);
System.out.println(" Please enter your monthly income ");
mi=Integer.parseInt(d.readLine());
System.out.println(" Please enter the following for your yearly investments ");
System.out.println(" Yearly investment in LIC ");
lic=Integer.parseInt(d.readLine());
System.out.println(" Yearly investment in UTI ");
uti=Integer.parseInt(d.readLine());
System.out.println(" Yearly investment in NSC ");
nsc=Integer.parseInt(d.readLine());
System.out.println(" Other yearly investment ");
oth=Integer.parseInt(d.readLine());
yi=lic+uti+nsc+oth;
}
public int incometax()
{
int inc=12*mi-25000,s=0;
if(inc>=75000 && inc<100000)
tax=(int)(.1*(inc-75000));
else if(inc>=100000 && inc<125000)
tax=2500+(int)(.15*(inc-100000));
else if(inc>=125000)
tax=6500+(int)(.18*(inc-125000));
if(sex=='f' || sex=='F')
tax-=5000;
tax-=.1*yi;  s=(int)(.1*tax);  tax+=s;
if(tax<=0)
tax=0;
return s;
}
public void display(int s)
{
System.out.println("\n\n Name\t\t\t\t:- "+name);
if(sex=='f')
System.out.println(" Sex\t\t\t\t:- Female");
else
System.out.println(" Sex\t\t\t\t:- Male");
System.out.println(" Monthly income\t\t\t:- "+mi);
System.out.println(" Yearly income \t\t\t:- "+mi*12);
System.out.println(" Standard deduction gives is    :- 25000");
System.out.println("\t\t\t\t   -------");
System.out.println(" Taxable Income\t\t\t:- "+(mi*12-25000));
System.out.println("\t\t\t\t   -------");
System.out.println(" LIC investment\t\t\t:- "+lic);
System.out.println(" UTI investment\t\t\t:- "+uti);
System.out.println(" NSC investment\t\t\t:- "+nsc);
System.out.println(" Other investment\t\t:- "+oth);
System.out.println(" Total investment\t\t:- "+yi);
System.out.println(" Rebate (10% of all investments):- "+(int)(.1*yi));
if(sex=='f' || sex=='F')
System.out.println(" Rebate given to woman is       :- 5000 ");
System.out.println(" Surcharge 10% of tax           :- "+s);
System.out.println(" Total tax to pay               :- "+tax);
}
}
class tax
{
public static void main(String args[])throws Exception
{
System.out.println(" Program to calculate income tax ");
System.out.println(" ------------------------------- ");
taxC ob=new taxC();  ob.getdata();
int s=ob.incometax();  ob.display(s);
}
}

    











 











Program to convert the case of inputted sentence and arrange the words in alphabetical order.

ALGORITHM
Step1-Start.
Step2-We have made parameterized constructor and the parameter is 
          String str1and we have assigned str to str1.
Step3-Input the String in the function getdata.
Step4-We have convert the case of the String and find out the length of  
          the  String in the function proceed.
Step5-We have done type casting and stored the character in c we have
          found the character of the string in ch as well as the next character     
          of  the string in ch1.
Step6-We have checked the condition i.e. (ch== ‘’||ch1== ‘c’).If this                       
           condition found true then go to Step7 .
Step7-We have taken out the character of the string and check the condition  i.e.(ch!= ‘’).If this condition found true then go to step-8.
Step8-We have taken the character of the String in String s
Step9-Apply break
Step10-We have print the arranged string in the function disp.
Step11-Use inheritance and we have made main function in class alph
Step12-We have called the function made above and we have arrange
             the string in alphabetical order
Step13-End                                               
                          PROGRAM

import java.io.*;
class stream
{
String str;
stream(String str1)
{
str=str1;
}
void getdata()throws Exception
{
DataInputStream d=new DataInputStream(System.in);
System.out.println("enter a String");
str=d.readLine();
}
void proceed()
{
int i,l,j,k;
char ch,c,ch1;
String s= new String(" ");
str=" "+str+" ";
str=str.toUpperCase();
l=str.length();
for(i=65;i<90;i++)
{
c=(char)i;
for(j=0;j<l-1;j++)
{
ch=str.charAt(j);
ch1=str.charAt(j+1);
if(ch==' ' && ch1==c)
{
for(j++;j<l;j++)
{
ch=str.charAt(j);
if(ch!=' ')
{
s=s+ch;
}
else if(ch==' ')
{
s=s+" ";
break;
}
}
}
}
}
str=" ";
str=s;
}
void disp()
{
System.out.println(str);
}
}
class alph
{
public static void main(String args[])throws Exception
{
stream ob=new stream(" ");
ob.getdata();
ob.proceed();
ob.disp();
}
}

          
 


               VARIABLE  DESCRIPTION-

VARIABLE
TYPE OF VARIABLE
FUNCTION
i ,j
Integer
For Loop
l
Integer
Length of the string
ch, ch1
Character
For storing the character of the string
str, str1,s
String
For storing the String



          
   Program to print the payroll 
                    of AN  employee

ALGORITHM
Step1-Start.
Step2-Enter the name, post, street, city, pin code, house number in the
          function get data.
Step3-Enter the basic pay , special pay, contribution to gpf, contribution to group scheme, monthly income tax deduction, compensatory
allowance.
Step4-We have calculated gross pay and net pay according to given slab in  the function pay.
Step5-We have print all the above calculated things and all the above
          entrances in the function display.
Step6-Use inheritance and made another class of name payroll and create
           main function and call all the function through object created in the
           class payrollC. 
Step7-End                                                
                       PROGRAM

import java.io.DataInputStream;
class payrollC
{
String name,post,city,hno,str;
int BP,SP,GPF,GIS,IT,CCA,DA,HRA,pin,GP,NP;
void getdata()throws Exception
{
DataInputStream d=new DataInputStream(System.in);
System.out.println(" Enter the following data for the employee ");
System.out.println(" Name ");
name=d.readLine();
System.out.println(" Designation or post ");
post=d.readLine();
System.out.println(" House number ");
hno=d.readLine();
System.out.println(" Street ");
str=d.readLine();
System.out.println(" City ");
city=d.readLine();
System.out.println(" PIN code ");
pin=Integer.parseInt(d.readLine());
DA=0;
HRA=0;
GP=0;
NP=0;
System.out.println(" Monthly basic pay ");
BP=Integer.parseInt(d.readLine());
System.out.println(" Special pay ");
SP=Integer.parseInt(d.readLine());
System.out.println(" Contribution to GPF ");
GPF=Integer.parseInt(d.readLine());
System.out.println(" Contribution to Group Scheme ");
GIS=Integer.parseInt(d.readLine());
System.out.println(" Monthly Income Tax deduction ");
IT=Integer.parseInt(d.readLine());
System.out.println(" Compensatory Allowence ");
CCA=Integer.parseInt(d.readLine());
}
void pay()
{
int bp=BP;
if(bp<=3500)
DA=114*bp/100;
else if(bp>3500 && bp<=6000)
DA=85*bp/100;
else
DA=74*bp/100;
if(bp<=1500)
HRA=250;
else if(bp>1500 && bp<=2800)
HRA=450;
else if(bp>2800 && bp<=3500)
HRA=900;
else
HRA=1000;
GP=bp+SP+HRA+DA+CCA;
NP=GP-(GPF+GIS+(IT*12));
}
void display()
{
pay();
System.out.println(" Name                         :- "+name);
System.out.println(" Designation or post          :- "+post);
System.out.println(" House number                 :- "+hno);
System.out.println(" Street                       :- "+str);
System.out.println(" City                         :- "+city);
System.out.println(" PIN code                     :- "+pin);
System.out.println("\n Monthly basic pay            :- "+BP);
System.out.println(" Special pay                  :- "+SP);
System.out.println(" Contribution to GPF          :- "+GPF);
System.out.println(" Contribution to Group Scheme :- "+GIS);
System.out.println(" Monthly Income Tax deduction :- "+IT);
System.out.println(" Compensatory Allowence       :- "+CCA);
System.out.println(" Total deduction              :- "+(GPF+GIS+IT));
System.out.println(" Gross pay                    :- "+GP);
System.out.println(" Net pay                      :- "+NP);
}
}
class payroll
{
static void main(String args[])throws Exception
{
System.out.println(" Program to  generate the payroll of an employee ");
System.out.println(" ----------------------------------------------- ");
payrollC ob=new payrollC();
ob.getdata();
ob.display();
}
}
    

              VARIABLE  DESCRIPTION
VARIABLE
TYPE OF VARIABLE
FUNCTION
Name , post , city , hno, str
String
To enter the name,  post, city, house number, street
BP,SP,GIS,GPF,IT,CCA
Integer
To enter all the pays and contributions
DA, HRA, GP, NP
Integer
To calculate the gross pay and net pay

Design a Class StringMagic to perform various operation on strings
Class Name  :   StringMagic
Data Member
str         :   to store the string
Mamber functios
void input ()    :   to accept a string
int pailin_count()  :   count the palindrome Words in str
String WordsSort()  :   Sort the str according to wordsr
length & Alpebatical orde
void display()  :   Display the orginal & sorted String

ALGORITHM-
Step1-Start
Step2-We have input the string i.e. String str
Step3-We have made function int pallin count in which we have checked
           whether the inputted string have pallindrome words and if there are
           pallindrome words then we have count the pallindrome words
Step4-We have made function Stringwordssort in which we have sorted 
           the inputted string.We have done this process to sort the inputted  
           string-
int l=0,p=0,x=0,y=0,q=0,sp=0,z=0,c=0,d=0,f=0,u=0;
String s1="",t=" ";
str=str+" ";
l=str.length();
for(y=0;y<l;y++)
{
if(str.charAt(y)==' ')
{
sp++;
}
}
String s2[]=new String[sp];
int a[]=new int[sp];
for(x=0;x<l;x++)
{
if(str.charAt(x)!=' ' && str.charAt(x+1)==' ')
{
s1=str.substring(p,x+1);
s1=s1.trim();
p=x+2;
s2[c]=s1;
a[c]=s1.length();
c++;
}
}
for(d=1;d<str.length();d++)
{
for(f=0;f<sp;f++)
{
if(a[f]==d)
{
t=t+s2[f]+" ";
}
}
}
return t;
}
Step5-We have made disp function in order to print the original string
         
Step6-End
                      PROGRAM

import java.io.*;
class StringMagic
{
String str;
public void input()throws IOException
{
InputStreamReader i=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(i);
System.out.println("Enter String");
str=br.readLine();
}
public int pailin_count()
{
int l=0,p=0,x=0,y=0,q=0;
String s1="",s2="";
str=str+" ";
l=str.length();
for(x=0;x<l;x++)
{
if(str.charAt(x)!=' ' && str.charAt(x+1)==' ')
{
s1=str.substring(p,x+1);
s1=s1.trim();
p=x+2;
for(y=(s1.length()-1);y>=0;y--)
{
s2=s2+s1.charAt(y);
}
if(s2.equals(s1))
{
q++;
}
s2="";
}
}
System.out.println("No. of palindrome words are"+" "+q);
return q;
}
public String wordssort()
{
int l=0,p=0,x=0,y=0,q=0,sp=0,z=0,c=0,d=0,f=0,u=0;
String s1="",t=" ";
str=str+" ";
l=str.length();
for(y=0;y<l;y++)
{
if(str.charAt(y)==' ')
{
sp++;
}
}
String s2[]=new String[sp];
int a[]=new int[sp];
for(x=0;x<l;x++)
{
if(str.charAt(x)!=' ' && str.charAt(x+1)==' ')
{
s1=str.substring(p,x+1);
s1=s1.trim();
p=x+2;
s2[c]=s1;
a[c]=s1.length();
c++;
}
}
for(d=1;d<str.length();d++)
{




for(f=0;f<sp;f++)
{
if(a[f]==d)
{
t=t+s2[f]+" ";
}
}
}
return t;
}
void disp()
{
System.out.println("the Original String is\n "+str);
System.out.println("the Sorted String is\n "+wordssort());
}
}

   




















  


No comments:

Post a Comment