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

Class 10 Computer Project Solve 2022

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Class 10 Computer Project Solve 2022

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 25

1.

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 term

(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

CODE:

Import java.util.*;
public class KboatOverloadSeries
{
void series(int x, int n) {
long sum = 0;
for (int i = 1; i <= n; i++) {
sum += Math.pow(x, i);
}
System.out.println("Sum = " + sum);
}

void series(int p) {
for (int i = 1; i <= p; i++) {
int term = (int)(Math.pow(i, 3) - 1);
System.out.print(term + " ");
}
System.out.println();
}

void series() {
double sum = 0.0;
for (int i = 2; i <= 10; i++) {
sum += 1.0 / i;
}
System.out.println("Sum = " + sum);
}
public static void main ()
{
Scanner sc=new Scanner(System.in);
System.out.println(“Enter numbers”);
int x,n,p;
x=sc.nextInt();
n=sc.nextInt();
p=sc.nextInt();
KboatOverloadSeries ob=new KboatOverloadSeries();
Ob. series(x,n);
Ob. series(p);
Ob. series();
}
}
VARIABLE DESCRIPTION:

Variables Data type Description


i int For looping
s double For calculating sum
x int For inputting a no.
n int For inputting a no.
p int For inputting
t int For doing the 2nd series

2 Design a class to overload a function volume() as follows :


(i) double volume (double R) — with radius (R) as an argument, returns the volume of a sphere using the
formula.
V = 4/3 × 22/7 × R3
(ii) double volume (double H, double R) – with height(H) and radius(R) as the arguments, returns the
volume of a cylinder using the formula.
V = 22/7 × R2 × H
(iii) double volume (double L, double B, double H) – with length(L), breadth(B) and Height(H) as the
arguments, returns the volume of a cuboid using the formula.

CODE:

public class KboatVolume


{
double volume(double r) {
double vol = (4 / 3.0) * (22 / 7.0) * r * r * r;
return vol;
}

double volume(double h, double r) {


double vol = (22 / 7.0) * r * r * h;
return vol;
}

double volume(double l, double b, double h) {


double vol = l * b * h;
return vol;
}

public static void main(String args[]) {


KboatVolume obj = new KboatVolume();
System.out.println("Sphere Volume = " +
obj.volume(6));
System.out.println("Cylinder Volume = " +
obj.volume(5, 3.5));
System.out.println("Cuboid Volume = " +
obj.volume(7.5, 3.5, 2));
}
}

VARIABLE DESCRIPTION:
Variables Data type Description
v double For calculating the volume
r double For radius
h double For height
l double For length
b double For breadth

3 Define a class ElectricBill with the following specifications:

class : ElectricBill

Instance variables / data member:

String n — to store the name of the customer


int units — to store the number of units consumed
double bill — to store the amount to be paid

Member methods:
void accept( ) — to accept the name of the customer and number of units consumed
void calculate( ) — to calculate the bill as per the following tariff:

Number of
Rate per unit
units

First 100 units Rs.2.00

Next 200 units Rs.3.00

Above 300 units Rs.5.00

A surcharge of 2.5% charged if the number of units consumed is above 300 units.

void print( ) — To print the details as follows:


Name of the customer: ………………………
Number of units consumed: ………………………
Bill amount: ………………………

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

CODE:

import java.util.Scanner;

public class ElectricBill


{
private String n;
private int units;
private double bill;

public void accept() {


Scanner in = new Scanner(System.in);
System.out.print("Enter customer name: ");
n = in.nextLine();
System.out.print("Enter units consumed: ");
units = in.nextInt();
}

public void calculate() {


if (units <= 100)
bill = units * 2;
else if (units <= 300)
bill = 200 + (units - 100) * 3;
else {
double amt = 200 + 600 + (units - 300) * 5;
double surcharge = (amt * 2.5) / 100.0;
bill = amt + surcharge;
}
}

public void print() {


System.out.println("Name of the customer\t\t: " + n);
System.out.println("Number of units consumed\t: " + units);
System.out.println("Bill amount\t\t\t: " + bill);
}

public static void main(String args[]) {


ElectricBill obj = new ElectricBill();
obj.accept();
obj.calculate();
obj.print();
}
}

VARIABLE DESCRIPTION:

Variables Data type Description


unit int For inputting no.of units
n String For name of customer
bill double For calculating bill
subcharge double For calculating bill
chargedbill double For calculating

4. Define a class Interest having the following description:


Data Members Purpose

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 functions Purpose

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%

CODE:

import java.util.Scanner;

public class Interest


{
private int p;
private float r;
private int t;
private double interest;
private double amt;

public void input() {


Scanner in = new Scanner(System.in);
System.out.print("Enter principal: ");
p = in.nextInt();
System.out.print("Enter time: ");
t = in.nextInt();
}

public void cal() {


if (t == 1)
r = 6.5f;
else if (t == 2)
r = 7.5f;
else if (t == 3)
r = 8.5f;
else
r = 9.5f;

interest = (p * r * t) / 100.0;
amt = p + interest;
}

public void display() {


System.out.println("Principal: " + p);
System.out.println("Interest: " + interest);
System.out.println("Amount Payable: " + amt);
}

public static void main(String args[]) {


Interest obj = new Interest();
obj.input();
obj.cal();
obj.display();
}
}

VARIABLE DESCRIPTION:

Variables Data type Description


p int For storing principal
r int For storing rate
t int For storing time
i double For calculating interest
pp int For parameterized
constructor
rr int For parameterized
constructor
tt int For parameterized
constructor
pp1 int For parameterized
constructor
rr1 int For parameterized
constructor
tt1 int For parameterized
constructor

5 Define a class named BookFair with the following description:


Instance variables/Data members :
String Bname — stores the name of the book
double price — stores the price of the book Member methods :
(i) BookFair() — Default constructor to initialize data members
(ii) void Input() — To input and store the name and the price of the book.
(iii) void calculate() — To calculate the price after discount. Discount is calculated based on the following
criteria.
Price Discount

Less than or equal to Rs. 1000 2% of price

More than Rs. 1000 and less than or equal to Rs. 3000 10% of price
More than % 3000 15% of price

(iv) void display() — To display the name and price of the book after discount. Write a main method to
create an object of the class and call the above member methods.

CODE:

import java.util.Scanner;

public class BookFair


{
private String bname;
private double price;

public BookFair() {
bname = "";
price = 0.0;
}

public void input() {


Scanner in = new Scanner(System.in);
System.out.print("Enter name of the book: ");
bname = in.nextLine();
System.out.print("Enter price of the book: ");
price = in.nextDouble();
}

public void calculate() {


double disc;
if (price <= 1000)
disc = price * 0.02;
else if (price <= 3000)
disc = price * 0.1;
else
disc = price * 0.15;

price -= disc;
}

public void display() {


System.out.println("Book Name: " + bname);
System.out.println("Price after discount: " + price);
}

public static void main(String args[]) {


BookFair obj = new BookFair();
obj.input();
obj.calculate();
obj.display();
}
}

VARIABLE DESCRIPTION:
Variables Data type Description
bname String For storing book name
price double For storing book price
dis double For calculating discount
net double For calculating net price

6 Write a program to accept a string and print the frequency of vowels, capitals, letters and digits in it.

CODE:

Class Str
{
void countCharacterType(String str)
{
// Declare the variable vowels, consonant, digit
// and special characters
int vowels = 0, consonant = 0, specialChar = 0,
digit = 0;

// str.length() function to count number of


// character in given string.
for (int i = 0; i < str.length(); i++) {

char ch = str.charAt(i);

if ( (ch >= 'a' && ch <= 'z') ||


(ch >= 'A' && ch <= 'Z') ) {

// To handle upper case letters


ch = Character.toLowerCase(ch);

if (ch == 'a' || ch == 'e' || ch == 'i' ||


ch == 'o' || ch == 'u')
vowels++;
else
consonant++;
}
else if (ch >= '0' && ch <= '9')
digit++;
else
specialChar++;
}
cout << "Vowels: " << vowels << endl;
cout << "Consonant: " << consonant << endl;
cout << "Digit: " << digit << endl;
cout << "Special Character: " << specialChar << endl;
}

// Driver function.
public static void main()
{
String str = "geeks for geeks121";
str ob=new str();
ob.countCharacterType(str);
}
}

VARIABLE DESCRIPTION:

Variables Data type Description


st string For storing a string
i int For looping
v int For counting vowels
cl int For counting capital letters
d int For counting digits
l int For storing length of the
string
ch char For checking individual
characters

7 Write a program to accept a string and print whether the string is a palindrome or not

CODE:

import java.util.*;
class PalindromeExample2
{
public static void main(String args[])
{
String original, reverse = ""; // Objects of String class
Scanner in = new Scanner(System.in);
System.out.println("Enter a string/number to check if it is a palindrome");
original = in.nextLine();
int length = original.length();
for ( int i = length - 1; i >= 0; i-- )
reverse = reverse + original.charAt(i);
if (original.equals(reverse))
System.out.println("Entered string/number is a palindrome.");
else
System.out.println("Entered string/number isn't a palindrome.");
}
}

VARIABLE DESCRIPTION:

Variables Data type Description


st string For storing the string
rev string For storing the reversed
string
i int For looping
l int For storing length of the
string
ch char For checking individual
characters

8 Write a program to accept name and total marks of N number of students in two single subscript
arrays name[] and totalmarks[].
Calculate and print:
A. The average of the total marks obtained by N number of students. [average = (sum of
total marks of all the students)/N
B. Deviation of each student’s tortal marks with the average. [deviation=total
marks of a student-average]

CODE:

import java.util.Scanner;

public class KboatSDAMarks


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter number of students: ");
int n = in.nextInt();

String name[] = new String[n];


int totalmarks[] = new int[n];
int grandTotal = 0;

for (int i = 0; i < n; i++) {


in.nextLine();
System.out.print("Enter name of student " + (i+1) + ": ");
name[i] = in.nextLine();
System.out.print("Enter total marks of student " + (i+1) + ": ");
totalmarks[i] = in.nextInt();
grandTotal += totalmarks[i];
}

double avg = grandTotal / (double)n;


System.out.println("Average = " + avg);

for (int i = 0; i < n; i++) {


System.out.println("Deviation for " + name[i] + " = "
+ (totalmarks[i] - avg));
}
}
}

VARIABLE DESCRIPTION:

Variables Data type Description


n int For storing the no.of
students
i int Loop variable
s int For storing sum
d double For storing deviation
avg double For storing average
name[] String For storing names
totalmarks[] int For storing total marks

9 Write a program to accept a list of n names. Sort the names in alphabetic order using Bubble Sort
Technique and print the names in sorted order in the following way. [Use compareTo()]
Serial Number Name 1 -------
2 -------
3 -------

CODE:

import java.util.*;

class GFG {
public static void main()
{
// storing input in variable
Scanner sc=new Scanner(System.in);
System.out.println(“Enter number of names”);
int n=sc.nextInt();

// create string array called names


String names[]= new String[n];
System.out.println(“Enter names”);
for (int i = 0; i < n; i++)
{
names[]=sc.next();
}
String temp;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {

// to compare one string with other strings


if (names[i].compareTo(names[j]) > 0) {
// swapping
temp = names[i];
names[i] = names[j];
names[j] = temp;
}
}
}

// print output array


System.out.println(
"The names in alphabetical order are: ");
for (int i = 0; i < n; i++) {
System.out.println(names[i]);
}
}
}
VARIABLE DESCRIPTION:

Variables Data type Description


n int For storing the no.of names
i int Loop variable
j int Loop variable
t String For swapping
a[] String For storing names of n
students

