do this to follwing code : 1) Provide comments in your code. 2)Provide a program design. 3) Browse the API Documentation to see all the features of the following classes: Point, Rectangle, String. code : import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int rectangle_count=0; Random random = new Random(); try{ System.out.print("Please enter the width and the height of the given rectangle: "); int width = sc.nextInt(); int height = sc.nextInt(); System.out.print("Please enter how many rectangles you would like to generate: "); rectangle_count = sc.nextInt(); while(rectangle_count <=0){ System.out.println("Error: Enter integer value > 0...Try Again"); System.out.print("lease enter how many rectangles you would like to generate: "); rectangle_count = sc.nextInt(); } System.out.println("**********************************************************************"); System.out.println("*\tRect#\t*\tR\t(\tx, \ty, \tw, \th\t)\t*\tcontained corners\t*"); System.out.println("**********************************************************************"); for(int i=0;i
do this to follwing code :
1) Provide comments in your code.
2)Provide a program design.
3) Browse the API Documentation to see all the features of the following classes: Point, Rectangle, String.
code :
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int rectangle_count=0;
Random random = new Random();
try{
System.out.print("Please enter the width and the height of the given rectangle: ");
int width = sc.nextInt();
int height = sc.nextInt();
System.out.print("Please enter how many rectangles you would like to generate: ");
rectangle_count = sc.nextInt();
while(rectangle_count <=0){
System.out.println("Error: Enter integer value > 0...Try Again");
System.out.print("lease enter how many rectangles you would like to generate: ");
rectangle_count = sc.nextInt();
}
System.out.println("**********************************************************************");
System.out.println("*\tRect#\t*\tR\t(\tx, \ty, \tw, \th\t)\t*\tcontained corners\t*");
System.out.println("**********************************************************************");
for(int i=0;i<rectangle_count;i++){
int w= (int)Math.floor(random.nextDouble()*width);
int h=(int)Math.floor(random.nextDouble()*height);
int x = (int)Math.floor(random.nextDouble()*(width-w));
int y = (int)Math.floor(random.nextDouble()*(height-h));
System.out.printf("*\t%d\t*\tR\t(\t%d, \t%d, \t%d, \t%d\t)\t*\t0\t*\n",(i+1),x,y,w,h);
}
System.out.println("**********************************************************************");
}catch(Exception e){
System.out.print("Error: It is not Integer value...Exit.");
}
}
}
Step by step
Solved in 4 steps with 2 images