Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a simple class named rect that representsrectangles that have integer valu

ID: 3613073 • Letter: W

Question

Write a simple class named rect that representsrectangles that have integer valued dimensions.


Sample Run:

prompt: a.out

Enter height: 7

Please width: 3

The area is 21

The perimeter is 20

***

***

***

***

***

***

***

prompt: a.out

Please enter the height of the rectangle: 0

Please enter the width of the rectangle: 10

Invalid retangle.

The area is 1

The perimeter is 4

*

prompt: a.out

Please enter the height of the rectangle: 32

Please enter the width of the rectangle: 32

The area is 1024

The perimeter is 128

This rectangle is too large to display.

Explanation / Answer

import java.util.*;import java.io.*;class rect{private int w,h;int Area() {return w*h;}int Perimeter() {return 2*(w+h);}int Width() {return w;}int Height(){return h;}void Set(int hh, int ww){h=hh;w=ww;}void Print() {int i,j;if(w >60 || h >20){System.out.println("The rectangle is too large to display"); return;}for(i=0;i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote