0% found this document useful (0 votes)
3 views6 pages

Java Programs for Tax, Word Count, HCF/LCM

The document contains three Java classes: Employee, sentence, and HCF_LCM. The Employee class calculates and displays tax based on user input for PAN number, name, and taxable income. The sentence class counts the occurrences of a specified word in a user-provided sentence, while the HCF_LCM class computes the highest common factor (HCF) and least common multiple (LCM) of two input numbers.
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)
3 views6 pages

Java Programs for Tax, Word Count, HCF/LCM

The document contains three Java classes: Employee, sentence, and HCF_LCM. The Employee class calculates and displays tax based on user input for PAN number, name, and taxable income. The sentence class counts the occurrences of a specified word in a user-provided sentence, while the HCF_LCM class computes the highest common factor (HCF) and least common multiple (LCM) of two input numbers.
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

1.

import [Link];

class Employee

int pan;

String name;

double tax_income;

double tax;

void input()

Scanner sc=new Scanner([Link]);

[Link]("Enter your pan number");

pan=[Link]();

[Link]();

[Link]("Enter your name");

name=[Link]();

[Link]("Enter your taxable income");

tax_income=[Link]();

void calc()

if(tax_income<=100000)

tax=0.0; //calculates the tax

}
else if(tax_income>=100001 && tax_income<=150000)

tax=(tax_income-100000)*0.1; //calculates the tax

else if(tax_income<=150001 && tax_income>=250000)

tax=5000+((tax_income-150000)*0.2); //calculates the tax

else

tax=25000+((tax_income-250000)*0.3); //calculates the tax

void display()

[Link]("Pan Number\tName\t Tax Income\t Tax");

[Link](" "+ pan + "\t " + name + "\t" + tax_income + "\t" + tax);

public static void main(String args[])

Employee obj = new Employee();

[Link](); //calls the method input()

[Link](); //calls the method calc()

[Link](); // calls the method display()

}
}

2.

import [Link];

class sentence

String sen;

String word;

int count;

String temp[];

sentence()

sen=""; //assigning default values

word=""; //assigning default values

count=0; //assigning deault values

void input()

Scanner sc=new Scanner([Link]);

[Link]("Enter the sentence");

sen=[Link](); //takes the sentence from the user

[Link]("Enter the word");

word=[Link](); //takes the word to be scanned in the sentence from the user

void check()

{
temp = [Link](" ");

for (int i = 0; i < [Link]; i++)

if ([Link](temp[i]))

count++; //counts the number of times the word appeared in the sentence

void display()

[Link]("The number of times the word "+word+" appears in the sentence: '"+sen+"' is
"+count);

public static void main(String args[])

sentence obj=new sentence();

[Link]();

[Link]();

[Link]();

3.

import [Link];

class HCF_LCM

{
int a,b;

int lcm;

int hcf;

int m,n;

HCF_LCM()

a=m;

b=n;

void input()

Scanner sc=new Scanner([Link]);

[Link]("Enter the first number");

a=[Link]();

[Link]("Enter the second number");

b=[Link]();

void hcf_cal()

int x=a;

int y=b;

while (y != 0)

int t = y;

y = x % y;
x = t;

hcf = x; //calculates the hcf of the two numbers

[Link]("The HCF of "+a+" and "+b+" is "+hcf);

void lcm_cal()

lcm = (a * b) / hcf; //calculates the lcm of the two numbers

[Link]("The LCM of "+a+" and "+b+" is "+lcm);

public static void main(String args[])

HCF_LCM obj=new HCF_LCM();

[Link](); //calls the method input()

obj.hcf_cal(); //calls the method hcf_cal()

obj.lcm_cal(); //calls the method lcm_cal()

You might also like