Advertisement
tolfasn

Wrapper Calculator

Oct 24th, 2015
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.83 KB | None | 0 0
  1. /*
  2.  * Calculates the number of candy bars that can be purchased
  3.  * based on a 15 dollar starting balance, a bar cost of 1 dollar
  4.  * and on the condition that for every 3 wrappers, you earn a free bar.
  5.  */
  6. package wrappercalculator;
  7.  /*
  8.  * Author Tolfasn
  9.  */
  10. public class WrapperCalculator {
  11.  
  12.     public static void main(String[] args) {
  13.         //stores starting values
  14.         int walletBalance = 15;
  15.         int barCount = 1;
  16.        
  17.         //loops to calculate the total number of bars
  18.         while(walletBalance > 0){
  19.             barCount ++;
  20.             if(barCount % 3 == 0)
  21.                     walletBalance = walletBalance;
  22.                 else walletBalance --;
  23.             //Displays the current number of candy bars
  24.             System.out.println("You have " + barCount + " candy Bars");
  25.         }
  26.     }
  27.    
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement