Programs on Sequence Structure
1. A company
has employees who are divided into four grades as follows:
Grade Basic(Rs./month) DA HRA
1 10,000 or more 40% 30%
2 5,000 - < 10,000 40% 25%
3 < 5,000 but > 2,000 30% 20%
4 2,000 or less 30% 15%
If the Net salary which is the total of Basic, DA, and HRA, is above Rs.50,000 per month then Income Tax at the rate of 30% of the annual salary exceeding 50,000 is deducted on monthly basis at source. Taking name of the employees and the Basic (monthly) pay as inputs, a pay slip, which contains Name, Grade, Basic monthly pay, DA, HRA, Monthly Income Tax and Net Monthly Salary, for employee is to be printed. Write a java program to perform this job.
Grade Basic(Rs./month) DA HRA
1 10,000 or more 40% 30%
2 5,000 - < 10,000 40% 25%
3 < 5,000 but > 2,000 30% 20%
4 2,000 or less 30% 15%
If the Net salary which is the total of Basic, DA, and HRA, is above Rs.50,000 per month then Income Tax at the rate of 30% of the annual salary exceeding 50,000 is deducted on monthly basis at source. Taking name of the employees and the Basic (monthly) pay as inputs, a pay slip, which contains Name, Grade, Basic monthly pay, DA, HRA, Monthly Income Tax and Net Monthly Salary, for employee is to be printed. Write a java program to perform this job.
2. Write a
program to input the values of three coefficients (A,B,C) of a quadratic
equation: (AX2 + BX + C = 0). Find the roots of the equation and
display them, stating whether roots are real unequal, real equal or imaginary.
[10+5]
Programs on Selection Structure
- Write a program to computerize the billing operation of a
telephone of a telephone company .The bill has to be generated based on
the following conditions:
Number
of calls Amount per call
First 50 calls free
Next 100 calls 50
P per call
Next 200 calls 80
P per call
Rest of the calls Rs 1.20 per call
A rent
of Rs 120 is charged from every customer.A tax of 15% is charged on the sum of charges and rent.The
total amount is tax added to the sum of charges and rent .Print the bill for a
customer.
- Display a menu
as follows:
1. Check for prime number
2. Display number of digits
3. Exit
Each option is defined in a separate function within the subclass, the required parameter is accepted in the main class. The main class is also to display the menu and to accept the choice from the user and to execute the corresponding function (use data input concept). - Write a program
that outputs the results of the following evaluations based on the number
entered by the user.
(i) Natural logarithm of the number
(ii) Absolute value of the number
(iii) Square root of the number
(iv) Random numbers between 0 and 1. - Using a switch statement, write a menu driven program to
convert a given temperature from Fahrenheit to Celsius and vice versa. For
an incorrect choice, an appropriate error message should be displayed.
- Write a menu driven class to
accept a number from the user and check whether it is a Palindrome or a
Perfect Number.
(a) Palindrome Number- (a number is a Palindrome which when read
in reverse order is same as read in the right order). Example: 11, 101, 151
etc.
(b) Perfect Number- (a number is called Perfect if it is equal to
the sum of its factors other than the number itself.) Example: 6 = 1 + 2 + 3
- Write a menu driven program to
access a number from the user and check whether it is a BUZZ number or to
accept any two numbers and to print the GCD of them.
a) A BUZZ number is the number which either ends with 7 is is
divisible by 7.
b) GCD (Greatest Common Divisor) of two integers is calculated by
continued division method. Divide the larger number by the smaller; the
remainder then divides the previous divisor. The process is repeated till the
remainder is zero. The divisor then results the GCD.
- An electronics shop has announced
the following seasonal discounts on the purchase of certain items.
Purchase Amount in Rs. Discount
on Laptop Discount on Desktop
PC
0 – 25000 0.0%
5.0%
25001 – 57000 5.0%
7.6%
57001 – 100000 7.5%
10.0%
More than 100000 10.0%
15.0%
Write a program based on the above criteria to input name,
address, amount of purchase and type of purchase (L for Laptop and D for
Desktop) by a customer. Compute and print the net amount to be paid by a
customer along with his name and address.
(Hint: discount = (discount
rate/100)* amount of purchase
Net amount = amount of purchase – discount)
- Shasha Travels
Pvt. Ltd. gives the following discount to its customers:
Ticket Amount
|
Discount
|
Above
Rs. 70000
|
18%
|
Rs.
55001 to 70000
|
16%
|
Rs.
35001 to 55000
|
12%
|
Rs.
25001 to 35000
|
10%
|
less
than Rs. 25001
|
2%
|
Write a
program to input the name and ticket amount for the customer and calculate the
discount amount and net amount to be paid. Display the output in the following
format for each customer :
Sr. No.
|
Name
|
Ticket charges
|
Discount
|
Net amount
|
1
|
–
|
–
|
–
|
–
|
(Assume
that there are 15 customers, first customer is given the serial number (Sr.No.)
1, next customer 2 … and so on)
- Given below is a hypothetical
table showing rates of income tax for the male citizens below the age of
65 years:
Taxable Income (TI) in Rs. Income
Tax in Rs.
Does not exceed Rs. 1,60,000 NIL
Is greater than Rs. 1,60,000 (TI
– 1,60,000)*10%
and less than or equal to Rs. 5,00,000
Is greater than Rs. 5,00,000
[(TI
– 5,00,000)*20%] + 34,000
and less than or equal to Rs. 8,00,000
Is greater than Rs. 8,00,000 [(TI
– 8,00,000)*30%] + 94,000
Write a program to input the age, gender (male or female) and
taxable income of a person. If the age is more than 65 years or the gender is
female, display “wrong category”. If the age is less than or equal to 65 years
and the gender is male, compute and display the income tax payable as per the
table given above.
10. Using the switch
statement, write a menu driven program to calculate the maturity amount of a
Bank Deposit.
The user is given the following options:
The user is given the following options:
- Term Deposit
- Recurring Deposit
For option (i) accept principal(P), rate of
interest(r) and time period in years(n). Calculateand output the maturity
amount(A) receivable using the formula
A =

For option (ii) accept Monthly Installment
(P), rate ofinterest(r) and time period in months(n). Calculate and output the
maturity amount(A) receivable using the formula
A =
For an incorrect option, an appropriate error
message should be displayed.
- Write a program in to input and
store all roll numbers, names and marks in 3 subjects of n number of
students in five single dimensional arrays and display the remark based on
average marks as given below
Average marks = total marks/3
Average marks
Remark
85 – 100
EXCELLENT
75 – 84
DISTINCTION
60 – 74 FIRST
CLASS
40 – 59 PASS
Less than 40 POOR
Programs on Looping
1. Write a
program to compute and display the sum of the following series:
S = (1)/(1!) – (1 + 2)/(1! * 2!)
+ (1+2 +3)/(1! * 2! * 3!) - (1 + 2 + 3 + 4)/(1! * 2! * 3! * 4!) +
………..(1 + 2 + 3 + 4 + ….+ n)/(1! * 2! * 3! * 4! * ….. * n!)
where n is any integer value taken from
the user as input.
2. Program
in loops [7+8]
i)
Write a program to print the following output
1
2
3
4
5 6
Number of lines are to be inputted by the user
ii) WAP to calculate the sum of the following series.
S = x/(x+1)!- x2/(x+2)!+x3/(x+3)!
……..n terms
3. Program
in loops [7+8]
(a) Write a java program to print n
terms of the fibonacci series as :
0,1,1,2,3,5,8……n terms
(b) Write a program to
accept a number form user and check it is prime or not.
[ Prime number is divisible by 1 and
itself e.g 3 it is divisible by 1 and 3, 17 it is divisible by 1 and 17
]
4.
Write a program to calculate and print the sum of odd numbers and the
sum of even numbers for the first n natural numbers. The integer n is to be entered by the user.
5.
Write a program to print the sum of negative numbers, sum of
positive even numbers and sum of positive odd numbers from a list of numbers(N)
entered by the user. The list terminates when the user enters a zero.
6.
Write a program to initialize the given data in an array and find
the minimum and maximum values along with the sum of the given elements.
Numbers : 2 5 4 l 3
Output : Minimum value : l
Maximum value : 5
Sum of the elements : 15
Numbers : 2 5 4 l 3
Output : Minimum value : l
Maximum value : 5
Sum of the elements : 15
- Write a program to calculate and
print the sum of each of the following series:
(a) Sum (S) = 2 - 4 + 6 - 8 + .... - 20
(b) Sum (S) = x/2 + x/5 + x/8 + x/11 + .... x/20
(Value of x to be input by the user.)
8.
Write a program to generate a triangle or an inverted triangle
till n terms based upon the user’s choice of triangle to be displayed.
Example 1
Example
2
Input:
Type 1 for a triangle and type 2 for an
inverted triangle
1 2
Enter the
number of terms Enter
the number of terms
5 6
Output: Output:
1 6
6 6 6 6 6
2 2 5
5 5 5 5
3 3 3 4
4 4 4
4 4 4 4 3
3 3
5 5 5 5 5
2
2
1
9.
Write a menu driven program to accept a number and check and
display whether it is a prime number or not OR an automorphic number or not.
(Use switch-case statement)
(a) Prime
number: A number is said to be a prime number if it is divisible only by 1 and
itself and not by any other number.
Example:
3, 5, 7, 11, 13, etc.
(b)
Automorphic number: An automorphic number is the number which is contained in
the last digit(s) of its square.
Example:
25 is an automorphic number as its square is 625 and 25 is present as the last
2 digits.
10.
Write a program to input a number and print whether the number is
a special number or not. (A number is said to be a special number, if
the sum of the factorial of the digits of the number is same as the original
number).
Example:
145 is a special number, because 1! + 4! + 5! = 1 + 24 + 120 = 145
(where !
stands for the factorial of the number and the factorial value of a number is
the product of all integers from 1 to that number, example 5! = 1*2*3*4*5 =
120).
11.
Write a menu driven program to perform the following . (Use
switch-case statement)
(a) To print the series 0, 3, 8, 15, 24 …….
n terms
(value of
‘n’ is to be an input by the user).
(b) To find the sum of the series given
below:
S = ½ + ¾ + 5/6 + 7/8 …….. 19/20
12.
Using the switch statement, write a menu driven program to:
i)
Generate and display the first 10 terms of the Fibonacci series
0, 1, 1,
2, 3, 5, …
The first
two Fibonacci numbers are 0 and 1, and each subsequent number is the sum of the
previous two.
ii) Find
the sum of the digits of an integer that is input:
Sample
input: 15390
Sample
output: Sum of the digits = 18
For an
incorrect choice, an appropriate error message should be displayed.
13.
The International Standard Book Number (ISBN) is a unique numeric
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*digit10 is divisible
by 11.
Example:
For an ISBN 1401601499
Sum =1*1
+ 2*4 + 3*0 + 4*1 + 5*6 + 6*0 + 7*1 + 8*4 + 9*9 + 10*9 = 253 which is divisible
by 11.
Write a
program to:
i. Input the ISBN code as a 10-digit
number
ii. If the ISBN is not a 10-digit
number, output the message "Illegal ISBN" and terminate the program
iii. If the number is 10-digit, extract
the digits of the number and compute the sum as explained above.
If the
sum is divisible by 11, output the message "Legal ISBN". If the sum
is not divisible by 11, output the message "Illegal ISBN".
14.
Using the switch statement, write a menu driven program:
i. To check and display whether the
number input by the user is a composite number or not (A number is said to be a
composite, if it has one or more than one factors excluding 1 and the number
itself).
Example: 4,
6, 8, 9,
ii. To find the smallest digit of an
integer that is input:
Sample
input: 6524
Sample
output: Smallest digit is 2
15.
A special two-digit number is such that when the sum of its digits
is added to the product of its digits, the result is equal to the original
two-digit number.
Example:
Consider the number 59.
Sum of
digits = 5 + 9 = 14
Product
of its digits = 5 x 9 = 45
Sum of
the sum of digits and product of digits = 14 + 45 = 59
Write a
program to accept a two-digit number. Add the sum of its digits to the product
of its digits. If the value is equal to the number input, output the message
“Special 2-digit number” otherwise, output the message “Not a special2-digit
number”.
16.
Write two separate programs to generate the following patterns
using iteration(loop) statements :
(a) *
* #
* # *
* # * #
* # * # *
(b) 5 4 3 2 1
5 4 3 2
5 4 3
5 4
5
17.
Use switch statement, write a menu driven program to:
(i) To
find and display all the factors of a number input by the user (including 1 and
excluding number itself.)
Example :
Sample
Input : n=15.
Sample
Output : 1,3,5
(ii) To
find and display the factorial of a number input by the user(the factorial of a
non-negative integer n ,denoted by n!, is the product of all integers less than
or equal to n. Example : Sample Input : n=5 Sample Output : 120.
For an
incorrect choice , an appropriate error message should be displayed.
18.
Using the switch statement, write a menu driven program for the
following:
(i) To
print the Floyd’s triangle [Given below]
1
2 3
4 5 6
7 8
9 10
11 12 13
14 15
(ii) To
display the following pattern
I
I C
I C S
I C S E
For an
incorrect option, an appropriate error message should be displayed.
19.
Write a program to accept a number and check and display whether
it is a spy number or not.
(A number
is spy if the sum its digits equals the product of the digits.)
Example:
consider the number 1124 , sum of the digits = 1 + 1 + 2 + 4 = 8
Product
of the digits = 1 X 1 X 2 X 4=8
20.
Using switch statement, write a menu driven program for the following
:
i) To
find and display the sum of the series given below:
S=
(where x=2)
ii) To
display the following series:
1 11
111 1111 11111
For an
incorrect option, an appropriate error message should be displayed.
Programs on Array
1. Write a
program to store 20 different names along with the corresponding telephone
numbers. Enter a name from the console and search
whether the name is present or not. If the name is
present, display the name along with the phone number, otherwise
display an appropriate message for the name not
found.
2. Write a
program to accept 15 integer from the keyboard, assuming that no integer
entered is a zero. Enter a number from keyboard and search in an array using
Binary Search Technique.
If the number is
present display " 67 is found at 5 index number" If the number is 67
and stored at 5 index number in an array. Else display " Number is not
present in the array".
3. Array
Program
(a) A class
namely, 'linear' with a member function to input a list of 10 elements in an
array. Write a program to declare the class, 'linear' and define the method of
the display of the numbers in ascending order using the Selection Sort
Method.[8]
(b) Write a program to create a double dimensional array to store 12 elements. Calculate and print the position of the maximum and minimum element of the array. [7]
(b) Write a program to create a double dimensional array to store 12 elements. Calculate and print the position of the maximum and minimum element of the array. [7]
- The marks
obtained by 50 students in a subject are tabulated as follows:-
Name Marks
--- ---
--- ---
Write a program to input the
names and the marks of the students in the subject.
Calculate and display:-
(i) The subject average marks ( subject average marks = subject total / 50 )
(ii) The highest mark in the subject and the name of the student.
(The maximum marks in the subject are 100)
Calculate and display:-
(i) The subject average marks ( subject average marks = subject total / 50 )
(ii) The highest mark in the subject and the name of the student.
(The maximum marks in the subject are 100)
5. The
annual examination results of 50 students in a class is tabulated as follows.
Roll no. Subject A Subject
B Subject C
……… ……… ………
………
Write a
program to read the data, calculate and display the following:
a)
Average mark obtained by each student.
b) Print
the roll number and average marks of the students whose average mark is above 80.
c) Print
the roll number and average marks of the students whose average mark is below
40.
6. Write a
program to perform binary search on a list of integers given below, to search
for an element input by the user, if it is found display the element along with
its position, otherwise display the message “Search element not found”
5,7,9,11,15,20,30,45,89,97
7. Write a
program to store 6 elements in an array P, and 4 elements in an array Q and
produce a third array R, containing all the elements of array P and Q. Display
the resultant array.
Example:
P[] Q[] R[]
4 19 4
6 23 6
1 7 1
2 8 2
3 3
10 10
19
23
7
8
- Write a program
to input and store the weight of ten people. Sort and display them in
descending order using the selection sort technique.
- Write a program
to accept the names of 10 cities in a single dimension string array and
their STD (Subscriber Trunk Dialing) codes in another single dimension
integer array. Search for a name of a city input by the user in the list.
If found, display “Search Successful” and print the name of the city along
with its STD code, or else display the message “Search Unsuccessful. No
such city in the list”.
- Write a program
to input 10 integer elements in an array and sort them in descending order
using bubble sort technique.
11.
Write a program to accept the year of graduation from school as an
integer value from the user. Using the Binary Search technique on the sorted
array of integers given below, output the message “Record exists” if the value
input is located in the array. If not, output the message “Record does not
exist”.
{1982,
1987, 1993, 1996, 1999, 2003, 2006, 2007, 2009, 2010}
- Write a program
to input twenty names in an array. Arrange these names in descending order
of alphabets , using the bubble sort technique
- Write a program
to input integer elements into an array of size 20 and perform the
following operations :
i) Display largest number from
the array
ii) Display smallest number from
the array
iii) Display sum of all the
elements of the array
- Write a program
to input forty words in an array. Arrange these words in descending order
of alphabets, using selection sort technique. Print the sorted array.
Programs on Strings
1. Write a
program to accept a String from the user and display the longest word in the
String. e.g.,
input: I read in class ten. Output: The longest word is class.
2. Write a java program to input a string and print
frequency of each character of the
string.
Example Input
: COMPUTER APPLICATION
OUTPUT
occurs 1 times
A
occurs 2 times
C
occurs 2 times
E
occurs 1 times
I
occurs 2 times
L
occurs 1 times
M
occurs 1 times
N
occurs 1 times
O
occurs 2 times
P
occurs 3 times
R
occurs 1 times
T
occurs 2 times
3. String Programs [8+7]
(a)
A class 'sortstring' contains an array 'Msg' as follows:
String Msg[]={"Fortune","favours","brave","the"};
Write a code for the class 'sort string' which will sort the individual words and display the output as
Fortune
brave
favours
the
(b) Write a program, which will read a text and count the occurrences of the word "the". For e.g. if the input is "The cat jumped over the fence", the output should be 2.
String Msg[]={"Fortune","favours","brave","the"};
Write a code for the class 'sort string' which will sort the individual words and display the output as
Fortune
brave
favours
the
(b) Write a program, which will read a text and count the occurrences of the word "the". For e.g. if the input is "The cat jumped over the fence", the output should be 2.
4. Write a
program to input any given string to calculate the total number of characters
and vowels present in the string and also reverse the string :-
Example : INPUT
Enter String : SNOWY
OUTPUT
Total number of characters : 05
Number of Vowels : 01
Reverse string : YWONS
Enter String : SNOWY
OUTPUT
Total number of characters : 05
Number of Vowels : 01
Reverse string : YWONS
5. Write a
program using a method Palin( ), to check whether a string is a Palindrome or
not. A Palindrome is a string that reads the same from left to right and vice
versa.
E.g. MADAM, ARORA, ABBA, etc.
E.g. MADAM, ARORA, ABBA, etc.
- Write a program to input a string
and print out the text with the uppercase and lowercase letters reversed,
but all other characters should remain the same as before.
Example: INPUT:
WelComE TO School
OUTPUT:
wELcOMe to sCHOOL
- Write a program
to input a sentence and print the number of characters found in the
longest word of the given sentence.
For
example is S = “India is my country” then the output should be 7.
- Write a program
to input a string in uppercase and print the frequency of each character.
Example:
INPUT: COMPUTER HARDWARE
OUTPUT:
CHARACTERS FREQUENCY
A 2
C 1
D 1
E 2
H 1
M 1
O 1
P 1
R 3
T 1
U 1
W 1
- Write a program
to accept a word and convert it into lowercase if it is in uppercase, and
display the new word by replacing only the vowels with the character following it.
Sample Input : computer
Sample Output : cpmpvtfr
- Write a program
to accept a string. Convert the string to uppercase. Count and output the
number of double letter sequences that exist in the string.
Sample input: SHE WAS FEEDING THE
LITTLE RABBIT WITH AN APPLE
Sample output: 4
- Write a program
that encodes a word in Piglatin. To translate word into Piglatin word,
convert the word into uppercase and then place the first vowel of the
original word as the start of the new word along with the remaining
alphabets. The alphabets present before the vowel being shifted towards
the end followed by “AY”.
Sample Input(1): London Sample
Output(1): ONDONLAY
Sample Input(2): Olympics Sample
Output(2): OLYMPICSAY
- Write a program
to assign a full path and file name as given below. Using library
functions, extract and output the file path, file name and file extension
separately as shown.
Input C:\Users\adm in\Pictures\flower.jpg
Output Path:
C:\Users\admin\Pictures\
File name: flower
Extension: jpg
- Design a class
to overload a function check() as follows:
i) void check(String str, char
ch) – to find and print the frequency of a character in a string.
Example :
Input Output
Str= “success” number of s present is=3
ch= ‘s’
ii) void check (String s1) – to
display only the vowels from string s1 , after converting it to lower case.
Example :
Input:
S1= “computer” output: o u e
Programs on Function Overloading
1. Write a
program to calculate the area and the perimeter of a rectangle and square
having the method display (int, int) and display(int) using overloading
technique.
- Using the
concept of function overloading WAP to find
i)
Sum of 2 integers,
ii)
Product of 2 Float values
iii)
Reverse a number.
- Write a program to using function called area() to output
the area of circle (p*r2),
where p=3.14
(
a ) square (side * side )
(
b ) rectangle (length * breadth )
Display
the menu to output the area as per User’s choice.
- Using the
concept of 'function overloading' write a class with functions 'fact(int)'
and ‘fact(int,int)’ which will calculate the value of n!/r!(n-r)! where n
and r are given by the user.[7]
- Write a class with the name volume using function overloading that computers
the volume of a cube, a sphere and a cuboid.
Formula: volume of a cube (vc) = s * s * s
volume of a sphere (vs) = 4/3 * pi * r * r *r (where pi = 3.14 or
22/7)
Volume of a cuboid (vcd) = l * b * h
- Write a class to
overload a function num_calc() as follows:
i) void num_calc(int num, char
ch) with one integer argument and one character argument, computes the square
of integer argument if choice ch is ‘s’ otherwise finds its cube.
ii) void num_calc(int a, int b,
char ch) with two integer arguments and one character argument. It computes the
product of integer arguments if ch is ‘p’ else adds the integers.
iii) void num_calc(String s1,
String s2) with two string arguments, which prints whether the strings are
equal or not.
- Design a class
to overload a function compare ( ) as follows:
(a) void compare (int, int) – to
compare two integer values and print the greater of the two integers.
(b) void compare (char, char) –
to compare the numeric value of two character and print the character with
higher numeric value
(c) void compare (String, String)
– to compare the length of the two strings and print the longer of the two.
- Design a class
to overload a function polygon() as follows:
a) void polygon(int n, char ch) –
with one integer argument and one character type argument that draws a filled
square of side n using the character stored in ch
b) void polygon(int x, int y) –
with two integer arguments that draws a filled rectangle of length x and
breadth y, usign the symbol ‘@’
c) void polygon() – with no
arguments that draws a filled triangle shown below.
Example:
i) Input value of n = 2, ch =
‘O’.
Output:
OO
OO
ii) Input value of n=2, y=5.
Output:
@@@@@
@@@@@
iii) Output:
*
**
***
- 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/a2 + 4/a5
+ 7/a8 + 10/a11 .....to n terms
10. Design a class to
overload a function area( ) as follows:
double area(double a, double b, double c)
with three double arguments, returns the area of a scalene triangle using the
formula: area =
where s =
double area(int a, int b, int height) with
three integer arguments, returns the area of a trapezium using the formula:
area =
double area(double diagonal1, double
diagonal2) with two double arguments, returns the area of a rhombus using the
formula: area =
- Design a class to overload a function
Joystring() as follows :
(i)void Joystring(String s, char ch1, char
ch2) with one string and two character arguments that replaces the character
argument ch1 with the character argument ch2 in the given string s and points
the new string
Example :
Input value of s = “TECHNALAGY”
ch1 = ‘A’ , ch2 = ‘O’
Output : “TECHNOLOGY”
(ii)void Joystring(String s) with one string
argument that prints the position of the first space and the last space of the
given String s.
Example :First Index : 5
Last Index : 36
(iii)void Joystring(String s1, String s2)
with two string arguments that combines the two strings with a space between
them and prints the resultant string
Example :
Input value of s1 = “COMMON WEALTH”
s2 = “GAMES”
Output : “COMMON WEALTH GAMES”
Programs
on Class and Objects and Constructor
- Define a class Teacher described as below
Data member :
Name:(name)
Address:(address)
Phone Number:(phno)
Highest
Qualification:(qualification)
Subject Specialisation:(subject)
Monthly Salary (msalary)
Income Tax (IT)
Member Method :
1 Default constructor
2 Accept() To Accept the details
of a teacher.
3 Display() To display the
teacher’s detials
4 Increment() To increment the
monthly salary by 5000
5
Compute() To compute the annual income tax as 5% of the annual salary above Rs 150000
Write a main method to create object
of a class and call the above member
method.
- Define a class
'numMagic' with two methods revNum(int n) and digitSum(int n). The method
revNum(int n) reverses the number passed as an argument e.g. if then
number is 346 it returns 643. digitSum(int n) returns the sum of the
digits. [8]
- Define a class salary described as below:-
Data Members : Name, Address, Phone, Subject Specialization,
Monthly Salary, Income Tax.
Member methods : (i)
To accept the details of a teacher including the monthly salary.
(ii) To display the details of the
teacher.
(iii) To compute the annual Income Tax as
5% of the annual salary above Rs.1,75,000/-.
Write
a main method to create object of a class and call the above member method.
- Define a class employee having the following description:-
Data
members/ int
pan to
store personal account number
Instance
Variables String
name to store
name
double
taxincome to store annual
taxable income
double
tax to store
tax that is calculated
Member
Functions:
input(
) Store
the pan number, name, taxableincome
calc(
) Calculate
tax for an employee
display(
) Output
details of an employee
Write
a program to compute the tax according to the given conditions and display the
output as per given format.
Total
Annual Taxable Income Tax
Rate
Upto
Rs. 1,00,000 No
tax
From
1,00,001 to 1,50,000 10%
of the income exceeding Rs. 1,00,000
From
1,50,001 to 2,50,000 Rs.
5,000 + 20% of the income exceeding Rs. 1,50,000
Above
Rs. 2,50,000 Rs.
25,000 + 30% of the income exceeding Rs. 2,50,000
Output:
Pan
Number Name Tax-income Tax
- - - -
- - - -
- Define a class student as described below:
Data
members/instance variables:
name,
age, m1, m2, m3 (marks in three subjects), maximum, average
Member
methods:
(i)
A parameterized constructor to initialize the data members
(ii)
To accept the details of a student
(iii)
To compute the average and maximum out of three marks
(iv)
To display the name, age, marks in three subjects, maximum and average.
Write
a main method to create an object of the class and call the above member
methods.
- Define a class called mobike with the following
description:
Instance
variables/data members:
int
bno – to store the bike’s number
int
phno – to store the phone number of the customer
String
name – to store the name of the customer
int
days – to store the number of days the bike is taken on rent
int
charge – to calculate and store the rental charge
Member
methods:
void
input( ) – to input and store the detail of the customer.
void
compute( ) – to compute the renall charge
The
rent for a mobike is charged on the following basis.
First
five days Rs 500 per day;
Next
five days Rs 400 per day
Rest
of the days Rs 200 per day
void
display ( ) – to display the details in the following format:
Bike
No. PhoneNo. No. of days Charge
- Define a class
called Library with the following description:
Instance variables/data members:
int acc_num – stores the accession number
of the book
String title – stores the title of the book
String author – stores the name of the
author
Member Methods:
void input() – to input and store the
accession number, title and author
void compute() – to accept the number of
days late, calculate and display the fine charged at the rate of Rs. 2 per day
void display() – to display the details in
following format
Accession Number Title Author
---------------- ----- ------
Write a main method to create an
object of the class and call the above member methods.
- Define a class
called FruitJuice with the following description:
Instance variables/data members:
int product_code - stores
the product code number
String flavour - stores
the flavor of the juice. (orangle, apple, etc.)
String pack_type - stores
the type of packaging (tetra-pack, bottle, etc.)
int pack_size - stores
package size (200ml, 400ml, etc.)
int product_price - stores
the price of the product
Member methods:
FruitJuice( ) – default
constructor to initialize integer data members to zero and string data members
to “”
void input( ) - to input
and store the product code, flavor, pack type, pack size and product price
void discount( ) - to
reduce the product price by 10
void display( ) - to
display the product code, flavor, pack type, pack size and product price
- Define a class
named movieMagic with the following description:
Instance variables/data members:
int year – to store the year of
release of a movie
String title – to store the title
of the movie
float rating – to store the
popularity rating of the movie
(minimum rating = 0.0 and maximum
rating = 5.0)
Member methods:
i. movieMagic( )Default constructor to initialize numeric data
members to 0 and String data member to “”.
ii. void accept( )To input and store year, title and rating.
iii. void display( )To display the title of a movie and a message
based on the rating as per the table below.
Rating Message to be displayed
0.0 to 2.0 Flop
2.1 to 3.4 Semi-hit
3.5 to 4.5 Hit
4.6 to 5.0 Super Hit
Write a main method to create an
object of the class and call the above member methods.
- Define a class
Parking Lot with the following description :
Instance variables/data members :
int vno – to store the vehicle
number
int hours – to store the number
of hours the vehicle is parked in the parking lot
double bill – to store the bill amount
Member methods :
void input() – To input and store
vno and hours
void calculate() – To compute the
parking charge at the rate of Rs.3 for the first hour or part thereof, and
Rs.1.50 for each additional hour or part thereof.
void display() – To display the
detail
Write a main method to create an
object of the class and call the above methods
- Define a class
named BookFair with the following description:
Instance variables/Data members:
String Bname – stores the name of the book.
double price – stores the price of the book.
Member Methods:
BookFair() Default constructor to initialize
data members.
void Input() To input and store the name and
the price of the book.
void calculate() To calculate the price after
discount. Discount is calculated based on the following criteria.
Price Discount
Less than or equal to Rs 1000 2%
of price
More than Rs 1000 and less than
or equal to Rs 3000 10% of price
More than Rs 3000 15%
of price
(iv) void display() To display the name and price of the book
after discount.
Write a main method to create an
object of the class and call the above member methods.
- Define a class
Electric Bill with the following specifications:
class : Electric Bill
Instance Variable/ data
member :
String n- to store the name of
the customer
int units – to store the number
of units consumed
double bill- to store the amount
to paid
Member methods:
Void accept() – to accept the
name of the customer and number of units consumed
Void calculate() – to calculate
the bill as per the following tariff :
Number of units Rate per unit
First 100 units Rs.2.00
Next 200 units Rs.3.00
Above 300 units Rs.5.00
A surcharge of 2.5% charged if
the number of units consumed is above 300 units.
Void print()- To print the
details as follows :
Name of the
customer……………………….
Number of units
consumed………………….
Bill amount…………………………………..
Write a main method to create an
object of the class and call the above member methods.
No comments:
Post a Comment