Starting from:

$30

CSCI301-Lab 3 Drawing Shapes Solved

In this project, we will demonstrate our knowledge of loops, decision statements, and nested statements to draw shapes. This project will consist of drawing rectangles, triangles, hexagons, octagons, and pentagons exactly as shown in the examples provided at the end of this document. 

Your program should be in class called DrawingShapes and stored in a file called DrawingShapes.java.   

Program Requirements
1.     You will need to comment each section of your source code that draws a shape.  For example, you need to include comments for the section of source code that draws a rectangle, comments for the section of code that draws a triangle, and so forth for each shape required in this project.  

2.     All instructions in this document must be followed in order for full credit to be awarded. Following the instructions is a vital part to this and all programming assignments.  

3.     Your program must follow the examples provided in the Examples section, and your program’s I/O (input and output) must match the examples exactly (otherwise, points will be deducted).  If your program does not produce the same output as our examples, then your program has a bug, and you’ll need to fix any bugs using any debugging techniques discussed this semester. There should be NO spaces to right of any *’s in your program’s output, and the number of spaces in front of the *’s do matter in order to output the shape correctly based on the examples. After drawing the last * in the shape, your program should print a single newline character.  

4.     Your program must handle all error cases as shown in the examples.  The valid shapes (r t h o p) are shown in the prompts in the examples, and any other input for shapes are considered as invalid. The user input for drawing an octagon is a lowercase o, the letter before p in the English alphabet.  A length is valid if and only if it is greater than 1, and a height is valid if and only if it is greater than 1.  Also, some shapes do not require height as an input, and these shapes should not prompt the user for a height.  Invalid inputs must be handled as shown in the examples.   

5.     For all sets of valid user input, your program must correctly draw the shape and dimension(s).  

 

Examples
Your program should work correctly on the examples below, and it should draw various shapes correctly when the inputs are valid.  All input and output should be formatted as shown when run  (note:  the new line(s) separating each example is not part of your program’s I/O, it is in this document to show the difference between examples).  Each example is separate run of a correctly working program. Some examples include invalid inputs, and some do not.   

Enter a shape: r t h o p

r

Enter a length

3

Enter a height

4

Below is a 3 by 4 rectangle of *

***

***

***

***

 

Enter a shape: r t h o p

t

Enter a length

6

Below is a triangle with two side lengths of 6 *      *

    ***

   *****

  *******

 *********

***********

 

       

h Enter a length

10

Below is a hexagon with side lengths of 10 *

         **********

        ************

       **************

      ****************

     ******************

    ********************

   **********************

  ************************

 **************************

****************************

 **************************   ************************

   **********************

    ********************

     ******************

      ****************        **************

        ************

         **********

 

       

o Enter a length

9

Below is an octagon with side lengths of 9 *

        *********

       ***********

      *************

     ***************

    *****************

   *******************

  *********************

 ***********************

*************************

*************************

*************************

*************************

*************************

*************************

*************************

*************************

*************************  ***********************

  *********************

   *******************

    *****************

     ***************

      *************        ***********

        *********

 

Enter a shape: r t h o p p Enter a length

3

Below is a pentagon with 4 side lengths of 3 *

  *

 ***

*****

*****

*****

 

Enter a shape: r t h o p

R Invalid shape Goodbye!

 

       

Z Invalid shape Goodbye!

 

Enter a shape: r t h o p r Enter a length

1

Length must be greater than 1 Goodbye!

 

Enter a shape: r t h o p r Enter a length

2

Enter a height

1

Height must be greater than 1 Goodbye!

 

Enter a shape: r t h o p h Enter a length

0

Length must be greater than 1

Goodbye!

 

Enter a shape: r t h o p o Enter a length

4

Below is an octagon with side lengths of 4 *

   ****

  ******

 ********

**********

**********

**********

**********

 ********

  ******

   ****

       

h Enter a length

3

Below is a hexagon with side lengths of 3 *   ***

 *****

*******

 *****

  ***

 

Enter a shape: r t h o p r Enter a length

10

Enter a height

4

Below is a 10 by 4 rectangle of *

**********

**********

**********

**********

 

Enter a shape: r t h o p p Enter a length

7

Below is a pentagon with 4 side lengths of 7 *

      *

     ***

    *****

   *******

  *********

 ***********

*************

*************

*************

*************

*************

*************

*************

 

       

o Enter a length

13

Below is an octagon with side lengths of 13 *

            *************

           ***************

          *****************

         *******************

        *********************

       ***********************

      *************************

     ***************************

    *****************************

   *******************************

  *********************************

 ***********************************

*************************************

*************************************

*************************************

*************************************

*************************************

*************************************

*************************************

*************************************

*************************************

*************************************

*************************************

*************************************

*************************************

 ***********************************

  *********************************

   *******************************

    *****************************

     ***************************       *************************        ***********************

        *********************

         *******************           *****************

           ***************

            *************

 

More products