Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- /**
- * Cooties class draws a cootie based on dice roll input.
- *
- * @author Ayan Patel
- * @author Ryan Cook
- * @author J. Dalbey
- * @version 1.1
- */
- public class Cooties_functional
- {
- /**
- * The entry point for this application
- * @param args (ignored)
- */
- public static void main(String[] args)
- {
- // parts of a cootie
- int i = 0;
- int numLegs = 0;
- int maxLegs = 6;
- int numEyes = 0;
- int maxEyes = 2;
- int head = 0;
- int numAnt = 0;
- int maxAnt = 2;
- int tail = 0;
- int body = 0;
- boolean done = false;
- boolean error = false;
- int diceRoll = 0;
- int turns = 0;
- //Create a scanner to read from standard input
- Scanner console = new Scanner(System.in);
- //Loop until cootie is done
- while (!done)
- {
- error = false;
- //Get input from user
- System.out.println(" Input dice roll: ");
- diceRoll = console.nextInt();
- //If input is body
- if (diceRoll == 1)
- {
- if (body == 0)
- {
- body = 1;
- }
- else
- {
- error = true;
- }
- }
- //If input is head
- else if (diceRoll == 2)
- {
- if (body == 1 && head == 0)
- {
- head = 1;
- }
- else
- {
- error = true;
- }
- }
- //If input is leg
- else if (diceRoll == 3)
- {
- if (body == 1 && numLegs < maxLegs)
- {
- numLegs += 1;
- }
- else
- {
- error = true;
- }
- }
- //If input is antenna
- else if (diceRoll == 4)
- {
- if (head >= 1 && numAnt < maxAnt)
- {
- numAnt += 1;
- }
- else
- {
- error = true;
- }
- }
- //If input is eyes
- else if (diceRoll == 5)
- {
- if (head >= 1 && numEyes < maxEyes)
- {
- numEyes += 1;
- }
- else
- {
- error = true;
- }
- }
- //If input is tail
- else if (diceRoll == 6)
- {
- if (body == 1 && tail == 0)
- {
- tail = 1;
- }
- else
- {
- error = true;
- }
- }
- else
- {
- System.out.println(" Invalid input.");
- }
- // Print the current cootie
- // Print antenna
- String antOut = "";
- if (numAnt > 0)
- {
- antOut += " !";
- }
- if (numAnt == 2)
- {
- antOut += " !";
- }
- System.out.println(antOut);
- // Print head and eys
- String headOut = "";
- if (head >= 1)
- {
- headOut += " (";
- }
- if (numEyes > 0)
- {
- headOut += "o ";
- }
- else
- {
- headOut += " ";
- }
- if (numEyes == 2)
- {
- headOut += "o";
- }
- else
- {
- headOut += " ";
- }
- if (head >= 1)
- {
- headOut += ")";
- }
- System.out.println(headOut);
- //loop unitl all legs are created
- for (i = 0; i < maxLegs; i = i + 2)
- {
- String bodyOut = "";
- if (numLegs > i)
- {
- bodyOut += "- ";
- }
- else
- {
- bodyOut += " ";
- }
- if (body == 1)
- {
- bodyOut += "[ ]";
- }
- if (numLegs > i + 1)
- {
- bodyOut += " - ";
- }
- else
- {
- bodyOut += " ";
- }
- System.out.println(bodyOut);
- }
- //Create tail
- if (tail == 1)
- {
- System.out.println(" T");
- }
- // A part could not be added with that roll.
- if (error)
- {
- System.out.println(" Can't add a part. \n");
- }
- turns += 1;
- //Once everything is complete, display message
- if (body == 1 && numLegs == maxLegs && numEyes == maxEyes && numAnt == maxAnt && tail == 1)
- {
- System.out.println(" Congratulations you have completed your cootie!");
- System.out.println(" It took you " + turns + " turns to finish your cootie. ");
- done = true;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement