-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInheritannce.java
More file actions
213 lines (171 loc) · 3.43 KB
/
Inheritannce.java
File metadata and controls
213 lines (171 loc) · 3.43 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
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
import java.util.*;
class Players
{
String name;
int age;
int exp;
double weight;
Players()
{
name = "Divyaansh";
age = 19;
exp = 6;
weight = 67.5;
}
}
class Cricket_Player extends Players
{
int runsInCareer;
double avg;
double strikeRate;
Cricket_Player()
{
super();
runsInCareer = 10000;
avg = 58.6;
strikeRate = 130.6;
}
public void display()
{
System.out.println("Name: " + name +"\n"+"Age: "+age+"\n"+"Experience: "+exp+"\n"+"Weight: "+weight+"\n"+"Runs in Career: "+runsInCareer+"\n"+"Average: "+avg+"\n"+"Strike Rate: "+strikeRate+"\n");
}
}
class Football_Player extends Players
{
int goals;
int assists;
Football_Player(int goals, int assists)
{
super();
this.goals = goals;
this.assists = assists;
}
public void display()
{
System.out.println("Name: " + name +"\n"+"Age: "+age+"\n"+"Experience: "+exp+"\n"+"Weight: "+weight+"\n"+"Goals in Career: "+goals+"\n"+"Assits in Career: "+assists+"\n");
}
}
class Hockey_Player extends Players
{
int goals;
int penaltiesTaken;
Hockey_Player(int goals, int penalties)
{
super();
this.goals = goals;
penalties = penaltiesTaken;
}
public void display()
{
System.out.println("Name: " + name +"\n"+"Age: "+age+"\n"+"Experience: "+exp+"\n"+"Weight: "+weight+"\n"+"Goals in Career: "+goals+"\n"+"Penalties in Career: "+penaltiesTaken+"\n");
}
}
public class Solution
{
public static void main(String args[])
{
Cricket_Player myPlayer1 = new Cricket_Player();
Football_Player myPlayer2 = new Football_Player(166,180);
Hockey_Player myPlayer3 = new Hockey_Player(202, 167);
myPlayer1.display();
myPlayer2.display();
myPlayer3.display();
}
}
import java.util.*;
public class Vehicle
{
//private int maxSpeed;
int minSpeed;
boolean isTheCarOn;
public Vehicle()
{
//maxSpeed = 180;
minSpeed = 0;
isTheCarOn = false;
}
}
class Car extends Vehicle
{
String modelType;
String modelName;
String colour;
public Car()
{
super();
modelType = "Hachback";
modelName = "Baleno";
colour = "Blue";
}
public void Display()
{
//Displaying every property
//System.out.println("Max Speed: " + maxSpeed); //Accessing private member of the super class
System.out.println("Min Speed: " + minSpeed);
System.out.println("Is the car on: " + isTheCarOn);
System.out.println("The Model type is: " + modelType);
System.out.println("The Model name is: " + modelName);
System.out.println("The colour is: " + colour);
}
public static void main(String args[])
{
Car myCar = new Car();
myCar.Display();
}
}
//Another problem
import java.util.*;
class Worker
{
String name;
double salary_rate;
double weekPay;
int hours;
Worker(String name, double salary_rate)
{
this.name = name;
this.salary_rate = salary_rate;
}
void ComPay(int hours)
{
this.hours = hours;
weekPay = hours*salary_rate;
System.out.println(weekPay);
}
}
class DailyWorker extends Worker
{
DailyWorker(String D_name,double rate)
{
super(D_name,rate);
}
void ComPay(int hours, int noOfDays)
{
this.hours = hours;
weekPay = hours*noOfDays*salary_rate;
System.out.println(weekPay);
}
}
class SalariedWorker extends Worker
{
SalariedWorker(String D_name,double rate)
{
super(D_name,rate);
}
void ComPay()
{
hours = 40;
weekPay = hours*salary_rate;
System.out.println(weekPay);
}
}
public class WorkerSalary
{
public static void main(String args[])
{
DailyWorker W1 = new DailyWorker("Bhupesh",10.0);
SalariedWorker W2 = new SalariedWorker("Ramu",7.0);
W1.ComPay(9, 6);
W2.ComPay();
}
}