SciCalculator.java 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import java.util.Scanner;
  2. import java.lang.*;
  3. public class SciCalculator{
  4. public static void main(String[] args){
  5. Scanner stdin = new Scanner(System.in);
  6. boolean isOn = true;
  7. int choice;
  8. Memory memNumber = new Memory();
  9. DisplayVal val = new DisplayVal();
  10. while(isOn){
  11. //display prompt
  12. System.out.println("\n******************************************");
  13. System.out.println(String.format("%"+30+"s", "Scientific Calculator"));
  14. System.out.println("------------------------------------------");
  15. System.out.println(val.valToString(val.getValue()));
  16. System.out.println("==========================================");
  17. System.out.println("Please choose a function (enter # 1-6)");
  18. System.out.println("(1) Input value to calculator");
  19. System.out.println("(2) Execute calculation");
  20. System.out.println("(3) Access memory functions (M+, MC, MRC)");
  21. System.out.println("(4) Change number system (maybe)"); //may link to class
  22. System.out.println("(5) Change units (maybe)"); //may link to class
  23. System.out.println("(6) Clear display");
  24. System.out.println("------------------------------------------");
  25. System.out.println("(7)Quit program");
  26. System.out.println("******************************************");
  27. System.out.print("> ");
  28. choice = stdin.nextInt();
  29. switch(choice){
  30. case 1: System.out.println("Enter the value you want to input to calculator:");//call change units function
  31. System.out.print("> ");
  32. double inVal = stdin.nextDouble();
  33. val.setValue(inVal);
  34. break;
  35. case 2: Operations op = new Operations();
  36. val.setValue(op.chooseOp(val.getValue()));//call operations function
  37. break;
  38. case 3: System.out.println("\n------------------------------------------");
  39. System.out.println("Choose memory function (enter 1 or 2)");
  40. System.out.println("(1) Recall value in memory");
  41. System.out.println("(2) Update value in memory");
  42. System.out.println("------------------------------------------");
  43. System.out.print("> ");
  44. int mem = stdin.nextInt();
  45. if(mem == 1){
  46. val.setValue(memNumber.getMemNum());
  47. }
  48. else if(mem == 2){
  49. memNumber.setMemNum();
  50. }
  51. else{
  52. System.out.println("Value in memory is: " + memNumber.getMemNum());
  53. }
  54. break;
  55. case 4: System.out.println("maybe number systems func");//clear display
  56. break;
  57. case 5: System.out.println("change units function (maybe)");//clear display
  58. break;
  59. case 6: System.out.println("clear display function");
  60. break;
  61. case 7:System.out.println("Goodbye");//clear display
  62. isOn = false;
  63. break;
  64. default:
  65. break;
  66. }
  67. }
  68. }
  69. }