## Description

Background

You have been assigned to construct a mathematical shape machine. This shape

machine can provide a variety of functions. The machine takes a radius/side and

will compute both the area and the perimeter/circumference. However, most of the

menu only functions with words. Other than the input for the radius/sides, the

machine will fail if it detects numbers. It is your job to construct this machine, to

ensure that everyone in the world can learn about shapes.

Description

This project will be utilizing Strings and Math methods to perform several

operations with shapes. The user will create a simple menu with multiple options.

The input should be done using Strings. For example, if you wanted to perform

functions for the square, the user would type ‘Square.’ There will also be an exit

command within the menu that lets the user close the program by typing in the

word ‘Exit.’

Your Assignment

The first part of the assignment will involve the user entering a password to have

access to the machine. The password will be in the form of the date. The user will

have to parse the date String and concatenate the elements of the date together to

be allowed access into the machine.

Next, the user will create a piece of code that takes in input from the user about

the shape’s radius/side length and have the program compute both the area and the

perimeter/circumference. For instance if the user chooses circle and gives the

radius of the circle, the program should output both the area and the

circumference.

Rules

1. The user MUST check for input validation at the menu step (See test

cases below).

2. The program should only run on the day it is being tested. NO HARD

CODING THE DATES.

User Input

Day must be a positive 2 digit number between 01 and 31

Month must be a positive 2 digit number between 01 and 12

Year must be 2016

*Note: You do not have to check to ensure that valid dates for each

month are entered (i.e. Feb 31st)

Code Structure

1. Display login message “Shape Machine login”

2. Take input for the day (2 digits), the month (2 digits), and the year (4

digits) as Strings.

a. “What is today’s day?”

b. “What is today’s month?”

c. “What is today’s year?

3. Compare it to the current date.

a. See notes at the end of this document how to get the exact date in

the correct format

b. If it matches

i. Display “Correct date. Welcome!”

c. If input is not valid

i. Display “#ERROR Login attempt #[n] Invalid input.

Please try again.”, where n is the login attempt number

(message for 1st and 2nd login attempt)

ii. Allow the user to input another date

1. If valid, display “Correct date. Welcome!” and

continue program

iii. If there are 3 total incorrect inputs, display an error

message and terminate the program

1. “#ERROR 3rd invalid login attempt. Terminating

program.” (message for 3rd login attempt)

4. Create the menu using String input as the only valid operation.

a. Make sure the input String matches exactly with the menu String

for it to work (i.e. case sensitive).

b. The menu will have 4 options, “Circles”, “Rectangles”,

“Triangles”, “Exit”

c. If a user inputs an option that is not valid, display an error

message but do not terminate the program

i. Error message should read “#ERROR Invalid option.

Please try again.”

5. If the user selects Circles

a. Display “Circles selected. Please enter the radius: ”

b. Take in user input

c. If the input is negative, display “#ERROR Negative input. Please

input the radius again: ”

i. Check the new input and if it is correct then proceed. If

not display the error message again and take in new input

until it is valid

ii. You do not need to worry about nonnumerical input

validation (the error should be generated only if the number

is negative)

d. Using the circumference, calculate and display the area and

perimeter of the circle (use Math.PI as a constant instead of

3.14159….)

i. “The circumference is: ____”

ii. “The area is: ____”

e. Also display character length information for the perimeter and

area. Total digits includes everything (for example for 23.0 the total

number of digits is 3 because of 2, 3 decimal and the 0).

i. “Total number of digits in the circumference is: ____”

ii. “Total number of digits in the area is: ____”

6. If the user selects Rectangles

a. Display “Rectangles selected. Please enter the 2 sides: ”

b. Take in the input for the 2 sides

c. If any of the 2 sides are negative or invalid, display “#ERROR

Negative input. Please input the 2 sides again: ”

i. Continue to take in input until the 2 sides are valid

ii. You do not need to worry about nonnumerical input

validation

d. Using the 2 input values, calculate the perimeter and the area

i. “The area is: ____”

ii. “The perimeter is: ____”

e. Also display display character information for the perimeter and

area

i. “Total number of digits in the area is: ____”

ii. “Total number of digits in the perimeter is: ____”

7. If the user selects Triangles

a. Display “Triangles selected. Please enter the 3 sides: ”

b. Take in the input for the 3 sides

c. If any of the 3 input sides are negative, display “#ERROR

Negative input. Please input the 3 sides again: ”

i. Continue to take in input until the 3 sides are valid

ii. You do not need to worry about nonnumerical input

validation.

d. Once you have 3 positive inputs, determine if the 3 sides

constitute a valid triangle

i. If the 3 sides to not generate a valid triangle, display the

error message “#ERROR Triangle is not valid. Returning to

menu.”, and return to the menu (Do not ask the user to

reenter the 3 sides).

ii. HINT: Look into the “continue” keyword in java and

how it can be used to return to the start of a loop

e. Calculate the perimeter and the area of the triangle

f. Determine the type of triangle (options are: Equilateral, Isosceles,

or Scalene)

i. The definition of Isosceles is debated. We are using the

strict definition of Isosceles wherein, a triangle is Isosceles

only if there are EXACTLY 2 sides that are equal. (i.e. an

Equilateral triangle should not also be classified as

Isosceles)

g. Display your results to the user

i. “The triangle is: “____”

ii. “The perimeter is: “____”

iii. “The area is: “____”

h. Also display display character information for the perimeter and

area

i. “Total number of digits in the perimeter is: ____”

ii. “Total number of digits in the area is: ____”

8. If the user selects Exit

a. Display message: “Terminating the program. Have a nice day!”

b. Terminate the program

Sample Run #1 invalid input (user input is in green) (all tested on 2109

2016)

Shape Machine login

What is today’s day? 22

What is today’s month? 09

What is today’s year? 2016

#ERROR Login attempt #1 Invalid input. Please try again.

What is today’s day? 21

What is today’s month? 09

What is today’s year? 2015

#ERROR Login attempt #2 Invalid input. Please try again.

What is today’s day? 21

What is today’s month? 9

What is today’s year? 2016

#ERROR 3rd invalid login attempt. Terminating program.

Sample Run #2 invalid input (user input is in green)

Shape Machine login

What is today’s day? 21

What is today’s month? 25

What is today’s year? 2016

#ERROR Login attempt #1 Invalid input. Please try again.

What is today’s day? 21

What is today’s month? 09

What is today’s year? 2016

Correct date. Welcome!

Welcome to the Shape Machine

Available Options:

Circles

Rectangles

Triangles

Exit

(program continues…)

Sample Run #3 invalid input (user input is in green)

Shape Machine login

What is today’s day? 21

What is today’s month? 09

What is today’s year? 2016

Correct date. Welcome!

Welcome to the Shape Machine

Available Options:

Circles

Rectangles

Triangles

Exit

Rectangles

Rectangles selected. Please enter the 2 sides: 2 5

#ERROR Negative input. Please input the 2 sides again: 2 5

The area is: 10.0

The perimeter is: 14.0

Total number of digits in the area is: 3

Total number of digits in the perimeter is: 3

Welcome to the Shape Machine

Available Options:

Circles

Rectangles

Triangles

Exit

Triangles

Triangles selected. Please enter the 3 sides: 2 2 5

#ERROR Triangle is not valid. Returning to menu.

Welcome to the Shape Machine

Available Options:

Circles

Rectangles

Triangles

Exit

Triangles

Triangles selected. Please enter the 3 sides: 3 4 5

#ERROR Negative input. Please input the 3 sides again: 3 4

5

The triangle is: Scalene

The perimeter is: 12.0

The area is: 6.0

Total number of digits in the perimeter is: 3

Total number of digits in the area is: 2

Welcome to the Shape Machine

Available Options:

Circles

Rectangles

Triangles

Exit

Exit

Circles

Circles selected. Please enter the radius: 11

The circumference is: 69.11503837897544

The area is: 380.1327110843649

Total number of digits in the circumference is: 16

Total number of digits in the area is: 16

Welcome to the Shape Machine

Available Options:

Circles

Rectangles

Triangles

Exit

Exit

Terminating the program. Have a nice day!

Sample Run #4 valid input (user input is in green)

Shape Machine login

What is today’s day? 21

What is today’s month? 09

What is today’s year? 2016

Correct date. Welcome!

Welcome to the Shape Machine

Available Options:

Circles

Rectangles

Triangles

Exit

circles

#ERROR Invalid option. Please try again.

Welcome to the Shape Machine

Available Options:

Circles

Rectangles

Triangles

Exit

Circles

Circles selected. Please enter the radius: 4

#ERROR Negative input. Please input the radius again: 4

The circumference is: 25.132741228718345

The area is: 50.26548245743669

Total number of digits in the circumference is: 17

Total number of digits in the area is: 16

Welcome to the Shape Machine

Available Options:

Available Options:

Circles

Rectangles

Triangles

Exit

Triangles

Triangles selected. Please enter the 3 sides: 13 16 25

The triangle is: Scalene

The perimeter is: 54.0

The area is: 91.19210492142398

Total number of digits in the perimeter is: 3

Total number of digits in the area is: 16

Welcome to the Shape Machine

Available Options:

Circles

Rectangles

Triangles

Exit

Triangles

Triangles selected. Please enter the 3 sides: 6 6 6

#ERROR Negative input. Please input the 3 sides again: 6 6

6

The triangle is: Equilateral

The perimeter is: 18.0

The area is: 15.588457268119896

Total number of digits in the perimeter is: 3

Total number of digits in the area is: 17

Welcome to the Shape Machine

Available Options:

Circles

Rectangles

Triangles

Exit

Rectangles

Rectangles selected. Please enter the 2 sides: 0.5 0.75

The area is: 0.375

The perimeter is: 2.5

Total number of digits in the area is: 4

Total number of digits in the perimeter is: 2

Welcome to the Shape Machine

Available Options:

Circles

Rectangles

Triangles

Exit

Triangles

Triangles selected. Please enter the 3 sides: 11.5 20 11.5

The triangle is: Isosceles

The perimeter is: 43.0

The area is: 56.789083458002736

Total number of digits in the perimeter is: 3

Total number of digits in the area is: 17

Welcome to the Shape Machine

Available Options:

Available Options:

Circles

Rectangles

Triangles

Exit

Circles

Circles selected. Please enter the radius: 0.5

The circumference is: 3.141592653589793

The area is: 0.7853981633974483

Total number of digits in the circumference is: 16

Total number of digits in the area is: 17

Welcome to the Shape Machine

Available Options:

Circles

Rectangles

Triangles

Exit

Exit

Terminating the program. Have a nice day!

Sample Run #5 valid input (user input is in green)

Shape Machine login

What is today’s day? 22

What is today’s month? 09

What is today’s year? 2016

#ERROR Login attempt #1 Invalid input. Please try again.

What is today’s day? 21

What is today’s month? 09

What is today’s year? 2016

Correct date. Welcome!

Welcome to the Shape Machine

Available Options:

Circles

Rectangles

Triangles

Exit

TrianglesRectangles

#ERROR Invalid option. Please try again.

Welcome to the Shape Machine

Available Options:

Circles

Rectangles

Triangles

Exit

Circlez

#ERROR Invalid option. Please try again.

Welcome to the Shape Machine

Available Options:

Circles

Rectangles

Triangles

Exit

Triangles

Triangles selected. Please enter the 3 sides: 13.667 15

Triangles selected. Please enter the 3 sides: 13.667 15

20.33

The triangle is: Scalene

The perimeter is: 48.997

The area is: 102.50179375946183

Total number of digits in the perimeter is: 5

Total number of digits in the area is: 17

Welcome to the Shape Machine

Available Options:

Circles

Rectangles

Triangles

Exit

Rectangles

Rectangles selected. Please enter the 2 sides: 1.75 1.75

#ERROR Negative input. Please input the 2 sides again: 1.75

1.75

The area is: 3.0625

The perimeter is: 7.0

Total number of digits in the area is: 5

Total number of digits in the perimeter is: 2

Welcome to the Shape Machine

Available Options:

Circles

Rectangles

Triangles

Exit

Circles

Circles selected. Please enter the radius: 3.14

The circumference is: 19.729201864543903

The area is: 30.974846927333928

Total number of digits in the circumference is: 17

Total number of digits in the area is: 17

Welcome to the Shape Machine

Available Options:

Circles

Rectangles

Triangles

Exit

Exit

Terminating the program. Have a nice day!

Sample Run #6 valid input (user input is in green)

Shape Machine login

What is today’s day? 22

What is today’s month? 09

What is today’s year? 2016

#ERROR Login attempt #1 Invalid input. Please try again.

What is today’s day? 21

What is today’s month? 09

What is today’s year? 2016

Correct date. Welcome!

Welcome to the Shape Machine

Available Options:

Circles

Rectangles

Triangles

Exit

Rect0ngles

#ERROR Invalid option. Please try again.

Welcome to the Shape Machine

Available Options:

Circles

