-
Notifications
You must be signed in to change notification settings - Fork 0
/
p9.java
49 lines (38 loc) · 1.19 KB
/
p9.java
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
import java.util.*;
interface Compute {
void convert();
}
class BytesConverter implements Compute{
int gb;
BytesConverter(int gb) {
this.gb = gb;
}
public void convert() {
long bytes = (long)(gb*1024.0*1024.0*1024.0);
System.out.println(bytes + " bytes is equal to " + bytes + " kilobytes.");
}
}
class CurrencyConverter implements Compute {
double euros;
CurrencyConverter(double euros) {
this.euros = euros;
}
public void convert() {
double rupees = euros * 90.0;
System.out.println(euros + " euros is equal to " + rupees + " rupees.");
}
}
public class p9 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the number of gigabytes: ");
int gb = scanner.nextInt();
BytesConverter bytesConverter = new BytesConverter(gb);
bytesConverter.convert();
System.out.print("Enter the amount in euros: ");
double eurosInput = scanner.nextDouble();
CurrencyConverter currencyConverter = new CurrencyConverter(eurosInput);
currencyConverter.convert();
scanner.close();
}
}