Question: using jGRASP Please submit the following java programs in a zipped folder on Canvas: Hexagonal Number (100 pts) - Hexagonal.java Extra Credit: Pattern of Stars
using jGRASP
Please submit the following java programs in a zipped folder on Canvas:
Hexagonal Number (100 pts) - Hexagonal.java
Extra Credit: Pattern of Stars (10pts) StarMethod2.java
Hexagonal Number
In mathematics, a Hexagonal number is a number that represents the number of dots needed to form a hexagon. Starting with 1 (the first point) we can add the appropriate number of dots so that the result is a hexagon of increasing size.
Based on the example above, the first few hexagonal numbers are:
1, 6, 15, 28, 45, 66, 91, 120, 153, 190, 231, 276, 325, 378,
To get a number in the hexagonal sequence, we use the formula pn= 3n (to the power of 2) -2* n for n>=1.
Write a program that does the following:
Prompts the user for a starting and ending integer value
Checks the values so that:
The starting value is greater than 0
The ending value is greater than the starting value
Calls a method called getHexagonalNumber to calculate and return the corresponding Hexagonal Number
Prints the number and its corresponding hexagonal value for the given range (in a table format)
Samples of the output are shown below. (Note, your program does not have to have the exact wording in the output, but should accomplish the same tasks.)
Sample Output 1
This program will print a table of hexagonal numbers in a given range. Enter a starting value (greater than 0): 0 Your previous entry is invalid. Enter another starting value: 1 Enter an ending value (greater than your starting value): -9 Your previous entry is invalid. Enter another ending value: 10 Number Hexagonal Number ----------------------------------- 1 1 2 6 3 15 4 28 5 45 6 66 7 91 8 120 9 153 10 190
Sample Output 2
This program will print a table of hexagonal numbers in a given range. Enter a starting value (greater than 0): 15 Enter an ending value (greater than your starting value): 9 Your previous entry is invalid. Enter another ending value: 25 Number Hexagonal Number ----------------------------------- 15 435 16 496 17 561 18 630 19 703 20 780 21 861 22 946 23 1035 24 1128 25 1225
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
