fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Celsius
  9. {
  10. private int value;
  11. private int convertedValue;
  12.  
  13. void setValue(int c)
  14. {
  15. value = c;
  16. convertedValue = (int)((9.0/5.0) * value + 32);
  17. }
  18.  
  19. int getValue()
  20. {
  21. return value;
  22. }
  23.  
  24. int getConvertedValue()
  25. {
  26. return convertedValue;
  27. }
  28. }
  29.  
  30. class Fahrenheit
  31. {
  32. private int value;
  33. private int convertedValue;
  34.  
  35. void setValue(int f)
  36. {
  37. value = f;
  38. convertedValue = (int)((9.0/5.0) * value + 32);
  39. }
  40.  
  41. int getValue()
  42. {
  43. return value;
  44. }
  45.  
  46. int getConvertedValue()
  47. {
  48. return convertedValue;
  49. }
  50. }
  51.  
  52. public class Main
  53. {
  54. public static void main (String[] args) throws IOException
  55. {
  56. BufferedReader stdin = new BufferedReader (inStream);
  57. String inData, choice1, choice2;
  58. int input, c, f;
  59. choice1 = "cel";
  60. choice2 = "fah";
  61.  
  62. System.out.println("Please choose Celsius or Fahrenheit (c for celcius and f for fahrenheit)");
  63. inData = stdin.readLine ( );
  64.  
  65. if (inData.equals(choice1))
  66. {
  67. System.out.println("Enter a value.");
  68. inData = stdin.readLine ( );
  69. c = Integer.parseInt (inData);
  70. Celsius cel = new Celsius();
  71. cel.setValue(c);
  72. System.out.println("The converted value is: " + cel.getConvertedValue());
  73. }
  74.  
  75. if (inData.equals(choice2))
  76. {
  77. System.out.println("Enter a value.");
  78. inData = stdin.readLine ( );
  79. f = Integer.parseInt (inData);
  80. Fahrenheit fah = new Fahrenheit();
  81. fah.setValue(f);
  82. System.out.println("The converted value is: " + fah.getConvertedValue());
  83. }
  84. }
  85. }
Success #stdin #stdout 0.07s 380160KB
stdin
cel
36
stdout
Please choose Celsius or Fahrenheit (c for celcius and f for fahrenheit)
Enter a value.
The converted value is: 96