Advertisement
Guest User

Untitled

a guest
Oct 5th, 2012
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.86 KB | None | 0 0
  1. //Converter from degrees Fahrenheit to degrees Celsius.
  2. import java.util.*;
  3.  
  4. class Temperature {
  5.     private double f_temp;
  6.     public double setFahrenheit(double x) {
  7.     f_temp = x;
  8.     }
  9.    
  10.     private double c_temp;
  11.     public double setCelsius(double y) {
  12.     c_temp = y;
  13.     }
  14.  
  15.     //Converstion to degrees Fahrenheit
  16.     public double toFahrenheit() {
  17.     return c_temp = (y * 1.8) + 32;
  18.         }
  19.    
  20.     //Converstion to degrees Celsius
  21.     public double toCelsius() {
  22.     return f_temp = (x - 32)/1.8;
  23.         }
  24. }
  25.  
  26. class Question7 {
  27.     public static void main (String[ ] args) {
  28.     Scanner question7;
  29. question7 = new Scanner(System.in);
  30.    
  31.     //Fahrenheit Input
  32.     Temperature temp = new Temperature();
  33.     System.out.print ("Enter a temperature in degrees Fahrenheit: " );
  34.     double input = question7.nextDouble();
  35.     temp.setFahrenheit(input);
  36.     temp.toCelsius();
  37.     System.out.println(input.toCelsius);
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement