Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2014
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. public static void main(String[] args) {
  2. System.out.println("please enter the two two integer values that you want"
  3. + " to vomplete the operation with ");
  4. Scanner scan = new Scanner(System.in);
  5. int first = scan.nextInt();
  6. int sec = scan.nextInt();
  7. System.out.println(" please enter the operation you want preformed");
  8. String opera = scan.next();
  9. System.out.println(" Here is the answer");
  10. int value = Acalc(opera, first, sec);
  11. String roman = Roman(value);
  12. System.out.println(" Here is the answer in roman numerals ");
  13. System.out.println(roman);
  14.  
  15. }
  16.  
  17. public static int Acalc(String opera, int n1, int n2){
  18. int result = 0;
  19. //Write the calulator
  20.  
  21. if (opera.equals("+"))
  22. {result=n1+n2;}
  23.  
  24. if (opera.equals("-"))
  25. { result=n1-n2;}
  26.  
  27. if (opera.equals("*"))
  28. {result=n1*n2;}
  29.  
  30. if (opera.equals("/"))
  31. {result=n1/n2;}
  32.  
  33. System.out.println(result);
  34.  
  35.  
  36.  
  37. return result;
  38. }
  39.  
  40. public static String Roman(double input){
  41.  
  42. String s = "";
  43.  
  44. if (input <1 || input < 999)
  45. System.out.println("negative roman numeral value ");
  46.  
  47. while (input >= 100) {
  48. s += "C";
  49. input -= 100;
  50. }
  51. while (input >= 90) {
  52.  
  53. s += "XC";
  54. input -= 90;
  55. }
  56. while (input >= 50) {
  57. s += "L";
  58. input -= 50;
  59. }
  60. while (input >= 40) {
  61. s += "XL";
  62. input -= 40;
  63. }
  64. while (input >= 10) {
  65. s += "X";
  66. input -= 10;
  67. }
  68. while (input >= 9) {
  69. s += "IX";
  70. input -= 9;
  71. }
  72. while (input >= 5) {
  73. s += "V";
  74. input -= 5;
  75. }
  76. while (input >= 4) {
  77. s += "IV";
  78. input -= 4;
  79. }
  80. while (input >= 1) {
  81. s += "I";
  82. input -= 1;
  83. }
  84. return s;
  85.  
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement