Advertisement
irishstorm

ex9d

Nov 19th, 2015
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class ex9d
  4. {
  5. public static void main(String[] args)
  6. {
  7.  
  8. Scanner input = new Scanner(System.in);
  9. int option = 0;
  10. char c;
  11.  
  12. do
  13. {
  14. System.out.print("***** Kilogram / Pound Converter *****\n\n***** [1] Kilogram to Pound : \n***** [2] Pound to Kilogram : ");
  15. option = input.nextInt();
  16.  
  17. switch(option)
  18. {
  19. case 1:
  20. System.out.print("Please enter a Kilogram Value : ");
  21. double a = input.nextDouble();
  22. System.out.print(a + " Kilograms converted to pounds is " + convertKilostoPounds(a));
  23. break;
  24.  
  25. case 2:
  26. System.out.print("Please enter a Pound Value : ");
  27. double b = input.nextDouble();
  28. System.out.print(b + " Kilograms converted to pounds is " + convertPoundstoKilos(b));
  29. break;
  30.  
  31. default:
  32. System.out.print("Incorect Option");
  33. }
  34.  
  35. System.out.print("\nWould you like to convert another value y/n? : ");
  36. c = input.next().charAt(0);
  37.  
  38. }
  39. while( c == 'y' || c == 'Y' );
  40.  
  41. }
  42.  
  43. public static double convertKilostoPounds(double a)
  44. {
  45. double i = a * 2.2;
  46. return Math.round(i * 100.0 ) / 100.0;
  47. }
  48.  
  49. public static double convertPoundstoKilos(double a)
  50. {
  51. double kilos = a / 2.2;
  52. return Math.round(kilos * 100.0 ) / 100.0;
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement