[go: up one dir, main page]

0% found this document useful (0 votes)
29 views2 pages

Programs 3 - 22 April 24

Uploaded by

rushikesh06rn
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)
29 views2 pages

Programs 3 - 22 April 24

Uploaded by

rushikesh06rn
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/ 2

The Bishop’s Co-Ed School, Undri

Class – X Programs – 3
Chapter 5 : USER-DEFINED METHODS Date – 22.04.24

Execute the program in BlueJ and then write its solution + ddt in your notebooks

PROGRAM 1
/*Page 337 qns 1*/
import java.util.*;
class Overload1
{
int price; //global variable

private void Discount(int d1) //version 1


{ double dis=price*(d1/100.0);
System.out.println("Discount = "+dis);
System.out.println("Amount to be paid = "+(price-dis));
}

private void Discount(int d1, int d2) //version 2


{ double dis=price*(d1/100.0);
System.out.println("First Discount = "+dis);
price -= dis;
dis=price*(d2/100.0);
System.out.println("Second Discount = "+dis);
System.out.println("Amount to be paid = "+(price-dis));
}

private void Discount(int d1, int d2,int d3) //version 3


{ double dis=price*(d1/100.0);
System.out.println("First Discount = "+dis);
price -= dis;
dis=price*(d2/100.0);
System.out.println("Second Discount = "+dis);
price -= dis;
dis=price*(d3/100.0);
System.out.println("Third Discount = "+dis);
System.out.println("Amount to be paid = "+(price-dis));
}

void main()
{
//decaration
Scanner sc=new Scanner(System.in);
int x,y,z;

//input
System.out.println("ENTER THE PRINTED PRICE OF AN ARTICLE");
price=sc.nextInt();
System.out.println("ENTER 3 DISCOUNTS TO CALCULATE SINGLE AND
SUCCESIVE DISCOUNTS");
x=sc.nextInt();
y=sc.nextInt();
z=sc.nextInt();

//function calls
Discount(x);
Discount(x,y);
Discount(x,y,z);
}
}

PROGRAM 2 –
/*Page 340 Qns 18*/
class Overload2
{ static void calculate(int m, char ch)
{ if(ch=='s')
Sopln(m%7==0?m+" is divisible by 7":m+" is NOT divisible by 7");
else
System.out.println(m%10==7?"Last digit is 7":"Last digit is NOT 7");
}
static void calculate(int a, int b, char ch)
{ if(ch=='g')
System.out.println("Greater number = "+Math.max(a,b));
else
System.out.println("Smaller number = "+Math.min(a,b));
}
}

PROGRAM 3 –
/*Page 340 qns 20*/
class Overload3
{ static double series(int n)
{
double sum;
int d;
for(d=1,sum=0.0; d<=n; sum+=1.0/d,d++);
return sum;
}
static double series(int a,int n)
{
double sum;
int num,term;
for(num=term=1,sum=0.0; term<=n; num+=3,term++)
sum+=num/Math.pow(a,num+1);
return sum;
}
}

***************************

You might also like