Computer Applications
Define a class to overload the method perform as follows: double perform (double r, double h) — to calculate and return the value of curved surface area of cone void perform (int r, int c) — Use NESTED FOR LOOP to generate the following format r = 4, c = 5 output 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 void perform (int m, int n, char ch) — to print the quotient of the division of m and n if ch is Q else print the remainder of the division of m and n if ch is R
Answer
import java.util.Scanner;
public class KboatOverloadPerform
{
double perform(double r, double h) {
double l = Math.sqrt((r * r) + (h * h));
double csa = Math.PI * r * l;
return csa;
}
void perform(int r, int c) {
for (int i = 1; i <= r; i++) {
for (int j = 1; j <= c; j++) {
System.out.print(j + " ");
}
System.out.println();
}
}
void perform(int m, int n, char ch) {
if (ch == 'Q') {
int q = m / n;
System.out.println("Quotient: " + q);
} else if (ch == 'R') {
int r = m % n;
System.out.println("Remainder: " + r);
} else {
System.out.println("Invalid Character!");
}
}
public static void main(String[] args) {
KboatOverloadPerform mo = new KboatOverloadPerform();
// Calculating CSA of a cone
double csa = mo.perform(3.0, 4.0);
System.out.println("Curved Surface Area of Cone: " + csa);
// Generating pattern
mo.perform(4, 5);
// Printing quotient or remainder
mo.perform(20, 6, 'Q');
mo.perform(20, 6, 'R');
}
}
Variable Description Table
Program Explanation
Output
Related Questions
Primitive data types are built in data types which are a part of the wrapper classes. These wrapper classes are encapsulated in the java.lang package. Non primitive datatypes like Scanner class are a part of the utility package for which an object needs to be created.
(a) To which package the Character and Boolean classes belong?
(b) Write the statement to access the Scanner class in the program.
DTDC a courier company charges for the courier based on the weight of the parcel. Define a class with the following specifications:
Class name: courier
Member variables:
name – name of the customer
weight – weight of the parcel in kilograms
address – address of the recipient
bill – amount to be paid
type – 'D'- domestic, 'I'- international
Member methods:
void accept ( ) — to accept the details using the methods of the Scanner class only.
void calculate ( ) — to calculate the bill as per the following criteria:
Weight in Kgs Rate per Kg First 5 Kgs Rs.800 Next 5 Kgs Rs.700 Above 10 Kgs Rs.500 An additional amount of Rs.1500 is charged if the type of the courier is I (International)
void print ( ) — To print the details
void main ( ) — to create an object of the class and invoke the methods
Define a class to accept a number from user and check if it is an EvenPal number or not.
(The number is said to be EvenPal number when number is palindrome number (a number is palindrome if it is equal to its reverse) and sum of its digits is an even number.)
Example: 121 – is a palindrome number
Sum of the digits – 1+2+1 = 4 which is an even numberDefine a class to accept values into an integer array of order 4 x 4 and check whether it is a DIAGONAL array or not. An array is DIAGONAL if the sum of the left diagonal elements equals the sum of the right diagonal elements. Print the appropriate message.
Example:
3 4 2 5
2 5 2 3
5 3 2 7
1 3 7 1Sum of the left diagonal element = 3 + 5 + 2 + 1 = 11
Sum of the right diagonal element = 5 + 2 + 3 + 1 = 11