-
Notifications
You must be signed in to change notification settings - Fork 0
/
vehicle_car_truck.java
138 lines (118 loc) · 3.75 KB
/
vehicle_car_truck.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package inheritance_interface;
import java.util.Scanner;
class vehicle{
// instance variables
String[] type= {"car","truck"};
int[] weight= {2,100};
// print details
public void show_vehicle() {
System.out.println("\n[+] We have :");
for(int i=0;i<type.length;i++) {
System.out.println("\t~ "+type[i]+"'s of weight starting from "+weight[i]+" tons");
}
}
// cost details
public void cost(String[] cost) {
System.out.println("[*] cost between "+cost[0]+" & "+cost[1]);
}
}
class car extends vehicle{
// instance variables
int lower;
int higher;
// print details
public void show_car(String[][] car) {
System.out.println("\n[+] We have :");
lower=Integer.valueOf(car[0][3]);
higher=Integer.valueOf(car[0][3]);
for(int i=0;i<5;i++) {
System.out.println("\t~ "+car[i][0]+" "+car[i][1]+" manufactured in "+car[i][2]+" costing "+car[i][3]+" giving a mileage of "+car[i][4]);
if (Integer.valueOf(car[i][3])<lower) {
lower=Integer.valueOf(car[i][3]);
}
else if (Integer.valueOf(car[i][3])>higher) {
higher=Integer.valueOf(car[i][3]);
}
else {continue;}
}
// super
String[] cost = {String.valueOf(lower),String.valueOf(higher)};
super.cost(cost);
}
// mileage
public void mileage(String[][] car) {
System.out.println("\n[+] Cars with mileage >30:");
for(int i=0;i<5;i++) {
if (Integer.valueOf(car[i][4])>30) {
System.out.println("\t~ "+car[i][0]+" "+car[i][1]+" has a mileage of "+car[i]);
}
}
}
}
class truck extends vehicle{
// instance variables
int lower;
int higher;
// print details
public void show_truck(String[][] truck) {
System.out.println("\n[+] We have :");
lower=Integer.valueOf(truck[0][3]);
higher=Integer.valueOf(truck[0][3]);
for(int i=0;i<5;i++) {
System.out.println("\t~ "+truck[i][0]+" "+truck[i][1]+" manufactured in "+truck[i][2]+" costing "+truck[i][3]+" giving a mileage of "+truck[i][4]);
if (Integer.valueOf(truck[i][3])<lower) {
lower=Integer.valueOf(truck[i][3]);
}
else if (Integer.valueOf(truck[i][3])>higher) {
higher=Integer.valueOf(truck[i][3]);
}
else {continue;}
}
// super
String[] cost = {String.valueOf(lower),String.valueOf(higher)};
super.cost(cost);
}
}
public class vehicle_car_truck {
public static void main(String[] args) {
System.out.println("*************** Hello 18BCI0174 - Aryan ****************");
vehicle obj=new vehicle();
obj.show_vehicle();
Scanner sc=new Scanner(System.in);
System.out.println("\n------------In cars we have------------");
String[][] car= new String[5][5];
for(int i=0;i<5;i++) {
System.out.println("Enter Company: ");
car[i][0]=sc.nextLine();
System.out.println("Enter Model: ");
car[i][1]=sc.nextLine();
System.out.println("Enter year of manu.: ");
car[i][2]=sc.nextLine();
System.out.println("Enter cost: ");
car[i][3]=sc.nextLine();
System.out.println("Enter mileage: ");
car[i][4]=sc.nextLine();
System.out.println("-----------------");
}
System.out.println("\n------------In trucks we have------------");
String[][] truck= new String[5][5];
for(int i=0;i<5;i++) {
System.out.println("Enter Company: ");
truck[i][0]=sc.nextLine();
System.out.println("Enter Model: ");
truck[i][1]=sc.nextLine();
System.out.println("Enter year of manu.: ");
truck[i][2]=sc.nextLine();
System.out.println("Enter cost: ");
truck[i][3]=sc.nextLine();
System.out.println("Enter mileage: ");
truck[i][4]=sc.nextLine();
System.out.println("-----------------");
}
car obj1=new car();
obj1.show_car(car);
obj1.mileage(car);
truck obj2=new truck();
obj2.show_truck(truck);
}
}