Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- //This is a program I wrote to predict the number of M&Ms in a bag based on previous bags.
- public class MandMPredictor {
- //This is the first program I've written solely by myself. Please comment tips!
- public static void main(String[] args) {
- Scanner keyboard = new Scanner(System.in);
- int numRed, numBlue, numOrange, numGreen, numBrown, numYellow, totalPrevious, previousBags, previousAdd, finalAdd, finalSubtract;
- System.out.println("Welcome, one and all, to the great M&M's calculator!");
- System.out.println("Please Enter the total number of bags opened beforehand.");
- previousBags = keyboard.nextInt(); //Samrg472: Input 0 as the number for previousBags. Watch the system crash XD
- System.out.print("So thats ");
- System.out.print(previousBags);
- System.out.println(" Bags beforehand? Ok, onto the next part.");
- System.out.println("How many M&Ms were in the bags? This should be COMBINED, not an average.");
- totalPrevious = keyboard.nextInt();
- System.out.println("Got it! So, there were " + totalPrevious + " M&M's in the previous bags? Ok then! next!");
- System.out.println("How many RED M&Ms were there? Again, this should be the total combined, not the average.");
- numRed = keyboard.nextInt();
- System.out.println("How many BLUE M&Ms were there?");
- numBlue = keyboard.nextInt();
- System.out.println("How many ORANGE M&Ms were there?");
- numOrange = keyboard.nextInt();
- System.out.println("How many GREEN M&Ms were there?");
- numGreen = keyboard.nextInt();
- System.out.println("How many BROWN M&Ms were there?");
- numBrown = keyboard.nextInt();
- System.out.println("Last one! How many YELLOW M&M's were there?");
- numYellow = keyboard.nextInt();
- System.out.println("Thank you for the inputs. Beginning processing...");
- numRed = (numRed / previousBags) - 2;
- numBlue = (numBlue / previousBags) - 2;
- numOrange = (numOrange / previousBags) - 2;
- numGreen = (numGreen / previousBags) - 2;
- numBrown = (numBrown / previousBags) - 2;
- numYellow = (numYellow / previousBags) - 2;
- finalAdd = numYellow + numBrown + numGreen + numOrange + numBlue + numRed;
- finalSubtract = (totalPrevious / previousBags) - finalAdd;
- finalAdd = finalAdd + finalSubtract;
- System.out.println("OK! Calculations complete!");
- 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." );
- System.out.println();
- System.out.println("All in all, there are " + finalAdd + "M&Ms total.);
- System.out.println("Thank you for using the M&M Predictatron. Code by Matthew Weidenhamer.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment