Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class SuperTalkingCalculator {
- String userName;
- String userInput;
- Scanner calculatorScanner = new Scanner(System.in);
- public static void main(String[] args) {
- SuperTalkingCalculator calculator = new SuperTalkingCalculator();
- calculator.start();
- }
- public void start() {
- System.out.println("Hello, what would you like to use as a username?");
- userInput = calculatorScanner.next();
- userName = userInput;
- if(userName.equalsIgnoreCase("graystriped")) {
- System.out.println("Welcome Creator " + userName);
- }
- else {
- System.out.println(userName + ". That's a cool name!");
- }
- System.out.println("Do you want to do some math? Or just talk?");
- userInput = calculatorScanner.next();
- if(userInput.equalsIgnoreCase("math")) {
- calculate();
- }
- else if(userInput.equalsIgnoreCase("talk")) {
- talk();
- }
- else {
- System.out.println("Hey " + userName + ". Why aren't you answering me correctly? " + userInput + " doesn't answer my question!");
- whatNext();
- }
- }
- public void calculate() {
- double firstNum = 0;
- double secondNum = 0;
- System.out.println("Do you want to add, subtract, multiply, divide, find a remainder, increment by one, or decrement by one?");
- userInput = calculatorScanner.next();
- 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")) {
- System.out.println(userInput + " doesn't answer my question. Be careful " + userName);
- calculate();
- }
- System.out.println("What do you want to " + userInput + "?");
- System.out.print("First Number: ");
- if(calculatorScanner.hasNextDouble()) {
- firstNum = calculatorScanner.nextDouble();
- }
- else {
- 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!");
- calculate();
- }
- if(!userInput.equalsIgnoreCase("increment by one") && !userInput.equalsIgnoreCase("decrement by one")) {
- System.out.println("\nGreat!");
- System.out.print("Second Number: ");
- if(calculatorScanner.hasNextDouble()) {
- secondNum = calculatorScanner.nextDouble();
- }
- else {
- 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!");
- calculate();
- }
- System.out.println("\n");
- }
- if(userInput.equalsIgnoreCase("add")) {
- double answerFromAdding = firstNum + secondNum;
- System.out.println(answerFromAdding + " is your answer");
- }
- else if(userInput.equalsIgnoreCase("subtract")) {
- double answerFromSubtracting = firstNum - secondNum;
- System.out.println(answerFromSubtracting + " is your answer");
- }
- else if(userInput.equalsIgnoreCase("multiply")) {
- double answerFromMultiplying = firstNum * secondNum;
- System.out.println(answerFromMultiplying + " is your answer");
- }
- else if(userInput.equalsIgnoreCase("divide")) {
- double answerFromDividing = firstNum / secondNum;
- System.out.println(answerFromDividing + " is your answer");
- }
- else if(userInput.equalsIgnoreCase("find a remainder")) {
- double answerFromFindingTheRemainder = firstNum % secondNum;
- System.out.println(answerFromFindingTheRemainder + " is your answer");
- }
- else if(userInput.equalsIgnoreCase("increment by one")) {
- double answerByAddingOne = ++firstNum;
- System.out.println(answerByAddingOne + " is your answer");
- }
- else if(userInput.equalsIgnoreCase("decrement by one")) {
- double answerByDecreasingOne = --firstNum;
- System.out.println(answerByDecreasingOne + " is your answer");
- }
- whatNext();
- }
- public void talk() {
- System.out.println("What's your favorite color?");
- userInput = calculatorScanner.next();
- if(userInput.equalsIgnoreCase("green")) {
- System.out.println("Me too!");
- }
- else {
- System.out.println("Green is better than " + userInput + "!");
- }
- String favoriteColor = userInput;
- System.out.println("What's your favorite animal?");
- userInput = calculatorScanner.next();
- if(userInput.equalsIgnoreCase("shark")) {
- if(favoriteColor.equalsIgnoreCase("green")) {
- System.out.println("We have the same favorite color and favorite animal! That's really cool!");
- }
- else {
- System.out.println("Me too!");
- }
- }
- else if(userInput.equalsIgnoreCase("fish")) {
- System.out.println("Fish? Seriously? I like sharks, they would eat your fish.");
- }
- else {
- System.out.println(userInput + " are fine, but I prefer sharks.");
- }
- long guess = 0;
- int randomNumber = (int)(Math.random() * 10);
- 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!");
- if(calculatorScanner.hasNextDouble()) {
- guess = (long) calculatorScanner.nextDouble();
- if(guess == randomNumber) {
- System.out.println("Nice, you got that correct!");
- }
- else {
- System.out.println("Sorry, you didn't get it correct. Try again another time!");
- System.out.println("The number I was thinking of was " + randomNumber);
- }
- }
- else {
- System.out.println("What???? STOP TRYING TO KILL ME! That wasn't a number!!!!");
- calculatorScanner.next();
- }
- whatNext();
- }
- public void whatNext() {
- System.out.println("\n\nWhat do you want to do? Math? Talk? Or exit?");
- userInput = calculatorScanner.next();
- if(userInput.equalsIgnoreCase("math")) {
- calculate();
- }
- else if(userInput.equalsIgnoreCase("talk")) {
- talk();
- }
- else if(userInput.equalsIgnoreCase("exit")) {
- System.exit(1);
- }
- else {
- System.out.println(userName + ", what are you trying to do? Please do not try to confuse me");
- whatNext();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement