Given the following, how do you make it so that there is adriver and a rect clas
ID: 3613111 • Letter: G
Question
Given the following, how do you make it so that there is adriver and a rect class and you are running the driver?-----------
import java.util.Scanner;
public 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 todisplay."); return; } for(i=0;i<h;i++) for(j=0;j<w;j++) { System.out.print('*'); if(j==w-1 && i!= h-1) System.out.println(); } }
//**************************************************************************
public static void main(String[] args) { int hh,ww; Scanner stdIn = new Scanner(System.in); System.out.print("Please enter the height of the rectangle:"); hh = stdIn.nextInt(); System.out.print("Please enter the width of the rectangle:"); ww = stdIn.nextInt(); rect r = new rect(); if(hh<=0 || ww<=0) { System.out.println("Invalid rectangle"); } else { r.Set(hh,ww); System.out.println("The area is " + r.Area()); System.out.println("The perimeter is " + r.Perimeter()); r.Print(); System.out.println(); } } } Given the following, how do you make it so that there is adriver and a rect class and you are running the driver?
-----------
import java.util.Scanner;
public 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 todisplay."); return; } for(i=0;i<h;i++) for(j=0;j<w;j++) { System.out.print('*'); if(j==w-1 && i!= h-1) System.out.println(); } }
//**************************************************************************
public static void main(String[] args) { int hh,ww; Scanner stdIn = new Scanner(System.in); System.out.print("Please enter the height of the rectangle:"); hh = stdIn.nextInt(); System.out.print("Please enter the width of the rectangle:"); ww = stdIn.nextInt(); rect r = new rect(); if(hh<=0 || ww<=0) { System.out.println("Invalid rectangle"); } else { r.Set(hh,ww); System.out.println("The area is " + r.Area()); System.out.println("The perimeter is " + r.Perimeter()); r.Print(); System.out.println(); } } }
Explanation / Answer
import java.util.Scanner;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;iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.