Assignment 5 

Due Thursday, October 11 at 9:20am on Canvas

Assignment 5.1: Collecting Student Data (10 pts)

  • The goal of this program is to collect student data and print it to the screen.
  • The program should first print out the message "Collecting Student Data!" and then move down two lines.
  • Your program should prompt the user for his or her GPA.
  • It should then ask for the student ID number of the user.
  • It should ask the user how many years he or she has attended De Anza.
  • Notice how the user input and the prompt are on THE SAME LINE.
  • Finally, the program should print another blank line and then print the student information to the screen.
  • Think carefully about what type of variables you will use to store each piece of information.
  • Also, think carefully about whether you will need input.nextInt() or input.nextDouble() for each piece of information.
  • Please include your name and section information in the block comment at the start of your program.
  • Save your project as Student2, name your class Student and upload to Canvas.
  • Your program output should look identical to the following (except for the user input which will vary):

Collecting Student Data!

Please enter your GPA: 3.5
Please enter your student ID number: 100066
Please enter the number of years you have attended De Anza: 2.5

3.5 is your GPA.
Your student ID number is 100066.
You have attended De Anza for 2.5 years.

Assignment 5.2: Costly Habits (10 pts)
  • One of the keys to financial well-being is to understand the impacts of our spending habits.
  • We all have little habits, such as buying coffee or snacks every day, that add up over time.
  • In this program we explore how much a habit will cost us, or a friend, by time we reach age 75.
  • Example Run: 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 properly if the inputs are different.
  • Write a program that calculates the cost of a daily habit by the time you reach age 75. Because the amounts may be large, we want to see the cost in both dollars and millions of dollars.
  • For example, $75,000 is 0.075 million dollars.
  • Open a new Java project called Habits with a class called
  • Ask the user for the following inputs (and no other input) in this order, as shown in the Example Run below:
    • age in years
    • habit cost per day
  • Assume the user enters valid integers for age and decimal numbers for habit cost per day.
  • Your program should then output the following:
  1. The amount of money the habit will cost the user in one year (hint: how many days in a year?)
  2. The amount of money the habit will cost the user by the time they reach 75. (hint: how many years until they reach 75?)
  3. The cost from #2 above in millions of dollars
  • Numbers may not display with exactly two decimal places, which is fine.

    Current age (years): 19
    Cost of daily habit: 10.75

    This year your habit will cost you $3923.75
    Between now and age 75, it will cost you $219730.0!
    Cost in millions of dollars is 0.21973!

  • Hint: Ignore leap years, and ignore that the user may be part way through the year.
    • For example, if the user enters age 50, assume there are 25 full years until he or she reaches age 75.
  • Hint 2: To get the cost in millions of dollars, divide by one million (how many 0s in a million?)
  • Hint 3: Assume the user is no older than age 75, and that the user enters correct data.
  • Submit when you are finished.