YCP Logo Lab 31: Java

Due: Friday, December 12th by 11:59 PM

Getting started

Import CS200_Lab31.zip (File->Import...->General->Existing Projects into Workspace->Archive File). You should see a project called CS200_Lab31 in the Package Explorer. Expand the src folder and the edu.ycp.cs200.rectangle package. You should see a file called Rect.java. Open the file. You will add your code to the main method.

Your task

In this lab you will practice writing Java programs.

Your task is to prompt the user to enter two int values, and to draw a rectangle of the specified size.

Example run:

Height and width? 7 45
*********************************************
*********************************************
*********************************************
*********************************************
*********************************************
*********************************************
*********************************************

Hints

Java has for, while, and do/while loops. Each one works just like its counterpart in C.

Use an instance of java.util.Scanner to read from the keyboard:

Scanner scanner = new Scanner(System.in);

The nextInt method reads one int value from the scanner. Make sure you have an import statement at the top of your source file (just underneath the package declaration):

import java.util.Scanner;

Once your program can print a solid rectangle, try some more interesting rectangles, e.g.:

Outlined rectangle:

Height and width? 7 45
*********************************************
*                                           *
*                                           *
*                                           *
*                                           *
*                                           *
*********************************************

Barn door square (height and width must be same):

Height and width? 10 10
**********
**      **
* *    * *
*  *  *  *
*   **   *
*   **   *
*  *  *  *
* *    * *
**      **
**********

Submitting

When you are done, save the project (CS200_Lab31) to a zip file by right-clicking it and choosing

Export...->Archive File

Upload the saved zip file to the Marmoset server as lab31. The server URL is

https://camel.ycp.edu:8443/