
Instructions:
->each class to be created must have encapsulated fields, setters and getters methods, and constructors
Create a class named "Paper" with the following attributes -"length" of type int -"width" of type int -"content" of type String
provide a method to compute the area of the paper
Create a class named "Envelope" with the following attribute
provide a method to compute the total area of all papers inside the envelope provide a method to compare if two envelopes are equal provide a method to determine if there are two same papers inside the envelope

Hi Friend,
Try the following code:
import java.util.*;
class Paper{
int length;
int width;
String content;
Paper(int length,int width,String content){
this.length=length;
this.width=width;
this.content=content;
}
public void setLength(int length){
length=length;
}
public int getLength(){
return length;
}
public void setWidth(int width){
width=width;
}
public int getWidth(){
return width;
}
public void setContent(String content){
content=content;
}
public String getContent(){
return content;
}
}
class Envelope{
public static void main(String[] args){
int ar1[]=new int[5];
int ar2[]=new int[5];
int count=0;
int totalarea1=0,totalarea2=0;
System.out.println("Envelope 1:");
Paper p1[]=new Paper[5];
Scanner input=new Scanner(System.in);
for(int i=0;i<p1.length;i++){
System.out.println("Enter length of paper "+(i+1)+": ");
int len=input.nextInt();
System.out.println("Enter width of paper "+(i+1)+": ");
int wid=input.nextInt();
int aa=len*wid;
ar1[i]=aa;
p1[i]=new Paper(len,wid,Integer.toString(aa));
p1[i].setLength(len);
p1[i].setWidth(wid);
p1[i].setContent(Integer.toString(aa));
}
for(int i=0;i<p1.length;i++){
totalarea1+=Integer.parseInt(p1[i].getContent());
}
System.out.println("Total Area of all papers inside the envelope1: "+totalarea1);
System.out.println("Envelope 2:");
Paper p2[]=new Paper[5];
for(int i=0;i<p2.length;i++){
System.out.println("Enter length of paper "+(i+1)+": ");
int len=input.nextInt();
System.out.println("Enter width of paper "+(i+1)+": ");
int wid=input.nextInt();
int aa=len*wid;
ar2[i]=aa;
p2[i]=new Paper(len,wid,Integer.toString(aa));
p2[i].setLength(len);
p2[i].setWidth(wid);
p2[i].setContent(Integer.toString(aa));
}
for(int i=0;i<p2.length;i++){
totalarea2+=Integer.parseInt(p2[i].getContent());
}
System.out.println("Total Area of all papers inside the envelope2: "+totalarea2);
if(totalarea1==totalarea2){
System.out.println("Envelopes are equal");
}
else{
System.out.println("Envelopes are not equal");
}
}
}
Thanks

Hi Friend,
Try the following code:
import java.util.*;
class Paper{
int length;
int width;
String content;
Paper(int length,int width,String content){
this.length=length;
this.width=width;
this.content=content;
}
public void setLength(int length){
length=length;
}
public int getLength(){
return length;
}
public void setWidth(int width){
width=width;
}
public int getWidth(){
return width;
}
public void setContent(String content){
content=content;
}
public String getContent(){
return content;
}
}
class Envelope{
public static void main(String[] args){
int ar1[]=new int[5];
int ar2[]=new int[5];
int count=0;
int totalarea1=0,totalarea2=0;
System.out.println("Envelope 1:");
Paper p1[]=new Paper[5];
Scanner input=new Scanner(System.in);
for(int i=0;i<p1.length;i++){
System.out.println("Enter length of paper "+(i+1)+": ");
int len=input.nextInt();
System.out.println("Enter width of paper "+(i+1)+": ");
int wid=input.nextInt();
int aa=len*wid;
ar1[i]=aa;
p1[i]=new Paper(len,wid,Integer.toString(aa));
p1[i].setLength(len);
p1[i].setWidth(wid);
p1[i].setContent(Integer.toString(aa));
}
for(int i=0;i<p1.length;i++){
totalarea1+=Integer.parseInt(p1[i].getContent());
}
System.out.println("Total Area of all papers inside the envelope1: "+totalarea1);
System.out.println("Envelope 2:");
Paper p2[]=new Paper[5];
for(int i=0;i<p2.length;i++){
System.out.println("Enter length of paper "+(i+1)+": ");
int len=input.nextInt();
System.out.println("Enter width of paper "+(i+1)+": ");
int wid=input.nextInt();
int aa=len*wid;
ar2[i]=aa;
p2[i]=new Paper(len,wid,Integer.toString(aa));
p2[i].setLength(len);
p2[i].setWidth(wid);
p2[i].setContent(Integer.toString(aa));
}
for(int i=0;i<p2.length;i++){
totalarea2+=Integer.parseInt(p2[i].getContent());
}
System.out.println("Total Area of all papers inside the envelope2: "+totalarea2);
if(totalarea1==totalarea2){
System.out.println("Envelopes are equal");
}
else{
System.out.println("Envelopes are not equal");
}
}
}
Thanks
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.