Rectangles

Triangles

Exit

Circles

Circles selected. Please enter the radius: 0.275

The circumference is: 1.7278759594743864

The area is: 0.23758294442772815

Total number of digits in the circumference is: 17

Total number of digits in the area is: 18

Welcome to the Shape Machine

Available Options:

Circles

Rectangles

Triangles

Exit

Triangles

Triangles selected. Please enter the 3 sides: 343 20 343

The triangle is: Isosceles

The perimeter is: 706.0

The area is: 3428.541964159109

Total number of digits in the perimeter is: 4

Total number of digits in the area is: 16

Welcome to the Shape Machine

Available Options:

Circles

Rectangles

Triangles

Exit

Triangles

Triangles selected. Please enter the 3 sides: 70 25 30

#ERROR Triangle is not valid. Returning to menu.

Welcome to the Shape Machine

Available Options:

Circles

Rectangles

Triangles

Exit

Triangles

Triangles selected. Please enter the 3 sides: 2 2 5

#ERROR Negative input. Please input the 3 sides again: 2 2

5

#ERROR Triangle is not valid. Returning to menu.

#ERROR Triangle is not valid. Returning to menu.

Welcome to the Shape Machine

Available Options:

Circles

Rectangles

Triangles

Exit

Exit

Terminating the program. Have a nice day!

Note(s)

● It is more helpful to use: use input.next() to read the selection from

Shapes Menu as opposed to input.nextLine()

● Please make sure to check your Eclipse settings

so that you are using UTF8 Encoding.

○ Eclipse > Preferences > General > Workspace : Text file

encoding

● You may see a different (rounded) result for area, depending on

how you multiply to get the answer. Please use the following

calculation (without parentheses) to avoid a difference in output:

○ double area = Math.PI * radius * radius;

● You will need to use the following code when comparing the user’s

entered date to the current date:

import java.text.SimpleDateFormat;

import java.util.Date;

String date = new SimpleDateFormat(“ddMMyyyy”).format(new Date());

new Date() creates a new object with today’s day

new SimpleDateFormat(“ddMMyyyy”).format(…)

converts the date it is given (…) to the ddMMyyyy String representation

● Be careful to ensure that you do NOT create a new Scanner object within a

loop. Aside from being inefficient and a waste of system resources, doing so will

create multiple Scanner objects, which will DEFINITELY ensure that your code

will not be graded as it should. You may call the scanner object

(input.next*()) within a loop, but you should not create new objects on

every loop iteration.

● You may want to use double instead of int for all area, perimeter and

circumference calculations in order to handle decimal values

● To determine if a triangle is valid, 3 conditions must be met

○ side a + side b > side c AND

○ side a + side c > side b AND

○ side b + side c > side a

● You don’t have to worry about very large exponential answers such as

1.2342343E13, all input will be small enough to avoid such answers

● When validating input for the shape sides, you do not need to worry about

string input (For example if you have to enter a side length, you do not need to

worry about the input being a string such as “aJkfkFKASD” or some random

sequence of characters

● continue; can be used to stop executing the current loop iteration and

begin the next

● break; can be used to immediately break out of any loop

● System.exit(0); can be used to immediately terminate the program from

any point. Use it wisely and sparingly.

Submission Requirements

● Name the project “Project2”

● Name the class “ShapeMachine”. This will make the java file have the

name: ShapeMachine.java

● Zip the java file (right click the java file > Send to > Compressed

(zipped) folder)

● Name the zip file project2_ulfid.zip where uflID is the

alphanumeric portion of your ufl email account that comes before the

@ufl.edu part.

● Submit using Canvas

If you submit the .java file without zipping, your project will not be graded.

If your file is not named project2_ulfid.zip, your project will not be

graded.

If you do not name the Project and class exactly as specified, your project will not

be graded.

To help you test the output of your program, there will be a sample executable

uploaded to Canvas.

It is highly recommended that you test your program piece by piece before

assembling your final code. You will have a much easier time if you build your

program piece by piece rather than trying to write the entire program. Pay very

close attention to the order that you give inputs to the sample program. Your

output should not differ in any way from the sample output. Using additional

prompts, words, abbreviations, etc may result in the grading program taking

unnecessary points off.

Sample test cases can be found under the Iteration Module on Canvas

Grading

● 90% of your program will be graded on its ability to generate proper

output

● 10% of your program will be graded on its adherence to the coding style

standards.