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

c10 Methods

The document outlines a series of programming questions and tasks related to Java methods, classes, and object-oriented programming concepts. It includes questions on method invocation, debugging method prototypes, and defining classes such as Employee, Telephone, and MovieMagic with specified data members and methods. Additionally, it covers topics like method return values, method overloading, and calculating tax and interest based on given conditions.
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)
3 views4 pages

c10 Methods

The document outlines a series of programming questions and tasks related to Java methods, classes, and object-oriented programming concepts. It includes questions on method invocation, debugging method prototypes, and defining classes such as Employee, Telephone, and MovieMagic with specified data members and methods. Additionally, it covers topics like method return values, method overloading, and calculating tax and interest based on given conditions.
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

STD 10 METHODS BASED REVISION FOR CE1

Q1. Give the output:

a) void test1(int n){ for(int x = 1 x <= 1 ;x++)

if( n% * x ==0) System.out.println(x); } when n=12

b) void test 2(int a, int b)

{ if(a > b)

a = a – b;

else

a=b-a } System.out.println(a);} if 4 and 17 are passed to the method.

c) void test 3(char c)

{ System.out.println( (int) c);} if 'm' is passed to c.

Q 2) What are the two ways of invoking methods?

Q 3) When a method returns the value, the entire method call can be assigned to a variable. Do you agree with the statement?

Q 4) When a method is invoked how many values can be returned from the method?

Q 5) Debug the errors and rewrite the following method prototypes:

(a) int sum(x,y);

(b) float product(a,int y);

(c) float operate(int x, float=3.4);

(d) float sum(int x,y);

Q 6) Write down the main method which calls the following method:

int square(int a) {return(a*a);}

Q 7) What happens when a method is passed by reference? Explain.

Q 8) Differentiate between pure and impure methods.

Q 9) What are the advantages of defining a method in a program?

Q 10) What is the role of the keyword void in declaring methods?

Q 11) If a method contains several return statements, how many of them will be executed?

Q 12) Which OOP principle implements method overloading?

Q 13) How are the following data passed to a method? a) Primitive types b) Reference types

Q14 ) Design a prototype for a method MyMethod( ) that accepts a single precision value, a single character and an integer to
return product of all the values input.

Q 15) Define a class Employee having the following description:

Class name: Employee

Data members/Instance variables

int pan : to store personal account number

String name : to store name

double taxincome : to store annual taxable income

double tax : to store tax that is calculated


Member functions:

void input() : Store the pan number, name, taxable income

void cal() : Calculate tax on taxable income.

void display() : Output details of an employee

Calculate tax based on the given conditions and display the output as given

Total Annual Taxable Income Tax Rate

Up to 2,50,000 No tax

From 2,50,001 to ₹5,00,000 10% of the income exceeding 2,50,000

From ₹5,00,001 to 10,00,000 30,000 + 20% of the income exceeding ₹5,00,000

Above ₹10,00,000 50,000 + 30% of the income exceeding ₹10,00,000

Output

Pan Number Name Tax Income Tax

Q16) Define a class Telephone having the following description:

Class name : Telephone

Data members

int prv , pre : to store the previous and present meter readings

int cal : to store the calls made (i.e. pre - prv)

String name : to store name of the consumer

double amt : to store the amount

double total : to store the total amount to be paid

Member functions:

void input () : Stores the previous reading, present reading and name of the consumer

void cal () : Calculates the amount and total amount to be paid

void display () : Displays the name of the consumer, calls made, amount and total

Write a program to compute the monthly bill to be paid according to the given conditions and display the output as per the given
format.

Calls made Rate

Up to 100 calls No charge

For the next 100 calls 90 paise per calls

For the next 200 calls 80 paise per calls

More than 400 calls 70 paise per calls

However, every consumer has to pay 180 per month as monthly rent for availing the service.

Output:

Name of the customer Calls made Amount to be paid

Q 17) Define a class Interest having the following description:

Class name : Interest

Data members :
int p : to store principal (sum)

int r : to store rate

int t : to store time

double interest : to store the interest to be paid

double amt : to store the amount to be paid

Member methods:

void input() : Stores the principal, rate, time

void cal() : Calculates the interest and amount to be paid

void display() : Displays the principal, interest and amount to be paid

Write a program to compute the interest according to the given conditions and display the output.

Time Rate of interest

For 1 year 6.5%

For 2 years 7.5%

For 3 years 8.5%

For 4 years or more 9.5%

(Note: Time to be taken only in whole years)

Q 18) Hero Honda has increased the cost of its vehicles as per the type of the engine using the following criteria:

Type of Engine Rate of increment

2 stroke 10% of the cost

4 stroke 12% of the cost

Write a program by using a class to find the new cost as per the given specifications:

Class name : Honda

Data members/Instance variables

int type : to accept type of engine 2 stroke or 4 stroke

int cost : to accept previous cost

Member Methods:

void gettype() : to accept the type of engine and previous cost

void find() : to find the new cost as per the criteria given above

void printcost() : to print the type and new cost of the vehicle

Q 19) Define a class named MovieMagic with the following description:

Class name : MovieMagic

Instance variables/Data members:

int year : to store the year of release of the 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 members to null

(ii) void accept(): to input and store year, title and rating.

iii) void display(): to display the title of the movie and a message based on the rating as per the table given below

Rating Message to be displayed

0.0 to 2.0 Flop

2.1 to 3.4 Semi-Hit

3.5 to 4.4 Hit

4.5 to 5.0 Super-Hit

Write the main method to create an object of the class and call the above member methods.

Q20.

Write a program in Java to find the roots of a quadratic equation ax²+bx+c=0 with the following specifications:

Class name : Quad

Data Members : float a,b,c,d (a,b,c are the co-efficients & d is the discriminant),

r1 and r2 are the roots of the equation.

Member Methods:

quad(int x,int y,int z) : to initialize a=x,b=y,c=z,d=0

void calculate() : Find d=b2-4ac, find and print the nature and value of root(s)

Condition Nature of the Root(s) Value of Root(s)

d below zero Roots are imaginary ----

d is equal to Roots are unique Root = -b/2a


zero
Roots are real and √(𝑏2 −4𝑎𝑐)
Root1 = -b +
d is above zero distinct 2𝑎

√(𝑏2 −4𝑎𝑐)
Root2 = -b - 2𝑎

Invoke in main ( )

You might also like