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

Java Assignment Sheet 1

The document outlines a Java assignment consisting of ten programming tasks. These tasks include implementing binary search, creating a Student class, calculating discounts for a travel company, checking for prime and automorphic numbers, designing a ShowRoom class, function overloading, generating Unicode letters, sorting an array, checking for Pronic numbers, and capitalizing the first letter of each word in a string. Each task provides specific requirements and examples for implementation.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Java Assignment Sheet 1

The document outlines a Java assignment consisting of ten programming tasks. These tasks include implementing binary search, creating a Student class, calculating discounts for a travel company, checking for prime and automorphic numbers, designing a ShowRoom class, function overloading, generating Unicode letters, sorting an array, checking for Pronic numbers, and capitalizing the first letter of each word in a string. Each task provides specific requirements and examples for implementation.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Java Assignment Sheet 1

1. 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
2. Define a class Student as given below:
Data members/instance variables:
name, age, m1, m2, m3 (marks in 3 subjects), maximum, average
Member methods:
a) A parameterized constructor to initialize the data members.
b) To accept the details of a student.
c) To compute the average and the maximum out of three marks.
d) To display the name, age, marks in three subjects, maximum and average.
Write a main method to create an object of a class and call the above member
methods.
3. Shasha Travels Pvt. Ltd. gives the following discount to its customers:
Ticket Amount Discount
Above Rs. 70000 18%
Rs. 55001 to Rs. 70000 16%
Rs. 35001 to Rs. 55000 12%
Rs. 25001 to Rs. 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:

Sl. No. Name Ticket Charges Discount Net Amount

(Assume that there are 15 customers, first customer is given the serial no (SI.
No.) 1, next customer 2 …….. and so on)
4. Write a menu driven program to accept a number from the user and check
whether it is a Prime number or an Automorphic number.
(a) Prime number: (A number is said to be prime, if it is only divisible by 1 and
itself)
Example: 3,5,7,11
(b) Automorphic number: (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 two digits.
5. Design a class name ShowRoom with the following description:

Instance variables / Data members:


String name — To store the name of the customer
long mobno — To store the mobile number of the customer
double cost — To store the cost of the items purchased
double dis — To store the discount amount
double amount — To store the amount to be paid after discount

Member methods:
ShowRoom() — default constructor to initialize data members
void input() — To input customer name, mobile number, cost
void calculate() — To calculate discount on the cost of purchased items, based on
following criteria

Cost Discount (in percentage)


Less than or equal to ₹10000 5%
More than ₹10000 and less than or equal to ₹20000 10%
More than ₹20000 and less than or equal to ₹35000 15%
More than ₹35000 20%

void display () — To display customer name, mobile number, amount to be paid after
discount.

Write a main method to create an object of the class and call the above member
methods.
6. Design a class to overload a function series( ) as follows:
(a) void series (int x, int n) – To display the sum of the series given below:
x1 + x2 + x3 + .......... xn terms
(b) void series (int p) – To display the following series:
0, 7, 26, 63 .......... p terms
(c) void series () – To display the sum of the series given below:
1/2 + 1/3 + 1/4 + .......... 1/10

7. Using the switch-case statement, write a menu driven program to do the


following:

(a) To generate and print Letters from A to Z and their Unicode

Letters Unicode
A 65
B 66
. .
Z 90

(b) Display the following pattern using iteration (looping) statement:

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

8. Write a program to input 15 integer elements in an array and sort them in


ascending order using the bubble sort technique.
9. Write a program to input a number and check and print whether it is a Pronic
number or not. (Pronic number is the number which is the product of two consecutive
integers)
Examples:
12 = 3 x 4
20 = 4 x 5
42 = 6 x 7
10. Write a program in Java to accept a string in lower case and change the first
letter of every word to upper case. Display the new string.
Sample input: we are in cyber world
Sample output: We Are In Cyber World

You might also like