A Problem Solved: Apples by the Box
Explore how to solve a real-world problem using Java by calculating costs and savings when buying apples individually versus by the box. Understand how to gather user input, perform arithmetic operations, and handle output in a Java program. This lesson introduces problem-solving with algorithms and touches on precision challenges with decimal numbers in Java.
We'll cover the following...
We'll cover the following...
Problem statement
You’re driving your car with your favourite person and spy a roadside stand. You stop and find a farmer who is selling apples individually and by the box. You buy a box of apples. How much would the apples have cost if you had bought the same number individually? How much did you save, if anything, by buying at the box rate?
Discussion
We really have two ...