10 Write a menu driven program to accept a number and check whether it is


(a) Palprime number – [a number is a palindrome and a prime number Eg. 101]
(b) Armstrong number – [Sum of the cubes of the digits = number Eg. 153]

CODE:

import java.util.Scanner;

public class KboatPalinOrPerfect


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("1. Palindrome number");
System.out.println("2. Armstrong number");
System.out.print("Enter your choice: ");
int choice = in.nextInt();
System.out.print("Enter number: ");
int num = in.nextInt();

switch (choice) {
case 1:
int copyNum = num;
int revNum = 0;

while(copyNum != 0) {
int digit = copyNum % 10;
copyNum /= 10;
revNum = revNum * 10 + digit;
}

if (revNum == num)
System.out.println(num + " is palindrome");
else
System.out.println(num + " is not palindrome");
break;

case 2:
int result = 0;
int orig = number;
while(number != 0){
int remainder = number%10;
result = result + remainder*remainder*remainder;
number = number/10;
}
if (result == orig)
System.out.println(num + " is a Armstrong number");
else
System.out.println(num + " is not a Armstrong number");
break;

default:
System.out.println("Incorrect Choice");
break;
}
}
}

VARIABLE DESCRIPTION:

Variables Data type Description


num int For storing the no.
choice int Switch case
result int To calculate result
orig int For storing the no.
copyNum int To copy the no.
revNum int To reverse the no.
number int For storing no.
remainder int For calculating remainder

11 Design a class RailwayTicket with the following description: Instance


variables/data members:
String name : to store the name of the customer.
String coach : to store the type of coach customer wants to travel. long mobno : to
store customer’s mobile number.
int amt : to store basic amount of ticket.
int totalamt : to store the amount to be paid after updating the original amount.
Methods:
void accept() : to take input for name, coach, mobile number and amount. void update() : to
update the amount as per the coach selected. Extra amount to be added in the amount as follows:
Type of coaches Amount
First_AC 700
Second_AC 500
Third_AC 250
sleeper None
void display() : To display all details of a customer such as name, coach, total amount and
mobile number.

Write a main() method to create an object of the class and call the above methods.

CODE:

import java.util.Scanner;

public class RailwayTicket


{
private String name;
private String coach;
private long mobno;
private int amt;
private int totalamt;

private void accept() {


Scanner in = new Scanner(System.in);
System.out.print("Enter name: ");
name = in.nextLine();
System.out.print("Enter coach: ");
coach = in.nextLine();
System.out.print("Enter mobile no: ");
mobno = in.nextLong();
System.out.print("Enter amount: ");
amt = in.nextInt();
}

private void update() {


if(coach.equalsIgnoreCase("First_AC"))
totalamt = amt + 700;
else if(coach.equalsIgnoreCase("Second_AC"))
totalamt = amt + 500;
else if(coach.equalsIgnoreCase("Third_AC"))
totalamt = amt + 250;
else if(coach.equalsIgnoreCase("Sleeper"))
totalamt = amt;
}

private void display() {


System.out.println("Name: " + name);
System.out.println("Coach: " + coach);
System.out.println("Total Amount: " + totalamt);
System.out.println("Mobile number: " + mobno);
}

public static void main(String args[]) {


RailwayTicket obj = new RailwayTicket();
obj.accept();
obj.update();
obj.display();
}
}

VARIABLE DESCRIPTION:

Variables Data type Description


name String For storing names
coach String To store type of coach
mobno long To store mobile no.
amt int To calculate amount
totalamt int To calculate total amount

12 Define a class ParkingLot with the following description: Instance


variables/data members:
int vno – To store the vehicle number
int hours – To store the number of hours the vehicle is parked in
the parking lot
double bill – To store the bill amount Member
methods:
void input() – To input and store vno and hours
void calculate() – To compute the parking charge at the rate of Rs.3 for
the first hour or part thereof, and Rs.1.50 for each additional hour or
part thereof.
void display() – To display the detail
Write a main method to create an object of the class and call the above methods

CODE:

import java.util.Scanner;

public class ParkingLot


{
private int vno;
private int hours;
private double bill;

public void input() {


Scanner in = new Scanner(System.in);
System.out.print("Enter vehicle number: ");
vno = in.nextInt();
System.out.print("Enter hours: ");
hours = in.nextInt();
}

public void calculate() {


if (hours <= 1)
bill = 3;
else
bill = 3 + (hours - 1) * 1.5;
}

public void display() {


System.out.println("Vehicle number: " + vno);
System.out.println("Hours: " + hours);
System.out.println("Bill: " + bill);
}

public static void main(String args[]) {


ParkingLot obj = new ParkingLot();
obj.input();
obj.calculate();
obj.display();
}
}

VARIABLE DESCRIPTION:

Variables Data type Description


hours int To store no.of hours
bill double To calculate bill
vno int To store vehicle no.
13 Write a FUNCTION sumprime(int) to input a number and display the digits which are prime. Also
print the sum of the prime digits

E.g
Input : - 23487
Output: - Prime digits are : 2 3 7
Sum : 12

CODE:
import java.util.*;

public class Brainly{

static void sumprime(int n){

int sum=0,d;

System.out.print("The prime digits are as follows - ");

while(n!=0){

d=n%10;

if(d==2 || d==3 || d==5 || d==7){

System.out.print(d+" ");

sum+=d;

n/=10;

System.out.println("\nThe sum of the prime digits is: "+sum);

public static void main(String args[]){

System.out.print("Enter a number: ");

sumprime((new Scanner(System.in)).nextInt());

}
VARIABLE DESCRIPTION:

Variables Data type Description


n int To store a no.
sum int To store sum
d int To extract digit
n1 int For inputting the no.
14 Design a class to overload a function num_calc( ) as follows:
void num_calc( int num, char ch) with one integer argument and one character argument, computes the
square of integer argument if choice ch is ‘s’ otherwise finds its cube.
void num_calc( int a, int b, char ch ) with two integer argument and one character argument. It computes
the product of integer arguments if ch is ‘p’ else adds the integers.
void num_calc( Sting s1, String s2) with two string arguments, which prints whether the strings
are equal or not. [use equalsIgnoreCase()]
[No need to write main()]

CODE:

class Overload

void num_calc(int num, char ch)

if(ch=='s')

num*=num;

else

num*=num*num;

System.out.println("Result is: "+num);

void num_calc(int a, int b, char ch)

if(ch=='p')

a*=b;

else

a+=b;

System.out.println("Result is: "+a);

void num_calc(int s1, int s2)

if(s1==s2)
System.out.println("Numbers are equal.");

else

System.out.println("Numbers are not equal.");

public static void main(String args[])

Overload obj=new Overload();

obj.num_calc(5,'s'); // computes square of 5.

obj.num_calc(5,10,'p'); //find the product of 5 and 10.

obj.num_calc(5,10); //prints that both are not equal.

VARIABLE DESCRIPTION:

Variables Data type Description


a,b int To store a no.
sum int To calculate sum
cube int To calculate cube
product int To calculate product
s1,s2 String To store a string
num int To store a no.
ch char To extract character

15 Write a class program 'series' with a function by using following specifications-


int fact(int) : The function calculates and returns factorial of a number.

Apply this function to find the sum of the following series in the main-function. (Note : n! = 1 x 2 x
3 x................................................x n )
S = 1 + 1 + 1 +..........................+1
2! 4! 6! 10!

CODE:

import java.util.*;

class GFG {

// Utility function to find


static int factorial(int n)
{
int res = 1;
for (int i = 2; i <= n; i++)
res *= i;
return res;
}

// A Simple Function to return value


static double sum(int n)
{
double sum = 0;
for (int i = 2; i <= n; i=i+2)
sum += 1.0/factorial(i);
return sum;
}

// Driver program
public static void main (String[] args)
{
int n = 5;
System.out.println(sum(n));
}
}

VARIABLE DESCRIPTION:

Variables Data type Description


n int To store a no.
i int Loop variable
f int For calculating factorial
s int For calculating sum of
factorials

16 Define a Class str1 in which there are 2 methods


1. cap() to input a word and display it in uppercase. [Use toUpperCase()]
2. small() to input a word and display it in lowercase [Use toLowerCase()]
Define main class to execute two functions USING SWITCH CASE.

CODE:

import java.util.*;
public class str_cap
{
Scanner sc=new Scanner(System.in);
void cap()
{
System.out.println("Enter a word");
String w=sc.next();
System.out.println(w.toUpperCase());
}
void small()
{
System.out.println("Enter a word");
String w=sc.next();
System.out.println(w.toLowerCase());
}

public static void main()


{
Scanner sc1=new Scanner(System.in);
str_cap ob=new str_cap();
int ch;
System.out.println("Enter 1 for display word in uppercase or 2 for display word in lowerrcase");
System.out.println("Enter your choice");
ch=sc1.nextInt();
switch(ch)
{
case 1:
ob.cap();
break;
case 2:
ob.cap();
break;
default:
System.out.println("Wrong choice");
}
}
}

VARIABLE DESCRIPTION:

Variables Data type Description


w String To store a word
ch int Switch case

17. Design a class to overload a function polygon() as follows:

1. void polygon(int n, char ch) — with one integer and one character type argument to draw a filled square of
side n using the character stored in ch.
2. void polygon(int x, int y) — with two integer arguments that draws a filled rectangle of length x and
breadth y, using the symbol '@'.
3. void polygon() — with no argument that draws a filled triangle shown below:

Example:

1. Input value of n=2, ch = 'O'


Output:
OO
OO
2. Input value of x = 2, y = 5
Output:
@@@@@
@@@@@
3. Output:
*
**
***

CODE:
public class KboatPolygon
{
public void polygon(int n, char ch) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
System.out.print(ch);
}
System.out.println();
}
}

public void polygon(int x, int y) {


for (int i = 1; i <= x; i++) {
for (int j = 1; j <= y; j++) {
System.out.print('@');
}
System.out.println();
}
}

public void polygon() {


for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= i; j++) {
System.out.print('*');
}
System.out.println();
}
}

