Advertisement
Guest User

Untitled

a guest
Oct 26th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.06 KB | None | 0 0
  1. package com.jurajmlich;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.  
  7. public static void main(String[] args) {
  8. Scanner scanner = new Scanner(System.in);
  9. System.out.println("Welcome to my calculator");
  10. Boolean shouldContinueAsking = true;
  11. while (shouldContinueAsking) {
  12. System.out.println("State your username");
  13. String username = scanner.next();
  14. System.out.println("Insert your password");
  15. String password = scanner.next();
  16.  
  17. if (username.equals("sona") && password.equals("sona123")) {
  18. shouldContinueAsking = false;
  19. } else {
  20. System.out.println("Username or password incorrect, try again");
  21. }
  22. }
  23.  
  24. while (true) {
  25. System.out.println("Insert the first number");
  26. Double firstNumber = scanner.nextDouble();
  27. System.out.println("Insert the second number");
  28. Double secondNumber = scanner.nextDouble();
  29. System.out.println("Decide which operation you would like me to do. Write the words multiply or divide or add or subtract.. ");
  30.  
  31. Boolean correct = false;
  32. while (!correct) {
  33. String operation = scanner.next();
  34. if (operation.equals("multiply")) {
  35. Double multiplication = firstNumber * secondNumber;
  36. System.out.println(multiplication);
  37. correct = true;
  38. } else if (operation.equals("divide")) {
  39. Double division = firstNumber / secondNumber;
  40. System.out.println(division);
  41. correct = true;
  42. } else if (operation.equals("add")) {
  43. Double addition = firstNumber + secondNumber;
  44. System.out.println(addition);
  45. correct = true;
  46. } else if (operation.equals("subtract")) {
  47. Double subtraction = firstNumber - secondNumber;
  48. System.out.println(subtraction);
  49. correct = true;
  50. } else {
  51. System.out.println("You dumb piece of shit");
  52. correct = false;
  53. System.out.println("Try again");
  54. }
  55. }
  56. System.out.println("Proceed to the next operation");
  57.  
  58. }
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66. /*
  67. // write out a message
  68. System.out.println("sonicka sa uz trapi");
  69.  
  70.  
  71. // read from console
  72. Integer firstNumber = scanner.nextInt();
  73. Integer secondNumber = scanner.nextInt();
  74. Integer result = firstNumber * secondNumber;
  75. String xenon = "ahoj Juri";
  76.  
  77. if (firstNumber > 10) {
  78. System.out.println("the number is bigger than 10");
  79. }
  80.  
  81. // write the result of 89 + 57
  82. System.out.println(result);
  83. System.out.println(xenon);
  84.  
  85. */
  86.  
  87. }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement