0% found this document useful (0 votes)
16 views

Akash Jha Computer Project Class X

Uploaded by

Akash Jha
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Akash Jha Computer Project Class X

Uploaded by

Akash Jha
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 63

A PROJECT

ON
COMPUTER APPLICATIONS
LABORATORY ASSIGNMENTS COMPLETED
DURING THE ACADEMIC YEAR 2020-2021

COMPILED BY: AKASH JHA


Class: 10 Sec: A
Session: 2021 ~ 2022
CERTIFICATE
This is to certify that this is the bonafide work of - MASTER
AKASH JHA

of Class 10, Section-A,


of St. Michael’s School, Siliguri.
He has worked on the following laboratory assignments
during the academic year: 2021-2022.

⮚ The student’s initiative, cooperativeness and participation


during the practical classes was:
EXCELLENT/GOOD/AVERAGE/BELOW AVERAGE

⮚ His aesthetic presentation, visual appeal, neatness and


expression in the assignment is:
EXCELLENT/GOOD/AVERAGE/BELOW AVERAGE

⮚ His content accuracy, creativity and analysis of different


programming concepts is:
EXCELLENT/GOOD/AVERAGE/BELOW AVERAGE

Student’s signature Evaluator’s signature


Assignment- 1
Write a Menu Driven Program in java to ask the user
to enter any number and check whether the number
is automorphic or neon as per the user’s choice.

//To enter any number and check whether the number is automorphic or
neon .
import java.util.*;
class automorphic_neon
{
public static void main (String args[])
{
Scanner sc= new Scanner (System.in);
int sum=0,num, sq, t,d=0 ,ch,r;
System.out.print("Enter any number");
num=sc.nextInt();
System.out.println ("Enter 1 to find whether a number is automorphic
or not.");
System.out.println ("Enter 2 to find whether a number is neon or
not.");
ch=sc.nextInt();
switch (ch)
{
case 1://To find a number is automorphic or not
{
sq=num*num;
t=num;
while(t!=0)
{
d++;//no. of digits
t=t/10;
}
r=sq%(int)(Math.pow(10,d));
if(r==num)
{
System.out.print(num+ "is an AUTOMORPHIC number");
}
else
{
System.out.print(num+ "is not an AUTOMORPHIC number");
}
break;
}
case 2 ://to find a number is neon or not
{
sq = num *num;
while(sq != 0)
{
d = sq % 10;
sum += d;
sq /= 10;
}
if(num==sum)
{
System.out.println(num + " is a NEON Number.");
}
else
{
System.out.println(num + " is not a NEON Number.");
}
break;
}
default :System.out.println("WRONG INPUT");
break;
}
}
}
VARIABLE DESCRIPTION TABLE

Variable Data Type Description


name
num int To store a number
ch int To store the choice
sq int To store the square of the number.
sum int To store the sum of the number
d int To store the number of digits.
t int To store the number of temporarily.
r int To store the new number which we need to
compare.

SAMPLE INPUT AND OUTPUT :


Assignment-2
Write a menu driven program in Java to ask the user
to enter any 2 numbers and print the LCM or the
HCF of the numbers as per the user’s choice.

// To enter any 2 nos. and print the HCF or LCMof the number.
import java.util.*;
class HCF_or_LCM
{
public static void main (String args[])
{
Scanner sc= new Scanner (System.in);
int a,b,ch,i;
System.out.println ("Enter any 2 nos.");
a=sc.nextInt();
b=sc.nextInt();
System.out.println ("Enter 1 to find the HCF of the 2 entered nos.");
System.out.println ("Enter 2 to find the LCM of the 2 entered nos.");
ch=sc.nextInt();
switch (ch)
{
case 1 : // To enter any 2 nos. and print the HCF of the nos.
for (i=a;i>=1;i--)
{
if (a%i==0 && b%i==0)
{
System.out.print ("HCF = "+i);
break;
}
}
break;
case 2 :// To enter any 2 nos. and LCM of the nos.
for (i=a;i<=a*b;i++)
{
if (i%a==0 && i%b==0)
{
System.out.print ("LCM = "+i);
break;
}
}
break;
default :System.out.print ("WRONG INPUT");
}
}// close of main method
}// close of class
VARIABLE DESCRIPTION TABLE

Variable Data Type Description


name
a int To store a number
b int To store a number
ch int To store the choice
i int Loop variable

SAMPLE INPUT AND OUTPUT :


Assignment-3
Write a program to input an integer and check
whether the integer is PERFECT, ABUNDANT or
DEFICIENT.
If the sum of the factors of a number excluding the
number is equal to the number then it is Perfect, if
greater than the number then it is Abundant and if it
is less than the number then it is Deficient.

// To input a number and check whether the integer is PERFECT,


ABUNDANT or DEFICIENT.
import java.util.*;
class perfect_abundant_deficient
{
public static void main (String args[])
{
Scanner sc=new Scanner (System.in);
int n,i,sum=0;
System.out.println("Enter a number");
n=sc.nextInt();
for(i=1;i<n;i++)
{
if(n%i==0)
{
sum = sum+i;
}
}
if(sum==n)
{
System.out.println("It is a Perfect number");
}
else if(sum>n)
{
System.out.println("It is an Abundant number");
}
else if(sum<n)
{
System.out.println("It is a Deficient number");
}
}//close of main method
}//close of class
VARIABLE DESCRIPTION TABLE

Variable name Data Type Description


n int To store a number
i int Loop variable
sum int To store the factors

SAMPLE INPUT AND OUTPUT :


Assignment-4
The International Standard Book number (ISBN) is a
unique book identifier which is printed on every
book. The ISBN is based upon a 10 digit code. The
ISBN is legal if:
1*digit1+2*digit2+3*digit3+4*digit4+5*digit5+
6*digit6+7*digit7+8*digit8+9*digit9+10*digit1
0 is divisible by 11.
Write a program in java to:
I. Input the ISBN code as a 10 digit number.
II. If the ISBN is not a 10digit number, then output
the message “ILLEGAL ISBN” and terminate the
program.
III. If the number is a 10digit number then compute
the sum as explained above and print whether
the number is a “Legal ISBN” or an “Illegal
ISBN”.
For example:1401601499 is a Legal ISBN.

//To print whether it is an illegal or legal isbn


import java.util.*;
class ISBN_NO
{
public static void main (String args[])
{
Scanner sc= new Scanner (System.in);
long num, i,ld,p,sum=0;
System.out.print ("Enter an ISBN code");
num = sc.nextLong();
if (num>=1000000000l &&num<=9999999999l)
{
for(i=10;i>=1;i--)
{
ld=num%10;
p= ld*i;
sum=sum+p;
num= num/10;
}
if (sum%11==0)
{
System.out.print ("It is a legal ISBN NO.");
}
else
{
System.out.print ("It is not a legal ISBN NO.");
}
}
else
{
System.out.print ("Illegal ISBN");
}
}
}

VARIABLE DESCRIPTION TABLE

Variable name Data Type Description


num long To store the ISBN code.
i long Loop variable.
ld long To store the last digit.
p long To store the product .
sum long To store the sum of the number.

SAMPLE INPUT AND OUTPUT :


Assignment-5
Write a program in Java to enter any number and check whether the
number is EMIRP or not.
An EMIRP(prime spelled backward) is a prime number that results in a
different prime when the decimal digits are reversed. This decision
excludes the related palindromic prime.

//To check whether a number is emirp or not.


import java.util.*;
class emirp
{
public static void main(String args[])
{
Scanner sc = new Scanner (System.in);
int n,ld,rev=1,c=0,d=0,i,temp;
System.out.print("Enter any number ");
n=sc.nextInt();
temp=n;
for(i=1;i<=n;i++)
{
if(n%i==0)
{
c++;
}
}
if(c==2)
{
while(n!=0)
{
ld=n%10;
rev=rev*10+ld;
n=n/10;
}
for(i=1;i<=rev;i++)
{
if(rev%i==0)
{
d++;
}
}
if(d==2&&rev!=temp)
{
System.out.print("It is a emirp number");
}
else
{
System.out.print("It is not a emirp number");
}
}
else
{
System.out.print("It is not a prime number");
}
}
}

VARIABLE DESCRIPTION TABLE

Variable name Data Description


Type
n int To store the number
ld, int Loop variable.
c int Counting variable
i int Loop variable.
temp int To store the number temporarily.
rev int To store the reverse of the
number.
d int Counting variable

SAMPLE INPUT AND OUTPUT :


Assignment-6
Write a program in Java using switch case and ask
the user to enter any number and check whether
the number is a TWIST number or PALINDROME
number.

// To enter any number and print whether it is a palindrome number or a


twist number
import java.util.*;
class palindrom_twist
{
public static void main (String args [])
{
Scanner sc= new Scanner ( System.in ) ;
int n,ch,i,ld,sum=0,temp;
System.out.println("Enter any number ");
n = sc.nextInt();
temp=n;
System.out.println("Enter 1 for palindrome and 2 for twist ");
ch = sc.nextInt();
switch(ch)
{
case 1:int rev=0;
while(n!=0)
{
ld=n%10;
rev=rev*10+ld;
n=n/10;
}
if(temp==rev)
{
System.out.print("IT IS A PALINDROME NUMBER");
}
else
{
System.out.print("IT IS NOT PALINDROME");
}
break ;
case 2:i=n;
ld=n%10;
while(n>9)
{
n=n/10;
}
if (ld%2==0 && n%2!=0)
{
System.out.print (i+" is a twist number");
}
else
{
System.out.print(i+" is not a twist number ");
}
break ;
default :System.out.print( "Wrong input " ) ;
}
}
}

VARIABLE DESCRIPTION TABLE

Variable name Data Description


Type
n int To store the number
ld int To store the last digit.
ch int To store the choice
i int Loop variable.
sum int To store the sum of number.
temp int To store the number temporarily

SAMPLE INPUT AND OUTPUT :


Assignment-7
Write a program to input a number and perform the
following operations:
i. Print the number in digits.
ii.Print the sum of the digits.
iii.Print the smallest digit present in the number.

// To print the number of digits, sum of the digits and smallest digit
present in the number
import java.util.*;
class num_sum_small
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int n,c=0,ld,sum=0,small=9;
System.out.println("Enter any number");
n=sc.nextInt();
while(n!=0)
{
c++;
ld=n%10;
sum=sum+ld;
small = Math.min(ld, small);
n=n/10;
}
System.out.println("The number of digits = "+c);
System.out.println("The sum of the digits = "+sum);
System.out.println("The smallest digit is "+small);
} // close of main method
} // close of class

VARIABLE DESCRIPTION TABLE

Variable name Data Description


Type
n int To store the number
ld int To store the last digit.
c int Counting variable
sum int To store the sum of number.
small int To store the smallest digit.

SAMPLE INPUT AND OUTPUT :


Assignment-8
Write a program in Java to print the first ten terms
of the Tribonacci series starting from 0.

// To print the first 10 terms of the tribonacci series


import java.util.*;
class Tribonacci
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("The first 10 terms of the Tribonacci
series are : ");
int a=0,b=0,c=1,d,i;
System.out.println(a+"\n"+b+"\n"+c);
for(i=1;i<=7;i++)
{
d=a+b+c;
System.out.println(d);
a=b;
b=c;
c=d;
}
}//close of main method
}//close of class

VARIABLE DESCRIPTION TABLE

Variable Variable Description


name Type

n int Stores the number of terms


a Int Stores the first term
b int Stores the second term
c Int Stores the third term
d int Stores the sum of the three terms

SAMPLE INPUT AND OUTPUT :


Assignment-9
Write a menu program to print the sum of either of
the following series:
i. S=9,99,8,89,7,79.....1,19
ii. S=(1*2)+(2*3)+(3*4)....(19*20)

// To generate the series as per users choice.


import java.util.*;
class series
{
public static void main (String args [])
{
Scanner sc=new Scanner (System.in);
int ch,i,p,s=0,j,r=0;
System.out.println("Enter 1 to print the sum of first series");
System.out.println("Enter 2 to print the sum of the second
series");
ch = sc.nextInt();
switch(ch)
{
case 1: for (i=9;i>=1;i--)
{
p= ((i*10)+9);
s= s+p+i;
}
System.out.print("the sum is "+s);
break;
case 2 :for(j=1;j<20;j++)
{
r +=j*(j+1);
}
System.out.print("the sum is "+r);
break;
default: System.out.print("WRONG INPUT");
} //close of switch case
} // close of main method
}//close of class
VARIABLE DESCRIPTION TABLE

Variable Variable Variable description


name type

ch int To store the choice of the user


i int Loop variable for case 1
p int To store the series
s int To store the sum of the first series
j int Loop variable for case 2
r int To store the sum of second series

SAMPLE INPUT AND OUTPUT :


Assignment- 10
Write a program in Java to enter a binary number.
Check whether the number entered in a Binary or
not. If it is a Binary number then print its decimal
equivalent.
Sample input:-1101
Output:- The decimal equivalent is 13

// To check whether the entered number is binary or not and change it to


its decimal equivalent
import java.util.*;
import java.lang.*;
class Binary_to_Decimal
{
public static void main(String args [])
{
Scanner sc=new Scanner(System.in);
int n,ld,p=0,deci=0,s,c=0;
System.out.println("Enter any Binary number");
n=sc.nextInt();
while(n!=0)
{
ld=n%10;
if(ld==0 || ld==1)
{
s=(int)Math.pow(2,p)*ld;
deci=deci+s;
p++;
n=n/10;
}
else
{
c++;
n=n/10;
}
}
if(c==0)
{
System.out.print("The decimal equivalent is "+deci);
}
else
{
System.out.print("It is not a binary number");
}
} //close of main method
} //close of class
VARIABLE DESCRIPTION TABLE

Variable Variable Variable description


name type

n int To store the number.


ld int To store the last digit
p int Counting variable
s int To store the sum .
deci int Loop variable for case 2
c int Counting variable

SAMPLE INPUT AND OUTPUT :


Assignment- 11
Write a program to enter any 10 number into an
array. Also ask the user to enter another number
and print whether the number is present or not. If
the number is present then print " Search
successful", otherwise print " Search successful".
( Using Linear Search Technique only)

//To check whether the number entered by the user is present in array or
not.
import java.util.*;
class Linearsearch
{
public static void main (String args [])
{
Scanner sc = new Scanner ( System.in);
int a []= new int [10] ;
int i,ns,f=0;
System.out.println("Enter a number to search");
ns=sc.nextInt();
System.out.println("Enter any 10 numbers");
for(i=0;i<9;i++)
{
a[i]=sc.nextInt();
if(ns==a[i])
{
f=1;
}
}
if(f==1)
System.out.print("The number is present.");
else
System.out.print("The number is not present.");
}
}
VARIABLE DESCRIPTION TABLE

Variable Variable Variable description


name type

ns int To store the choice of the user


i int Loop variable
f int Counting variable
a int To store the numbers into an array.

SAMPLE INPUT AND OUTPUT :


Assignment- 12
Write a program to accept the following numbers
into an array.
24, 28, 34, 56, 78, 89, 90, 99, 100.
Ask the user to enter any number and print whether
the number is present or not from the list of
assigned numbers using the Binary search
technique.

//To check whether the number entered by the user is present in array or
not.
import java.util.*;
class search
{
public static void main (String args [])
{
Scanner sc = new Scanner ( System.in);
int a []= {24, 28,34,56,78,89,90,99,100} ;
int i,ns,f=0,p=0;
System.out.println("Enter a number to search");
ns=sc.nextInt();
for(i=0;i<9;i++)
{
if(ns==a[i])
{
f=1;
p=i;
break;
}
}
if(f==1)
{
System.out.print("The number is present at position "+ (p+1));
}
else
{
System.out.print("The number is not present.");
}
}
}
VARIABLE DESCRIPTION TABLE

Variable Variable Variable description


name type

ns int To store the choice of the user


i int Loop variable
f int Counting variable
a int To store the numbers into an array.
p int To store the value of i temporarily.

SAMPLE INPUT AND OUTPUT :


Assignment- 13
Write a program to enter any 12 number and print
them in ascending order using bubble short
technique.

//To enter any 12 numbers and print them in ascending order using bubble
sort Technique.
import java.util.*;
class ascending12
{
public static void main (String args [])
{
Scanner sc = new Scanner ( System.in);
int a[ ]=new int [12];
int i,j,temp;
System.out.println("Enter any 12 numbers");
for(i=0;i<12;i++)
{
a[i]=sc.nextInt();
}
//bubble sorting
for(i=0;i<11;i++)
{
for(j=0;j<11-i;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}//close of loop
}//close of outer loop
}
System.out.println("The number in ascending order are :");
for(i=0;i<12;i++)
{
System.out.println(a[i]);
}
}
}

VARIABLE DESCRIPTION TABLE


Variable Variable Variable description
name type

temp int To store the number temporarily.


i int Loop variable
j int Loop variable
a int To store the numbers into an array.
SAMPLE INPUT AND OUTPUT :
Assignment- 14
Write a program to enter any 12 number and print
them in ascending order using selection short
technique.

//To enter any 12 numbers and print them in ascending order using
selection sort Technique.
import java.util.*;
class ascending_selectionsort
{
public static void main (String args [])
{
Scanner sc = new Scanner ( System.in);
int a[]=new int [12];
int i,j,min,temp;
System.out.println("Enter any 12 numbers");
for(i=0;i<12;i++)
{
a[i]=sc.nextInt();
}
//Selection sorting
for(i=0;i<11;i++)
{
min=i;
for(j=i+1;j<12;j++)
{
if(a[min]>a[j])
{
min=j;
}
}//close of inner loop
//swap two numbers
temp=a[min];
a[min]=a[i];
a[i]=temp;
}//close of outer loop
System.out.println("The number in ascending order are");
for(i=0;i<12;i++)
{
System.out.println(a[i]);
}
}
}
VARIABLE DESCRIPTION TABLE
Variable Variable Variable description
name type

temp int To store the number temporarily.


i int Loop variable
j int Loop variable
a int To store the numbers into an array.
min int To store the smallest number.

SAMPLE INPUT AND OUTPUT :


Assignment-15
Write a program to Enter any 5 numbers in array A
and 3 numbers in array B. Merge the two arrays and
print them.

//To merge two arrays.


import java.util.*;
class merge
{
public static void main (String args[])
{
Scanner sc = new Scanner ( System.in);
int A[]= new int[5];
int B[]= new int[3];
int C[]= new int[8];
int i,j;
System.out.println("Enter any 5 numbers");
for (i=0;i<5;i++)
{
A[i]=sc.nextInt();
}
System.out.println("Enter any 3 numbers");
for (i=0;i<3;i++)
{
B[i]=sc.nextInt();
}
//merging
for(i=0;i<5;i++)
{
C[i]=A[i];
}
for(j=0;j<3;j++)
{
C[i+j]=B[j];
}
System.out.print("The merged array is");
for(i=0;i<8;i++)
{
System.out.println(C[i]);
}
}
}
VARIABLE DESCRIPTION TABLE

Variable Variable Variable description


name type

i int Loop variable


j int Loop variable
A int To store the numbers into an array.
B int To store the numbers into an array.
c int To store the numbers into an array.

SAMPLE INPUT AND OUTPUT :


Assignment- 16
Write a program to enter 10 numbers into an array
and print the array after shifting all odd numbers to
the top and even numbers to the bottom without
changing the order of the numbers.

// To print the odd number followed by even number


import java.util.*;
class odd_even
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int a []=new int [10];
int i;
System.out.println("Enter any 10 numbers");
for(i=0;i<10;i++)
{
a[i]=sc.nextInt();
}
System.out.println("The odd numbers followed by even are :");
for(i=0;i<10;i++)
{
if(a[i]%2!=0)
{
System.out.println(a[i]);
}
}
for(i=0;i<10;i++)
{
if(a[i]%2==0)
{
System.out.println(a[i]);
}
}
}
}

VARIABLE DESCRIPTION TABLE

Variable Variable Variable description


name type

i int Loop variable


a int To store the numbers into an array.
SAMPLE INPUT AND OUTPUT :
Assignment- 17
Design a class to overload a function Volume() as
follows
a. double volume(double R) as an argument,
returns the volume of sphere using the
formula(v=4/3*22/7*r*r*r)
b. double volume (double H, double R)-with height
H and radius R as the arguments , returns the
volume of cylinder using the formula(v=22/7*r*h)
c. double volume(double L, double B, double H) as
arguments returns the volume of cuboid(v=L*B*H)

//To overload a function volume as follows


import java.lang.*;
class overload_volume
{
double volume (double R)
{
double vo;
vo=(4.0/3.0)*(22.0/7.0)*R*R*R;
return vo;
}
double volume (double R,double H)
{
double vol;
vol=(22.0/7.0)*R*R*H;
return vol;
}
double volume (double L,double B, double H)
{
double vl;
vl=L*B*H;
return vl;
}
public static void main(String args[])
{
overload_volume ob=new overload_volume();
double a,b,c;
a= ob.volume(10.5);
b= ob.volume(7.0,15.0);
c= ob.volume(3.0,4.0,5.0);
System.out.println("The volume of sphere is "+a);
System.out.println("The volume of cylinder is "+b);
System.out.println("The volume of cuboid is "+c);
}
}
VARIABLE DESCRIPTION TABLE

Variable Variable Variable description


name type

R double To store the radius.


L double To store the length.
B double To store the breadth
H double To store the height.
vo double To store the volume
vol double To store the volume
vl double To store the volume.
a double To call the functions
b double To call the functions
c double To call the functions.

SAMPLE INPUT AND OUTPUT :


Assignment- 18
Design a class to overload a function series() as
follows:
I. double series(double n)with one double
argument and returns the sum of the series,
sum= 1/1 +1/2+1/3+…..+1/n
II. double series (double a, double n) with two
double arguments and returns the sum of the
series.
Sum=1/a^2+4/a^5+7/a^8+10/a^11+………..to
n terms

//To print the following series.


import java.util.Scanner;
class overload_sum
{
public static double series(double n)
{
double s=0.0d;
for(int i=1;i<=n;i++)
{
s=s+(double)1.0/i;
}
return s;
}
public static double series (double a,double n)
{
double s=0.0d;
int x=1,y=2;
for(int i=1;i<=n;i++)
{
s=s+x/Math.pow(a,y);
x=x+3;
y=y+3;
}
return s;
}
public static void main (String args[])
{
Scanner in =new Scanner(System.in);
double n,a,result;
System.out.println("Enter last limit of the series");
n=in.nextDouble();
a=in.nextDouble();
result=series(a,n);
System.out.println("Result of the series "+result);
}
}

VARIABLE DESCRIPTION TABLE

Variable Variable Variable description


name type

n double Last limit of the series.


sum double Sum of the terms.
i int Loop variable
a double Variable used in terms.
x int Temporary variable
y int Temporary variable
result double To contain the sum of the series.

SAMPLE INPUT AND OUTPUT :


Assignment- 19
Define a class Employee having the following decription
Data members/Instance variable
Int pan – to store personal account number
String name- to store the name
Double tax income-to store annual taxable income
Double tax-to store tax that is calculated
Member functions
Input()-store the pan number, name, taxable income
Calc()-calculate tax for employee
Display()-outputdetails of an employee.
Write a program to compute the tax according to given conditions
and display the output as given form.
Output: Pan number Name Taxable Income Tax
Income Tax Rate
Upto 100000 no tax
From 100001 to 150000 10% of the income abopve 1 lakh
From 150000 to 250000 5000+20% of income above 1.5
Above 250000 25000+30% of income above
2.5lakh
//To print the tax to be paid.
import java.util.*;
class Employee
{
int pan;
String name;
double tax_income,tax;
void input()
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter the personal account number ");
pan=sc.nextInt();
System.out.print("Enter the name ");
name=sc.next();
System.out.print(" Enter the taxable income ");
tax_income=sc.nextDouble();
}
void calc()
{
if(tax_income<=100000)
tax=0.0;
else if (tax_income>=100001 &&tax_income<=150000)
tax=(tax_income-100000)*10.0/100.0;
else if (tax_income>=150001 &&tax_income<=250000)
tax=5000+(tax_income-150000)*20.0/100.0;
else if (tax_income>250000)
tax=30000+(tax_income-250000)*30.0/100;
}
void display()
{
System.out.println("Pan number\tName\tTaxable Income\t Tax");
System.out.println(pan+" \t "+name+" \t "+tax_income+" \t "+tax);
}
public static void main(String args[])
{
Employee ob= new Employee();
ob.input();
ob.calc();
ob.display();
}
}// close of class
VARIABLE DESCRIPTION TABLE

Variable Variable Variable description


name type

pan int To store the permanent account number.


tax_income double To store the taxable income.
tax double To store the tax to be paid.
name string To store the name.

SAMPLE INPUT AND OUTPUT :


Assignment-20
Anshul transport company charges for the parcels of its
customers as per the specifications given below. ( Class name:
Atransport )
Member Variable: String name- to store the name of the
customer.
Int w- to store the weight of the parcel in kg.
Int charge- to store the charge of the parcel.
Member functions : void accept()-to accept the name of the
customer and weight of the parcel from the user.(using scanner
class )
Void calculate()- to calculate the charge as per the following
criteria given below.( A surcharge of 5% is also charged on the
bill.)
Weight in kg
charges/kg
Up to 10kg
25/kg
Next 20kg
20/kg
Above 30kg
10/kg
Void print () – to print the name of the customer, weight of the
parcel, total bill inclusive of surcharge in a tabular form
(NameWeight Bill amount)
Define a class with the above, mentioned specifications, create
the main method, create an object and invoke the member
methods.

//To find the total bill paid by a customer for transport.


import java.util.*;
class Atransport
{
String name;
int w ,charge;
void input()
{
Scanner sc = new Scanner (System.in);
System.out.print("Enter the name of the customer");
name=sc.next();
System.out.print("Enter the weight of the parcel in kg.");
w=sc.nextInt();
}
void calculate()
{
if (w<=10)
{
charge=w*25;
}
else if (w>=11 && w<=30)
{
charge=250+(w-10)*20;
}
else if (w>30)
{
charge=250+400+(w-30)*10;
}
charge = charge + charge*5/100;
}
void print()
{
System.out.println("Nmae/Weight/Bill Amount");
System.out.println(name+"\t"+w+"\t"+charge);
}
public static void main (String args[])
{
Atransport ob = new Atransport();
ob.input();
ob.calculate();
ob.print();
}// close of loop
}

VARIABLE DESCRIPTION TABLE

Variable Variable Variable description


name type

w int To store weight.


charge int To store the bill to be paid.
name string To store the name.

SAMPLE INPUT AND OUTPUT :

You might also like