public static void main(String args[]) {


KboatPolygon obj = new KboatPolygon();
obj.polygon(2, 'o');
System.out.println();
obj.polygon(2, 5);
System.out.println();
obj.polygon();
}
}

VARIABLE DESCRIPTION:

Variables Data type Description


n int To store a no.
ch char For storing character
i int loop variable
j int loop variable
x int To store a no.
y int To store a no.

18 Write a program to accept a number and check and display whether it is a spy number or not.
(A number is spy if the sum of its digits equals the product of its digits.)
Example : consider the number 1124,
Sum of the digits = 1 + 1 + 2 + 4 = 8
Product of the digits = 1 × 1 x 2 x 4 = 8
CODE:

import java.util.Scanner;

public class KboatSpyNumber


{
public void spyNumCheck() {

Scanner in = new Scanner(System.in);

System.out.print("Enter Number: ");


int num = in.nextInt();

int digit, sum = 0;


int orgNum = num;
int prod = 1;

while (num > 0) {


digit = num % 10;

sum += digit;
prod *= digit;
num /= 10;
}

if (sum == prod)
System.out.println(orgNum + " is Spy Number");
else
System.out.println(orgNum + " is not Spy Number");

}
}

VARIABLE DESCRIPTION:

Variables Data type Description


num int To store a no.
digit int For extracting digits
orgNum int For storing the no.
prod int To calculate product
sum int To calculate sum

19 Write a FUNCTION prime(int) to input a number and display the digits which are prime. Also print the
sum of the prime digits
E.g
Input : - 23489
Output: - Prime digits are : 2 3 9

CODE:
import java.util.*;

public class Brainly{

static void sumprime(int n){


int sum=0,d;

System.out.print("The prime digits are as follows - ");

while(n!=0){

d=n%10;

if(d==2 || d==3 || d==5 || d==7)

System.out.print(d+" ");

n/=10;

System.out.println("\nThe sum of the prime digits is: "+sum);

public static void main(String args[]){

System.out.print("Enter a number: ");

sumprime((new Scanner(System.in)).nextInt());

}
VARIABLE DESCRIPTION:

Variables Data type Description


n int To store the number
sum Int For calculating sum
d int For digit extraction

20 Write a program in java to overload the following function findarea(). The details of the class is given below:
class : Area
member function:
void findarea(int a,int b)-to calculate the area of a rectangle
void findarea(int a)- to calculate the area of a square
void findarea(double r)- to calculate the area of a circle

CODE:

public class area


{
void findarea(int a,int b)
{
System.out.println(a*b);
}
void findarea(int a)
{
System.out.println(a*a);
}
void findarea(double r)
{
System.out.println(3.14*r*r);

}
public static void main()
{
area ob=new area();
ob.findarea(10,12);
ob.findarea(9);
ob.findarea(5.6);
}
}

VARIABLE DESCRIPTION:

Variables Data type Description


a int To store side of a square
and length of a rectangle
b int To store breadth of a
rectangle
r double To store radius of a circle

You might also like