-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCar.java
More file actions
50 lines (48 loc) · 2.08 KB
/
Car.java
File metadata and controls
50 lines (48 loc) · 2.08 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
public class Car {
String manufacturer;
int price;
Car(String manufacturer,int price){
this.manufacturer = manufacturer;
this.price = price;
}
public static void main(String[] args) {
Car obj1 = new Car("Tesla", 2500000);
Car obj2 = new Car("Tata", 400000);
Car obj3 = new Car("Maruti", 300000);
if (obj1.price > obj2.price) {
if (obj2.price > obj3.price) {
System.out.println(obj1.price + " " + obj1.manufacturer);
System.out.println(obj2.price + " " + obj2.manufacturer);
System.out.println(obj3.price + " " + obj3.manufacturer);
} else if (obj3.price > obj1.price) {
System.out.println(obj3.price + " " + obj3.manufacturer);
System.out.println(obj1.price + " " + obj1.manufacturer);
System.out.println(obj2.price + " " + obj2.manufacturer);
}
}
else if(obj2.price>obj1.price){
if(obj1.price>obj3.price){
System.out.println(obj2.price+" "+obj2.manufacturer);
System.out.println(obj1.price+" "+obj1.manufacturer);
System.out.println(obj3.price+" "+obj3.manufacturer);
}
else if(obj3.price> obj2.price){
System.out.println(obj3.price+" "+obj3.manufacturer);
System.out.println(obj2.price+" "+obj2.manufacturer);
System.out.println(obj1.price+" "+obj1.manufacturer);
}
}
else{
if(obj1.price>obj3.price){
System.out.println(obj1.price+" "+obj1.manufacturer);
System.out.println(obj3.price+" "+obj3.manufacturer);
System.out.println(obj2.price+" "+obj2.manufacturer);
}
else{
System.out.println(obj3.price+" "+obj3.manufacturer);
System.out.println(obj2.price+" "+obj2.manufacturer);
System.out.println(obj1.price+" "+obj1.manufacturer);
}
}
}
}