-
Notifications
You must be signed in to change notification settings - Fork 0
/
Q_38.java
151 lines (136 loc) · 3 KB
/
Q_38.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
139
140
141
142
143
144
145
146
147
148
149
150
151
package Q37;
import java.util.Scanner;
class vehicle{
Scanner sc=new Scanner(System.in);
Scanner in=new Scanner(System.in);
int vehicleNo,insuranceNo;
String color;
double average,maint;
double fuel;
void getDetails() {
System.out.println("Enter vehicle no");
vehicleNo=in.nextInt();
System.out.println("Enter insurance no");
insuranceNo=in.nextInt();
System.out.println("Enter color");
color=sc.nextLine();
System.out.println("Enter average");
average=sc.nextDouble();
System.out.println("Enter maintenance");
maint=sc.nextDouble();
}
void getConsumption() {
System.out.println("Enter consumption of vehicle");
fuel=sc.nextDouble();
}
void displayConsumption() {
System.out.println("Consumption="+fuel);
}
}
class twoWheeler extends vehicle{
String type,name;
void average() {
System.out.println("Average of two wheeler vehicle"+average);
}
void maintenance() {
System.out.println("Maintenance of two wheeler vehicle"+maint);
}
void getType() {
System.out.println("Enter the type of company");
type=sc.nextLine();
}
void getName() {
System.out.println("Enter the type of company");
name=sc.nextLine();
}
}
class Geared extends twoWheeler{
void Average() {
double avg;
System.out.println("Enter average of geared two wheeler vehicle");
avg=sc.nextDouble();
System.out.println("Geared Average="+avg);
}
}
class NonGeared extends twoWheeler{
void Average() {
double avg;
System.out.println("Enter average of Non geared two wheeler vehicle");
avg=sc.nextDouble();
System.out.println("Non Geared Average"+avg);
}
}
class fourWheeler extends vehicle{
void average() {
System.out.println("Average of four wheeler vehicle"+average);
}
void maintenance() {
System.out.println("Maintenance of four wheeler vehicle"+maint);
}
}
public class Q_37 {
public static void main(String[] args) {
twoWheeler obj1=new twoWheeler();
fourWheeler obj2=new fourWheeler();
Geared obj3=new Geared();
NonGeared obj4=new NonGeared();
obj1.getDetails();
obj1.getConsumption();
obj1.displayConsumption();
obj1.average();
obj1.maintenance();
obj3.Average();
obj4.Average();
obj2.getDetails();
obj2.getConsumption();
obj2.displayConsumption();
obj2.average();
obj2.maintenance();
obj3.Average();
obj4.Average();
}
}
/*Output
Enter vehicle no
1911
Enter insurance no
3455
Enter color
Blue
Enter average
77.6
Enter maintenance
32.2
Enter consumption of vehicle
12
Consumption=12.0
Average of two wheeler vehicle77.6
Maintenance of two wheeler vehicle32.2
Enter average of geared two wheeler vehicle
66.
Geared Average=66.0
Enter average of Non geared two wheeler vehicle
45.3
Non Geared Average45.3
Enter vehicle no
1923
Enter insurance no
5678
Enter color
Black
Enter average
78.5
Enter maintenance
10
Enter consumption of vehicle
56.4
Consumption=56.4
Average of four wheeler vehicle78.5
Maintenance of four wheeler vehicle10.0
Enter average of geared two wheeler vehicle
65.4
Geared Average=65.4
Enter average of Non geared two wheeler vehicle
43.6
Non Geared Average43.6
*/