This code is for a simple investment tracking application that calculates daily and total earnings of an investment over 7 days period.
- The user is prompted to enter the buying price per share.
- The user is then prompted to enter the closing price for each day of the week (7 days).
- For each day, the application calculates the earnings by subtracting the buying price from the closing price.
- The earnings are stored in an array
weekly
. - The application then prints out a message indicating whether the investment has gained, lost, or broken even for each day.
- After all 7 days, the application calculates the total weekly earnings by summing up the earnings for each day.
- The total weekly earnings are printed out to the console.
buyingPrice
: The buying price per share.closingPrice
: The closing price for each day.weekly
: An array of doubles to store the earnings for each day.day
: An integer variable to keep track of the current day.i
: An integer variable to iterate through theweekly
array.j
: An integer variable to iterate through theweekly
array in the second loop.totalWeeklyEarnings
: A double variable to store the total weekly earnings.
Scanner
to read input from the user.System.out.println
andSystem.out.printf
to print output to the console.Arrays
to store and manipulate theweekly
array.
Code Output On Console: