Console.java 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import java.util.*;
  2. import java.lang.*;
  3. /**
  4. * Created by leon on 2/9/18.
  5. */
  6. public class Console {
  7. //Saves the input in the next open slot of the array
  8. public static void SaveParameter(String s, String[] b){
  9. for(int i = 0; i < b.length; i++){
  10. if(b[i].equals("0")){
  11. b[i] = s;
  12. break;
  13. }
  14. }
  15. }
  16. //Saves the input in the next open slot of the array
  17. public static void SaveParameter(Double s, Double[] b){
  18. for(int i = 0; i < b.length; i++){
  19. if(b[i] == null){
  20. b[i] = s;
  21. break;
  22. }
  23. }
  24. }
  25. //Shifts the elements of the array back one position starting from the i position
  26. public static void ArrShifter(int i , String[] op, Double[] num ){
  27. for(int j = (i+1); j < num.length -1; j++){
  28. num[j] = num[j + 1];
  29. }
  30. for(int j = i; j < num.length -1; j++){
  31. op[j] = op[j + 1];
  32. }
  33. }
  34. public static void DeleteOp(int i, String[] op){
  35. for(int j = i; j < op.length -1; j++){
  36. op[j] = op[j + 1];
  37. }
  38. }
  39. //Displays the elements of the arrays in alternating order.
  40. public static void DisplayCurrent(Double[]num, String[]op){
  41. for(int i = 0; i < num.length; i++){
  42. if(num[i] != null){
  43. System.out.print(String.format("%s ",num[i]));
  44. }
  45. if(!op[i].equals("0")){
  46. System.out.print(String.format("%s ",op[i]));
  47. }
  48. }
  49. System.out.print("\n");
  50. }
  51. public static void print(String output, Object... args) {
  52. System.out.printf(output, args);
  53. }
  54. public static void println(String output, Object... args) {
  55. print(output + "\n", args);
  56. }
  57. public static String getStringInput(String prompt) {
  58. Scanner scanner = new Scanner(System.in);
  59. println(prompt);
  60. String userInput = scanner.nextLine();
  61. return userInput;
  62. }
  63. public static Integer getIntegerInput(String prompt) {
  64. return null;
  65. }
  66. public static Double getDoubleInput(String prompt) {
  67. Scanner scanner = new Scanner(System.in);
  68. println(prompt);
  69. Double userInput = scanner.nextDouble();
  70. return userInput;
  71. }
  72. }