Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Calculates the number of candy bars that can be purchased
- * based on a 15 dollar starting balance, a bar cost of 1 dollar
- * and on the condition that for every 3 wrappers, you earn a free bar.
- */
- package wrappercalculator;
- /*
- * Author Tolfasn
- */
- public class WrapperCalculator {
- public static void main(String[] args) {
- //stores starting values
- int walletBalance = 15;
- int barCount = 1;
- //loops to calculate the total number of bars
- while(walletBalance > 0){
- barCount ++;
- if(barCount % 3 == 0)
- walletBalance = walletBalance;
- else walletBalance --;
- //Displays the current number of candy bars
- System.out.println("You have " + barCount + " candy Bars");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement