9.1
public class Rectangle {
double width=1;
double height=1;
Rectangle()
{
}
void width(double width)
{
this.width=width;
}
void height(double height)
{
this.height=height;
}
public double getArea()
{
return width*height;
}
double gerPerimeter()
{
return (width+height)*2;
}
}
public class Demo {
public static void main(String[] args) {
Rectangle a=new Rectangle();
Rectangle b=new Rectangle();
a.height=40;
a.width=4;
b.height=35.9;
b.width=3.5;
System.out.println(a.width+" "+a.height+" "+a.getArea()+" "+a.gerPerimeter());
System.out.println(b.width+" "+b.height+" "+b.getArea()+" "+b.gerPerimeter());
}
}
9.2
public class Stock {
String symbo1;
String name ;
double previousClosingPrice;
double currentPrice;
Stock()
{
}
double getChangePercent(){
return (currentPrice-previousClosingPrice)/previousClosingPrice*100;
}
}
public class Demo {
public static void main(String[] args) {
Stock ORCL=new Stock();
ORCL.previousClosingPrice=34.5;