darkuslord98

M&M counter program

Mar 30th, 2013
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.77 KB | None | 0 0
  1. import java.util.Scanner;
  2. //This is a program I wrote to predict the number of M&Ms in a bag based on previous bags.
  3. public class MandMPredictor {
  4. //This is the first program I've written solely by myself. Please comment tips!
  5.     public static void main(String[] args) {
  6.         Scanner keyboard = new Scanner(System.in);
  7.         int  numRed, numBlue, numOrange, numGreen, numBrown, numYellow, totalPrevious, previousBags, previousAdd, finalAdd, finalSubtract;
  8.        
  9.         System.out.println("Welcome, one and all, to the great M&M's calculator!");
  10.         System.out.println("Please Enter the total number of bags opened beforehand.");
  11.         previousBags = keyboard.nextInt(); //Samrg472: Input 0 as the number for previousBags. Watch the system crash XD
  12.         System.out.print("So thats ");
  13.         System.out.print(previousBags);
  14.         System.out.println(" Bags beforehand? Ok, onto the next part.");
  15.        
  16.         System.out.println("How many M&Ms were in the bags? This should be COMBINED, not an average.");
  17.         totalPrevious = keyboard.nextInt();
  18.         System.out.println("Got it! So, there were " + totalPrevious + " M&M's in the previous bags? Ok then! next!");
  19.        
  20.         System.out.println("How many RED M&Ms were there? Again, this should be the total combined, not the average.");
  21.         numRed = keyboard.nextInt();
  22.         System.out.println("How many BLUE M&Ms were there?");
  23.         numBlue = keyboard.nextInt();
  24.         System.out.println("How many ORANGE M&Ms were there?");
  25.         numOrange = keyboard.nextInt();
  26.         System.out.println("How many GREEN M&Ms were there?");
  27.         numGreen = keyboard.nextInt();
  28.         System.out.println("How many BROWN M&Ms were there?");
  29.         numBrown = keyboard.nextInt();
  30.         System.out.println("Last one! How many YELLOW M&M's were there?");
  31.         numYellow = keyboard.nextInt();
  32.         System.out.println("Thank you for the inputs. Beginning processing...");
  33.         numRed = (numRed / previousBags) - 2;
  34.         numBlue = (numBlue / previousBags) - 2;
  35.         numOrange = (numOrange / previousBags) - 2;
  36.         numGreen = (numGreen / previousBags) - 2;
  37.         numBrown = (numBrown / previousBags) - 2;
  38.         numYellow = (numYellow / previousBags) - 2;
  39.         finalAdd = numYellow + numBrown + numGreen + numOrange + numBlue + numRed;
  40.         finalSubtract = (totalPrevious / previousBags) - finalAdd;
  41.         finalAdd = finalAdd + finalSubtract;
  42.         System.out.println("OK! Calculations complete!");
  43.         System.out.println("This machine estimates that there are " + numRed + " Red, " + numBlue + " Blue, " numOrange + " Orange, " + numGreen + " Green, " + numBrown + " Brown, and " + numYellow + "Yellows. There are also" + finalSubtrackt + " Unknown. These are the ones that I cannot calculate precisely." );
  44.         System.out.println();
  45.         System.out.println("All in all, there are " + finalAdd + "M&Ms total.);
  46.         System.out.println("Thank you for using the M&M Predictatron. Code by Matthew Weidenhamer.");
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment