Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

ASSIGNMENTS (GR X)

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Assignments (Gr X)

1) Design a class to represent a bank account. Include the following methods:


Data members: i)Name of the depository
ii) Account Number
iii) Type of account
iv) Balance amount in the account
Methods: i) To assign initial values.
ii) To deposit an amount
iii) To withdraw amount after checking balance
iv) To display the name and balance
v) To write proper constructor and functions

2) A cloth showroom has announced the following festival discounts on the purchase of items, based on the
total cost of the items purchased.
Total cost Discount(in %)
Less than Rs. 2000 5%
Rs.2000 to Rs.5000 25%
Rs.5001 to Rs.10000 35%
Above Rs.10000 50%
Write a program to input the total cost and to compute and display the amount to be paid by the customer after
availing the discount.

3) Design a class to overload a function num_calc() as follows:


a) void num calc(int num,char ch) with one integer argument and one character argument , computes the
square of integer arguments of choice ch is ‘s’ otherwise finds the cube.
b) void num calc(int a, int b, char ch) with two integer arguments and one character argument if ch is ‘p’ else
adds the integer.
c) void num calc(String s1, String s2) with two string arguments, which prints whether the strings are equal or
not.

4) Write a program in Java to accept a number from user and check if it is a Kaprekar number or not.
A kaprekar number is a non-negative integer, the representation of whose square in that base can be split
into two parts that add up to the original number.
e.g: 452= 2025
20+25=45
Hence, 45 is the kaprekar number.

5) Write a program to ask the user to enter an integer and print the following pattern:
a) Enter a character and an integer : @ 5

@@@@@
@ @
@ @
@ @
@@@@@

b) Enter an integer: 10

A
AB
ABC
ABCD
ABCDE
ABCDEF
ABCDEFG
ABCDEFGH
ABCDEFGHI
ABCDEFGHIJ
6) 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: The number when read in reverse order is the same as in right order.
e.g : 11, 101, 121, 1331, 010, etc
b) Perfect Number: The number if it is equal to the sum of its factors other than the number itself.
e.g.: 6 = 1 + 2 + 3

7) Write a program to calculate and print the sum of each of the following series.
𝑥2 𝑥4 𝑥6 𝑥 20
i] 1− + + ….
2! 4! 6! 20!

𝑥 𝑥 𝑥 𝑥
ii] 1 − + + ….
4 7 10 19

8) Write a menu driven program to input a number (<=50) from the decimal number system and perform the
following operations using switch case:
i] Convert it into its equivalent Binary number using the function void binary (int)
Ii] Convert it into its equivalent Roman Number using the function void roman (int)

9) Write a Java program to find the largest and smallest element in an array of 5 elements, passed as argument.

10) Write a program to store names and the numbers in an array and allow it to be looked up. The user is given
a name of commands:
A = Add a new number
F = Find the number
Q = Quit
The ‘A’ command prompts the user to enter a name and a number which are then stored in the programs
database.
The ‘F’ command prompts the user to enter a name. the program then displays all matching name in the
database, along with corresponding phone numbers. It is not necessary to enter the entire name; all names that
begin with the specified characters will be displayed. The ‘Q’ command causes the program to terminate.

11) Write a program to enter a sentence from the keyboard and search for a character in it and print the
locations at which the character is present in the string.
E.g.: Venkatesh is playing with a kite.
Enter the character to be searched : k
Output: Searched character found at location(s) : 4 29

12) Write a program to accept a string from the user and display the following:-
1) Number of vowels and consonants in it.
2) Reverse of the string.
3) All the Uppercase character into lowercase and vice versa.

13) Write a program to input a string (word). Convert it into lowercase letters. Count and print the frequency of
each alphabet present in the string. The output should be given as:
Sample Input: Alphabets
Sample Output:
==========================
Alphabet Frequency
==========================
a 2
b 1
e 1
h 1
l 1
p 1
s 1
t 1
14) Write a program to input a word from the user and remove the consecutive repeated characters by replacing
the sequence of repeated characters by its single occurrence.
Example:
INPUT – Jaaavvvvvvvvaaaaaaaaaaa
OUTPUT – Java
INPUT – Heeeiiiissggoiinggg
OUTPUT – Heisgoing

15) A bank intends to design a program to display the denomination of an input amount, up to 5 digits. The
available denomination with the bank are of rupees 1000 , 500 , 100 , 50 , 20 , 10 , 5 , 2 , and 1.
Design a program to accept the amount from the user and display the break-up in descending order of
denomination. (i.e. preference should be given to the highest denomination available) along with the total
number of notes. [Note: Only the denomination used, should be displayed].
Example:
INPUT: 14788
OUTPUT:
DENOMINATIONS:
1000 x 14 = 14000
500 x 1 = 500
100 x 2 = 200
50 x 1 = 50
20 x 1 = 20
10 x 1 = 10
5 x 1 = 5
2 x 1 = 2
1 x 1 = 1
————————————–
TOTAL = 14788
————————————–
Total Number of Notes = 23

16) Write a program to find the shortest and the longest word in a sentence and print them along with their
length.
Sample Input: I am learning Java
Sample Output:
Shortest word = I
Length = 1
Longest word = learning
Length = 8

17) Write a program to generate Armstrong numbers from 1 till 500 and store them as a one-dim array print the
formed array.

18) Hamming distance between two number can be observed by counting number of places bits are different in
the binary representation of the number .
For Example :
Enter 2 number
35 45
100011 101101
Hamming distance is 3

19) Write a program to input and store integer elements in a double dimensional array of size 4×4 and find the
sum of all the elements.

7345

5461

6942

3275
Sum of all the elements: 73

20) Write a program to input a matrix of integers of order 3 x 5

Arrange each row in increasing order of integer numbers:

E.g:

Input: 6 9 8 -1 3

9 0 8 50 20

13 1 -3 7 6

Output:-1 3 6 8 9

0 8 9 20 50

-3 1 6 7 13

You might also like