Page 476 - Computer science 868 Class 12
P. 476
void update( ) : to update the stock by adding the previous quantity by the purchased
quantity and replace the rate of the item if there is a difference in the
purchase rate. Also update the current stock value as: (quantity * unit price)
void display( ) : to display the stock details before and after updating
Ans. class Godown
{ String item;
int qty;
double rate,amt;
Godown(String i,int q,double r)
{ item=i;
qty=q;
rate=r;
amt=q*r;
}
void display()
{ System.out.print("Name:"+item+" Quantity "+qty+" Rate "+rate+" Amount "+amt);
}
}
class Update extends Godown
{ int pur_qty;
double pur_rate;
Update(String i,int q,double r,int pq,double pr)
{ super(i,q,r);
pur_qty=pq;
pur_rate=pr;
}
void update()
{ qty=qty+pur_qty;
rate=pur_rate;
amt=qty*rate;
}
void display()
{ System.out.println("Before updaton");
super.display();
System.out.println("After updaton");
update();
System.out.println("Qty"+ qty+" rate "+rate+" amount "+amt);
}
public static void main(String i,int q,double r,int pq,double pr)
{ Update ob=new Update(i,q,r,pq,pr);
ob.display();
}
}
#Interdisciplinary
D. Java programs: #Experiential Learning
1. A class D2Point defines the co-ordinates of a point in a plane, while another class D3Point defines the coordinates of a point in a
space. The details of both the classes are given below. [ISC 2004]
Class name : D2Point
Data Members
double x, y : To store the values of x and y coordinates
D2Point(double nx, double ny) : Constructor to assign nx to x and ny to y
double distance2D(D2Point b) : To return distance between point object b and the current point object in
the plane using formula:
2
2
PQ = (x − x 1 ) + (y − y 1 ) assuming (x , y ) and (x , y ) as the two points.
2
2
2
2
1
1
474474 Touchpad Computer Science-XII

