Assignment 6

Due Tuesday, May 1 at 1:20pm 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: Suggesting Blog Titles (10 pts)

  • A blog is a website for commentary, discussion or information that is more or less regularly updated. To attract attention, blog entries often have sensational or provocative headlines.
  • For this assignment, we will write a program to produce suggested blog titles on a topic selected by the user.
  • The name of the source code file for this program must be blogtitles.java and all your code must be in this file.
  • Write a program that produces the following five (5) blog titles based on user input of a topic and number:
    • [number] Secrets That Experts Of [topic] Want You To Know!
    • [number] Reasons [topic] Will Change The Way You Think About Everything!
    • You Will Never Believe This Awesome Truth Behind [topic]
    • Here's What No One Tells You About [topic]
    • [number] Ways [topic] Can Help You Live To 100!
  • Ask the user for the following inputs (and no other input) in this order, as shown in the Sample Output below:
    1. Single word topic
    2. Integer number between 3 and 20
  • The words [topic] and [number] (shown in square brackets above for emphasis) must be replaced by the user input.
  • Sample Output: The input prompts and outputs of the program must look like the following for full credit, including the same order of input and wording of the output. For the input shown you must get the same output. However, the output must change correctly if the inputs are different.
    Enter a single-word topic: Java
    Enter an integer number between 3 and 20: 10
    
    Suggested blog titles:
    10 Secrets That Experts Of Java Want You To Know!
    10 Reasons Java Will Change The Way You Think About Everything!
    You Will Never Believe This Awesome Truth Behind Java
    Here's What No One Tells You About Java
    10 Ways Java Can Help You Live To 100!
    

    In the above invocation of the program, the user entered "Java" (without the quotes) as the topic and "10" (without the quotes) as the number.

  • Note the the user should be able to enter any topic of their choice and any number of their choice and the program should adapt the output accordingly.
  • Hint: You will need to use the Scanner class and create a new Scanner to read user input in your program
  • You may add additional blog title suggestions after the above 5, but must print the above 5 blog titles at a minimum.