Answer:
Java program is given below. You can get .class after you execute java programs, You can attach those files along with .java classes given , Those .class files are generated ones.
Explanation:
//Rectangle.java class
public class Rectangle {
private int x;
private int y;
private int width;
private int height;
// constructs a new Rectangle with the given x,y, width, and height
public Rectangle(int x, int y, int w, int h)
{
this.x=x;
this.y=y;
this.width=w;
this.height=h;
}
// returns the fields' values
public int getX()
{
return x;
}
public int getY()
{
return y;
}
public int getWidth()
{
return width;
}
public int getHeight()
{
return height;
}
// returns a string such as “Coordinate is (5,12) and dimension is 4x8” where 4 is width and 8 is height. public String toString()
public String toString()
{
String str="";
//add x coordidate , y-coordinate , width, height and area to str and return
str+="Coordinate is ("+x+","+y+")";
str+=" and dimension is : "+width+"x"+height;
str+=" Area is "+(width*height);
return str;
}
public void changeSize(int w,int h)
{
width=w;
height=h;
}
}
======================
//main.java
class Main {
public static void main(String[] args) {
//System.out.println("Hello world!");
//create an object of class Rectangle
Rectangle rect=new Rectangle(5,12,4,8);
//print info of rect using toString method
System.out.println(rect.toString());
//chamge width and height
rect.changeSize(3,10);
//print info of rect using toString method
System.out.println(rect.toString());
}
}
==========================================================================================
//Output
Coordinate is (5,12) and dimension is : 4x8 Area is 32
Coordinate is (5,12) and dimension is : 3x10 Area is 30
========================================================================================