-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavalab14.java
More file actions
52 lines (42 loc) · 1.19 KB
/
Copy pathjavalab14.java
File metadata and controls
52 lines (42 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import java.util.Scanner;
import javax.sound.sampled.SourceDataLine;
abstract class temperature{
double temp;
void setTempData(double par){
temp=par;
}
abstract void changeTemp();
}
class fahreneit extends temperature{
double ctemp;
void changeTemp(){
ctemp = (5.0/9.0)*(temp-32);
System.out.println("Temperature in celsius : " + ctemp + "°C");
}
}
class celsius extends temperature{
double ftemp;
void changeTemp(){
ftemp = (9.0/5.0)*temp+32;
System.out.println("Temperature in fahreneit : " + ftemp + "°F");
}
}
public class javalab14 {
public static void main(String []st){
Scanner sc = new Scanner(System.in);
temperature ob;
fahreneit ob1 = new fahreneit();
celsius ob2 = new celsius();
ob = ob1;
System.out.println("Enter temperature value in fahreneit:");
int Temperature =sc.nextInt();
ob.setTempData(Temperature);
ob.changeTemp();
ob = ob2;
System.out.println("Enter temperature value in celsius:");
Temperature =sc.nextInt();
ob.setTempData(Temperature);
ob.changeTemp();
sc.close();
}
}