In-class Exercise for CS 111A - Advanced Methods

Write the main and outputLine methods to complete the program below. The main method must call both getPosNumber and outputLine The program is to use getPosNumber to input width and height, and then use outputLine to draw a rectangle of asterisks (*) on the screen with those dimensions. Here is sample output for two different runs of the program:

This program will output a rectangle. 
How wide do you want it? -1 
You must enter a positive integer 
How wide do you want it? 5 
How tall? 0 
You must enter a positive integer 
How tall? 3 
***** 
***** 
***** 

----------------------------------------
  
This program will output a rectangle. 
How wide do you want it? 4 
How tall? 2 
**** 
****

Here is the program's source code:

import java.util.Scanner; 
class Test3Coding 
{ 
  static Scanner sc = new Scanner(System.in); 
  
  public static void main(String[] args) 
  { 
    // insert your code here 
  } 
  
  static int getPosNumber(String prompt) 
  { 
    int val; 
    do 
    { 
      System.out.print(prompt); 
      val = sc.nextInt(); 
      if (val <= 0) System.out.println("You must enter a positive integer"); 
    } while(val <= 0); 
    return val; 
  } 
  
  // output size number of the char s on one line. 
  static void outputLine(char s, int size) 
  { 
    // insert your code here 
  } 
}