0% found this document useful (0 votes)
4 views4 pages

Assignment on methods 2 2

The document outlines a programming assignment consisting of six questions, each requiring the design of specific methods and classes in Java. Tasks include calculating rental charges for motorbikes, checking for Nest and Lead numbers, validating ISBN numbers, and creating overloaded methods for summation and pattern display. Additionally, it involves implementing a menu-driven program to identify Trunk and Xylem numbers based on user input.

Uploaded by

amruthabs125
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views4 pages

Assignment on methods 2 2

The document outlines a programming assignment consisting of six questions, each requiring the design of specific methods and classes in Java. Tasks include calculating rental charges for motorbikes, checking for Nest and Lead numbers, validating ISBN numbers, and creating overloaded methods for summation and pattern display. Additionally, it involves implementing a menu-driven program to identify Trunk and Xylem numbers based on user input.

Uploaded by

amruthabs125
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Assignment

Question 1
An automobile company provides motorbike on rent. Design a class with a user-defined
method motorbike(), which calculates the rental charges to be paid by the customer.
The description of the method is as follows:
public static void motorbike(String name, long mob, int days) – where ‘name’ stores
the name of the customer, ‘mob’ stores the mobile number and ‘days’ stores the
number of days the motorbike is taken on rent.
Calculate the rental charges to be paid by the customer based on the
following criteria:
Days Rate per day
First five days ₹500 per day
Next five days ₹400 per day
Next four days ₹200 per day
Above 14 days ₹100 per day
Display all the details in the following format.
Name Mobile No. No. of days Charge
---------- ----------- ---------- -------
Call the user-defined method from main().
Question 2
Using the switch statement write a menu driven program:
(i) To call a method nestNum(). The description of the method is as
follows:
public static void nestNum() – Which checks and displays whether a
number input by the user is a Nest number or not.
Nest number - “A number is said to be a ‘Nest Number’ if the number
contains at least one digit which is zero.”
Example 1: Input : 2008
Output : 2008 is a Nest Number
Example 2: Input : 145
Output : 145 is not a Nest Number
1
(ii) To call a method leadNum(). The description of the method is as
follows:
public static void leadNum() : Which checks and displays whether a
number input by the user is a Lead Number or not. ( A number is called
a Lead number if the sum of the even digits is equal to the sum of the
odd digits. )
Example 1: Input : 1452
Sumev= 2+4 =6 , Sumod= 1+5 =6
Output : 1452 is a Lead Number
Example 2: Input : 74615
Sumev= 4+6 =10 , Sumod= 7+1+5 =13
Output : 74615 is not a Lead Number
Question 3
Write a program to design a method isbn(). The description of the method is as
follows.
public static int isbn() : Which returns the sum, and displays if the number input by
the user is a valid ISBN number or not.
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 x digit1 + 2 x digit2 + 3 x digit3 + 4 x digit4 + 5 x digit5 + 6 x digit6
+ 7 x digit7 + 8 x digit8 + 9 x digit9 + 10 x digit10 is divisible by 11.
Example: For an ISBN 1401601499
Sum= 1x1 + 2 x 4 + 3 x 0 + 4 x 1 + 5 x 6 + 6 x 0 + 7 x 1 + 8 x 4 + 9 x 9
+ 10 x 9 = 253 which is divisible by 11.
Write a program to:
(i) Input the ISBN code as a 10-digit integer.
(ii) If the ISBN is not a 10-digit integer, 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.
2
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”.
Question 4
Design a class to overload a method sum() as follows:
(i) public static double sum(): Which returns the sum of the following series
2 – 4 + 6 – 8 + ………. – 20
(ii) public static double sum (int x, int n): Which returns the sum of the following
series with x and n as arguments.
x2 x4 x6 x8
+ + + +…….+ n terms
2 5 8 11
Question 5
Design a class to overload a method pattern() as follows:
(a) public static void pattern(): Which displays the following pattern.
@ * @ * @
@ * @ * @
@ * @ * @
@ * @ * @
(b) public static void pattern( int x , char ch ): Which displays the following
pattern, where x and ch are the arguments.
Input: x = 4, ch = ‘&’
Output:
& & & &
& & &
& &
&
Question 6
Using the switch-case statement write a menu driven program:
(i) To call a method trunkNum(): The description of the method is as
follows:
public static void trunkNum( int x ): Which checks and displays
whether a number input by the user is a Trunk number or not.

3
Trunk number: A number is considered a Trunk number when the
reverse of the number is larger than the accepted number.
Example 1. : Input : 4014
Reverse : 4104
Output : 4014 is a Trunk number
Example 2. : Input : 5213
Reverse : 3125
Output : 5213 is not a Trunk number
(ii) To call a method xylemNum( ): The description of the method is as
follows:
public static void xylemNum( int x ): Which checks and displays
whether a number input by the user is a Xylem number or not.
A number N will be a Xylem number if the sum of its extreme digits
(first and last digits) is equal to the sum of mean digits ( all digits
except first and last digits.)
Example 1: Input : 34236
Extreme : 3 + 6 = 9, Mean: 4 + 2 + 3= 9
Output : 34236 is a Xylem number.
Example 2: Input : 2145
Extreme : 2 + 5 = 7, Mean: 1 + 4 = 5
Output : 2145 is not a Xylem number.
_______________________

You might also like