Professional Documents
Culture Documents
Adobe Scan Jan 05, 2024
Adobe Scan Jan 05, 2024
[10]
Design a class NumDude to check if a given number is a
Dudeney number or not. (A Dudency number is a positive
integer that is a perfect cube, such that the sum of its digits
isequal to the cube root of the number.)
Example: 5832 = (5 +8 +3 +2) = (18 - 5832
Some of the members of the class are given below:
Class name :Unique
Data memberlinstance variable:
num
: to store a positive integer
number
Methods/Member
NumDude( )
functions:
: default constructor to
the data member with initialise
initialvalue legal
SECTION B
Answer 6.
import java.util.Scanner;
publicclass NumDude
intnum;
public NumDude()
num-0;
public void input()
if (x==0)
return 0;
else
return x%10 +sumDigits(x/10):
int sdig=sumDigits(num);
if ((sdig*sdig*sdig) = num)
System.out.println("Dudency number "):
else
System.out.println("Not a Dudency number ");
sort(this):
System.out,println("Deque is empty"); checked using checked using
Top--1 Front=-1 ||
Systemout println( "Sorted sentence else if(front-rear)
Front=Rear+l
Full condition is
publicsatic void main(String args|]) Fullcondition is
System.out.println("The deleted element 1s : checked using checked using
Rear--Max-1
SortAlpha ob-new SortAIpha(); Qarrlfront|D: Top-Max-1
tront-1; There are no variants There are three types
ob.acceptsent(): of variants ie circular
available for stack
rear-1; queue, double-ended
ob d1splay0:
queue and priority
else if(tront-(size-1) queue
Can be considered as
SECTION C Can be considered as a
System.out.println("The deleted element is " vertical collection visual
a horizontal collection
Answer 9.
Qarrlfront|D; visual
() front-0: Used to solve the
Used to solve the
class deQueue
recursive type problems problem having
else sequential processing
int Qarrl): Answer 10.
int lim; class supply extends demand
System.out.printIn("The deleted element is :".
int front;
Qarrlfront|)D.
int rear; int pproduced,
Iront=front+1;
public deQueue(int ) double prate;
public supply(int pd, double pr, String prodid,
lim=l; String pn, int pdm)
front=-1; (i) Difference between stack and queue:
rear-1; Pproduced=pd;
Stack Queue prate-pr;
Qarrl]=new Qarr[l];
The stack is based on super(prodid.pn, pdm):
The queue is based on
LIFO(Last In First Out) FIFO(First In First Out)
public vod addFront(int v) principle principle. public double calculation ()
Insertion Operation is Insertion Operation
if(front-0 && ear=lim-1) | (front-rear-l called Push Operation is called Enqueue return ((prate*super.pdemand) (prate*
System.out.println("Overflow from tront Operation pproduced));
else if(front-1) && (rear=1) Deletion Operation is Deletion Operation
Ifront-rear-0; called Pop Operation is called Dequeue public void display )
Qarr[front]=v; Operation
Push and Pop Operation Enqueue and Dequeue
takes place from one Operation takes place
System.out.println("Product ID", super.pid);
else if (front--0) end of the stack from a different end of
System.out.println("Product Name :" super.
pname);
| front=lim-1; the queue
Qar[front|=v; Ihe most accessible The insertion end is System.out.println("Product demand" super.
pdemand);
element is called Top called Rear End and the
else
and the least
is called the accessible deletion end is called
System.out.println("Product
Pproduced):
Produced
the stack Bottom of the Front End.
int sdig=sumDigits(num);
if ((sdig*sdig*sdig) num) public void display()
System.out.printin("Dudency number ");
else int i,j;
System.out.printin("Not aDudency number "): System.out.println("Before Transpose:");
for(i-0; i <m; it+)
public static void main(String args[]) |
NumDudeob=new NumDude(); for(j-0; j <m; jt+)
ob.input):
ob.isDude(); System.out.print(arr[ili]" ");
System.out.println(" "):
Answer 7.
transpose();
import java.util.Scanner; System.out.println("After Transpose:");
public class Trans for(i -0; i<m; itt)
tor(j=0; j<m;j++)