Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. import java.io.IOException;
  2. import java.io.*;
  3. import java.util.Scanner;
  4.  
  5. public class Menu {
  6. Scanner scan = new Scanner(System.in);
  7. int selection;
  8.  
  9. public int GetSelection()
  10. {
  11. selection = scan.nextInt();
  12. return selection;
  13. }
  14.  
  15. public void display()
  16. {
  17.  
  18. System.out.println("Please choose an option from the following:");
  19. System.out.println("[1] Convert Decimal to Binary");
  20. System.out.println("[2] Convert Decimal to Hexadecimal");
  21. System.out.println("[3] Convert Binary to Decimal");
  22. System.out.println("[4] Convert Binary to Hexadecimal");
  23. System.out.println("[5] Convert Hexadecimal to Decimal");
  24. System.out.println("[6] Convert Hexadecimal to Binary");
  25. System.out.println("[0] Exit");
  26.  
  27. System.out.println("n");
  28. System.out.println("You entered: " + selection);
  29. }
  30.  
  31. }
  32.  
  33.  
  34. ----------------------------
  35. import java.io.*;
  36. import java.lang.*;
  37. import java.util.Scanner;
  38.  
  39.  
  40. public class Driver
  41. {
  42.  
  43. public static void main(String[] args)throws IOException {
  44.  
  45. LineWriter lw = new LineWriter("csis.txt");
  46. int selection;
  47.  
  48. Decimal dec = new Decimal();
  49. Binary bin = new Binary();
  50. Hexadecimal hex = new Hexadecimal();
  51. Menu menu = new Menu();
  52.  
  53.  
  54. do{
  55. menu.display();
  56.  
  57. selection=menu.GetSelection();
  58.  
  59. switch (selection){
  60.  
  61. case '1':{ dec.getDec();
  62. break;}
  63. case '2':{ dec.getHex();
  64. break;}
  65. case '3':{ bin.getBin();
  66. break;}
  67. case '4':{ bin.getHex();
  68. break;}
  69. case '5':{ hex.getHex();
  70. break;}
  71. case '6': { hex.getDec();
  72. break; }
  73. //default: System.out.println("Error: Unrecognized Selection");
  74. // break;
  75.  
  76. }
  77. }while (selection !=0);
  78. }
  79. }
  80.  
  81. switch(selection){
  82.  
  83. case '1':
  84. System.out.println("Hello World from char");
  85. break;
  86.  
  87. case 1:
  88. System.out.println("Hello World from int");
  89. break;
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement