Advertisement
Graystriped

Talking Calculator V3

May 25th, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.50 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3.  
  4. public class SuperTalkingCalculator {
  5.    
  6.     String userName;
  7.     String userInput;
  8.     Scanner calculatorScanner = new Scanner(System.in);
  9.    
  10.    
  11.     public static void main(String[] args) {
  12.         SuperTalkingCalculator calculator = new SuperTalkingCalculator();
  13.         calculator.start();
  14.  
  15.     }
  16.    
  17.     public void start() {
  18.         System.out.println("Hello, what would you like to use as a username?");
  19.        
  20.         userInput = calculatorScanner.next();
  21.        
  22.         userName = userInput;
  23.        
  24.         if(userName.equalsIgnoreCase("graystriped")) {
  25.             System.out.println("Welcome Creator " + userName);
  26.         }
  27.        
  28.         else {
  29.             System.out.println(userName + ". That's a cool name!");
  30.         }
  31.        
  32.         System.out.println("Do you want to do some math? Or just talk?");
  33.        
  34.         userInput = calculatorScanner.next();
  35.        
  36.         if(userInput.equalsIgnoreCase("math")) {
  37.             calculate();
  38.         }
  39.        
  40.         else if(userInput.equalsIgnoreCase("talk")) {
  41.             talk();
  42.         }
  43.        
  44.         else {
  45.             System.out.println("Hey " + userName + ". Why aren't you answering me correctly? " + userInput + " doesn't answer my question!");
  46.             whatNext();
  47.         }
  48.     }
  49.    
  50.     public void calculate() {
  51.         double firstNum = 0;
  52.         double secondNum = 0;
  53.        
  54.        
  55.         System.out.println("Do you want to add, subtract, multiply, divide, find a remainder, increment by one, or decrement by one?");
  56.        
  57.         userInput = calculatorScanner.next();
  58.        
  59.        
  60.         if(!userInput.equalsIgnoreCase("add") && !userInput.equalsIgnoreCase("subtract") && !userInput.equalsIgnoreCase("multiply") && !userInput.equalsIgnoreCase("divide") && !userInput.equalsIgnoreCase("find a remainder") && !userInput.equalsIgnoreCase("increment by one") && !userInput.equalsIgnoreCase("decrement by one")) {
  61.             System.out.println(userInput + " doesn't answer my question. Be careful " + userName);
  62.             calculate();
  63.         }
  64.        
  65.         System.out.println("What do you want to " + userInput + "?");
  66.        
  67.         System.out.print("First Number: ");
  68.        
  69.        
  70.         if(calculatorScanner.hasNextDouble()) {
  71.             firstNum = calculatorScanner.nextDouble();
  72.         }
  73.        
  74.         else {
  75.             System.out.println(userName + ", do you hate me? If I didn't see that it could've killed me! " + calculatorScanner.next() + " is not a number!");
  76.             calculate();
  77.         }
  78.        
  79.         if(!userInput.equalsIgnoreCase("increment by one") && !userInput.equalsIgnoreCase("decrement by one")) {
  80.             System.out.println("\nGreat!");
  81.            
  82.             System.out.print("Second Number: ");
  83.            
  84.            
  85.            
  86.             if(calculatorScanner.hasNextDouble()) {
  87.                 secondNum = calculatorScanner.nextDouble();
  88.             }
  89.            
  90.             else {
  91.                 System.out.println(userName + ", do you hate me? If I didn't see that it could've killed me! " + calculatorScanner.next() + " is not a number!");
  92.                
  93.                 calculate();
  94.                
  95.             }
  96.            
  97.             System.out.println("\n");
  98.         }
  99.        
  100.         if(userInput.equalsIgnoreCase("add")) {
  101.             double answerFromAdding = firstNum + secondNum;
  102.            
  103.             System.out.println(answerFromAdding + " is your answer");
  104.         }
  105.         else if(userInput.equalsIgnoreCase("subtract")) {
  106.             double answerFromSubtracting = firstNum - secondNum;
  107.            
  108.             System.out.println(answerFromSubtracting + " is your answer");
  109.         }
  110.         else if(userInput.equalsIgnoreCase("multiply")) {
  111.             double answerFromMultiplying = firstNum * secondNum;
  112.            
  113.             System.out.println(answerFromMultiplying + " is your answer");
  114.         }
  115.         else if(userInput.equalsIgnoreCase("divide")) {
  116.             double answerFromDividing = firstNum / secondNum;
  117.            
  118.             System.out.println(answerFromDividing + " is your answer");
  119.         }
  120.         else if(userInput.equalsIgnoreCase("find a remainder")) {
  121.             double answerFromFindingTheRemainder = firstNum % secondNum;
  122.            
  123.             System.out.println(answerFromFindingTheRemainder + " is your answer");
  124.         }
  125.         else if(userInput.equalsIgnoreCase("increment by one")) {
  126.             double answerByAddingOne = ++firstNum;
  127.            
  128.             System.out.println(answerByAddingOne + " is your answer");
  129.         }
  130.         else if(userInput.equalsIgnoreCase("decrement by one")) {
  131.             double answerByDecreasingOne = --firstNum;
  132.            
  133.             System.out.println(answerByDecreasingOne + " is your answer");
  134.         }
  135.        
  136.         whatNext();
  137.        
  138.     }
  139.    
  140.     public void talk() {
  141.         System.out.println("What's your favorite color?");
  142.        
  143.         userInput = calculatorScanner.next();
  144.        
  145.         if(userInput.equalsIgnoreCase("green")) {
  146.             System.out.println("Me too!");
  147.         }
  148.         else {
  149.             System.out.println("Green is better than " + userInput + "!");
  150.         }
  151.        
  152.         String favoriteColor = userInput;
  153.        
  154.         System.out.println("What's your favorite animal?");
  155.        
  156.         userInput = calculatorScanner.next();
  157.        
  158.        
  159.         if(userInput.equalsIgnoreCase("shark")) {
  160.             if(favoriteColor.equalsIgnoreCase("green")) {
  161.                 System.out.println("We have the same favorite color and favorite animal! That's really cool!");
  162.             }
  163.             else {
  164.                 System.out.println("Me too!");
  165.             }
  166.            
  167.         }
  168.        
  169.         else if(userInput.equalsIgnoreCase("fish")) {
  170.             System.out.println("Fish? Seriously? I like sharks, they would eat your fish.");
  171.         }
  172.        
  173.         else {
  174.             System.out.println(userInput + " are fine, but I prefer sharks.");
  175.         }
  176.        
  177.         long guess = 0;
  178.        
  179.         int randomNumber = (int)(Math.random() * 10);
  180.        
  181.        
  182.         System.out.println("I have a number between 0 and 10 in my mind. Can you find it out? I will die if you enter anything that isn't a number!");
  183.        
  184.         if(calculatorScanner.hasNextDouble()) {
  185.             guess = (long) calculatorScanner.nextDouble();
  186.            
  187.            
  188.             if(guess == randomNumber) {
  189.                 System.out.println("Nice, you got that correct!");
  190.             }
  191.            
  192.             else {
  193.                 System.out.println("Sorry, you didn't get it correct. Try again another time!");
  194.                
  195.                 System.out.println("The number I was thinking of was " + randomNumber);
  196.             }
  197.         }
  198.        
  199.         else {
  200.             System.out.println("What???? STOP TRYING TO KILL ME! That wasn't a number!!!!");
  201.            
  202.             calculatorScanner.next();
  203.         }
  204.        
  205.         whatNext();
  206.        
  207.     }
  208.    
  209.     public void whatNext() {
  210.        
  211.         System.out.println("\n\nWhat do you want to do? Math? Talk? Or exit?");
  212.        
  213.         userInput = calculatorScanner.next();
  214.        
  215.        
  216.        
  217.         if(userInput.equalsIgnoreCase("math")) {
  218.             calculate();
  219.         }
  220.        
  221.         else if(userInput.equalsIgnoreCase("talk")) {
  222.             talk();
  223.         }
  224.        
  225.        
  226.         else if(userInput.equalsIgnoreCase("exit")) {
  227.             System.exit(1);
  228.         }
  229.        
  230.         else {
  231.             System.out.println(userName + ", what are you trying to do? Please do not try to confuse me");
  232.            
  233.             whatNext();
  234.         }
  235.     }
  236.  
  237. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement