0
0
Javaprogramming~15 mins

One-dimensional arrays in Java - Mini Project: Build & Apply

Choose your learning style8 modes available
folder_codeWorking with One-Dimensional Arrays in Java
📖 Scenario: You are helping a small store owner keep track of daily sales for a week. The owner wants to store the sales amounts in an array and then calculate the total sales.
🎯 Goal: Build a Java program that creates an array of daily sales, sets a target sales threshold, calculates the total sales using a loop, and then prints the total sales.
📋 What You'll Learn
Create a one-dimensional array called dailySales with exactly 7 elements representing sales amounts for each day.
Create an integer variable called salesTarget and set it to 500.
Use a for loop with the variable i to sum all elements in dailySales into a variable called totalSales.
Print the value of totalSales.
💡 Why This Matters
🌍 Real World
Stores and businesses often track daily sales or data points in arrays to analyze performance over time.
💼 Career
Understanding arrays and loops is fundamental for software development jobs that involve data processing and reporting.
Progress0 / 4 steps
1
Create the daily sales array
Create a one-dimensional integer array called dailySales with these exact values: 120, 85, 90, 100, 95, 110, 130.
Java
💡 Need a hint?

Use curly braces {} to list the values inside the array.

2
Set the sales target
Create an integer variable called salesTarget and set it to 500.
Java
💡 Need a hint?

Use int salesTarget = 500; to create the variable.

3
Calculate total sales using a for loop
Create an integer variable called totalSales and set it to 0. Then use a for loop with the variable i to add each element of dailySales to totalSales.
Java
💡 Need a hint?

Use dailySales.length to get the number of elements in the array.

4
Print the total sales
Write a System.out.println statement to print the value of totalSales.
Java
💡 Need a hint?

Use System.out.println(totalSales); to display the total sales.