Assignment 6

Due Tuesday, October 16 at 9:20am on Canvas.

#### Activity 6.1: Imagine All the People (10 pts)

• Worldwide population continues to grow every year [1]. One model for projecting the growth is given by the equation:
population = 7.35 · e 0.0071 (Year - 2016)
• which reports the results in billions.
• The letter `e` in the above formula is the mathematical symbol for Euler's number, the base of the natural logarithms.
• To calculate this exponent in Java, you will need to use the `Math.exp()` method from java.lang.Math.
• Add a block comment at the top of your program with your name and section information.
/*
* @author first name last name
* Section info
*/
• Write a program that requests a year from a user and displays the estimated population for that year as shown in the Example Run below.
• You must name the source code file `PopGrowth.java`.
• Create a new Scanner variable at the top of your program, named input.
• Then, declare a new integer variable called year.
• Prompt the user to enter the year for which they wish to calculate the world population.
• Calculate the population for the year using the formula for population shown above.
• Use the `Math.exp()` method from `java.lang.Math`  to calculate the power of e (Euler's number).
• Example Run: The outputs of the program must look like the following for you to receive full credit. For the input shown (`2020`) you must get the same output. However, the output numbers must change if the inputs are different.
```Enter the year: 2020
Estimated worldwide population in 2020: 7.561732368586969 billion
```
• Use the default formatting and precision for the numbers -- do NOT add any numerical formatting statements to the code.
• When your program works identically to the example output above, submit PopGrowth.java to Canvas.

Assignment 6.2: Calculator Part 2 (10 pts)

• We are going to create a calculator program using the math methods from the Math library.
• Open a new Java class in Eclipse called Maths.java
• Create a program that prompts the user to input a number, and then performs calculations on that number.
• Your calculator is going to perform the following operations on that number:
• Raise the number to the power of 2, 3, and 4 (square, cube, quartic)
• Calculate the floor of the number
• Calculate the ceiling of the number
• Calculate the square root of the number
• Calculate the natural log of the number (hint: use the log function)
• Your program should give output as shown below.
Your output should look identical to the following (except user input will vary):

Enter a number: 2.5
The square of 2.5 is: 6.25
The cube of 2.5 is: 15.625
The quartic (fourth power) of 2.5 is: 39.0625
The ceiling of 2.5 is: 3.0
The floor of 2.5 is: 2.0
The square root of 2.5 is: 1.58114
The natural log of 2.5 is: 0.916291

• Write a program that plays the game of Mad Libs.
• Your program must prompt the user to enter the following information as Strings in this order:
1. A man's name
2. A woman's name
5. A color
6. A noun
7. An animal
8. A body part
9. A holiday

• After the Strings are entered, substitute the Strings into the below story and output the story to the console:

# The Haunted Tower

One afternoon <man name> and <woman name> were walking down a(n) <adjective1> trail, looking for kindling for their campfire. The trees were <adjective2> and <color>, and there were colorful wildflowers all around. <man name> and <woman name> began to pick the wildflowers, and after a while, they went so far that they had wandered away from the trail.

It started to get dark. <man name> began to get worried, but <woman name> seemed excited to have an adventure. 'Look!' <woman name> said. 'Do you see that tower? It looks like a <noun>!'

'We're saved!' cried <man name>, who was relieved.

Once they got closer, <man name> felt very uneasy again. It didn't look like the cozy little cottage <man name> had been imagining, but rather a big, spooky tower! It was about 14 feet tall, and it was covered with green ivy and moss. It was the creepiest thing <man name> had ever seen!

<man name> said, '<woman name>, let's keep walking! There's no way I'm going into that tower! It looks haunted!'

'Don't be such a(n) <animal>! We're going in. I think it looks safe to me!' said <woman name>.

<man name> was so scared. He felt his <body part> chatter as <woman name> opened the door. All of a sudden, <man name> felt that he was not alone. He opened his eyes, prepared to see the worst. But instead, he saw all his friends and family inside the haunted tower! 'Surprise! Happy <holiday>, <man name>!' they all cried.

Note that you will need to decide where to insert newline characters into the output to make the text look like the above output.
• Be careful of the spelling, including capitalization, and spacing
• Note: Please use the single quote around the lines of dialogue (as shown above) rather than the double quote.
• Note 2: Use only input.nextLine() to ensure that you read in all of the user input for each question.
• Also be careful not to change the formatting of the above story in any way! You will want to preserve the original spacing and punctuation.
• Your output should look identical to the following, except user input will vary:

Enter a man's name: Larry
Enter a woman's name: Noreen
Enter a color: red
Enter a noun: book
Enter an animal: duck
Enter a body part: leg
Enter a holiday: Valentine's

The Haunted Tower

One afternoon Larry and Noreen were walking down a(n) funny trail, looking for kindling for their campfire. The trees were amazing and red, and there were colorful wildflowers all around. Larry and Noreen began to pick the wildflowers, and after a while, they went so far that they had wandered away from the trail.

It started to get dark. Larry began to get worried, but Noreen seemed excited to have an adventure. 'Look!' Noreen said. 'Do you see that tower? It looks like a book!'

'We're saved!' cried Larry, who was relieved.

Once they got closer, Larry felt very uneasy again. It didn't look like the cozy little cottage Larry had been imagining, but rather a big, spooky tower! It was about 14 feet tall, and it was covered with green ivy and moss. It was the creepiest thing Larry had ever seen!

Larry said, 'Noreen, let's keep walking! There's no way I'm going into that tower! It looks haunted!'

'Don't be such a(n) duck! We're going in. I think it looks safe to me!' said Noreen.

Larry was so scared. He felt his leg chatter as Noreen opened the door. All of a sudden, Larry felt that he was not alone. He opened his eyes, prepared to see the worst. But instead, he saw all his friends and family inside the haunted tower! 'Surprise! Happy Valentine's, Larry!' they all cried.