c10 Methods
c10 Methods
{ if(a > b)
a = a – b;
else
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 6) Write down the main method which calls the following method:
Q 11) If a method contains several return statements, how many of them will be executed?
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.
Calculate tax based on the given conditions and display the output as given
Up to 2,50,000 No tax
Output
Data members
int prv , pre : to store the previous and present meter readings
Member functions:
void input () : Stores the previous reading, present reading and name of the consumer
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.
However, every consumer has to pay 180 per month as monthly rent for availing the service.
Output:
Data members :
int p : to store principal (sum)
Member methods:
Write a program to compute the interest according to the given conditions and display the output.
Q 18) Hero Honda has increased the cost of its vehicles as per the type of the engine using the following criteria:
Write a program by using a class to find the new cost as per the given specifications:
Member Methods:
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
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
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:
Data Members : float a,b,c,d (a,b,c are the co-efficients & d is the discriminant),
Member Methods:
void calculate() : Find d=b2-4ac, find and print the nature and value of root(s)
√(𝑏2 −4𝑎𝑐)
Root2 = -b - 2𝑎
Invoke in main ( )