0
0
Javaprogramming~15 mins

Arithmetic operators in Java - Mini Project: Build & Apply

Choose your learning style9 modes available
Arithmetic Operators in Java
📖 Scenario: You are helping a small shop owner calculate the total cost of items bought by customers. You will use arithmetic operators to add, subtract, multiply, and divide prices.
🎯 Goal: Build a simple Java program that uses arithmetic operators to calculate the total price, discount, and final amount to pay.
📋 What You'll Learn
Create variables for item prices
Create a variable for discount percentage
Calculate total price using addition
Calculate discount amount using multiplication
Calculate final price after discount using subtraction
Print the final price
💡 Why This Matters
🌍 Real World
Calculating prices and discounts is common in shopping and billing systems.
💼 Career
Understanding arithmetic operators is essential for any programming job involving calculations or data processing.
Progress0 / 4 steps
1
Create item price variables
Create three double variables called price1, price2, and price3 with values 10.5, 20.0, and 5.5 respectively.
Java
Need a hint?

Use double type for prices and assign the exact values.

2
Add discount percentage variable
Add a double variable called discountPercent and set it to 10.0 to represent a 10% discount.
Java
Need a hint?

Remember to use double for the discount percentage.

3
Calculate total, discount amount, and final price
Calculate the total price by adding price1, price2, and price3 into a double variable called totalPrice. Then calculate the discount amount by multiplying totalPrice with discountPercent divided by 100 into a double variable called discountAmount. Finally, calculate the final price after discount by subtracting discountAmount from totalPrice into a double variable called finalPrice.
Java
Need a hint?

Use + for addition, * for multiplication, and - for subtraction.

4
Print the final price
Use System.out.println to print the text "Final price: " followed by the value of finalPrice.
Java
Need a hint?

Use System.out.println("Final price: " + finalPrice); to print the result.