-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSolution.java
More file actions
110 lines (87 loc) · 5.21 KB
/
Solution.java
File metadata and controls
110 lines (87 loc) · 5.21 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
//So then, let us follow after things which make for peace, and things by which we may build one another up. (Romans 14:19)
package com.javarush.task.task15.task1503;
/*
ООП - машинки
*/
public class Solution {
public static void main(String[] args) {
new Solution.LuxuriousCar().printlnDesire();
new Solution.CheapCar().printlnDesire();
new Solution.Ferrari().printlnDesire();
new Solution.Lanos().printlnDesire();
}
public static class Ferrari extends LuxuriousCar {
public void printlnDesire() {
System.out.println(Constants.WANT_STRING + Constants.FERRARI_NAME);}//add your code here
}
public static class Lanos extends CheapCar {
public void printlnDesire() {
System.out.println(Constants.WANT_STRING + Constants.LANOS_NAME);}//add your code here
}
public static class Constants {
public static String WANT_STRING = "Я хочу ездить на ";
public static String LUXURIOUS_CAR = "роскошной машине";
public static String CHEAP_CAR = "дешевой машине";
public static String FERRARI_NAME = "Феррари";
public static String LANOS_NAME = "Ланосе";
}
public static class LuxuriousCar {
protected void printlnDesire() {
System.out.println(Constants.WANT_STRING + Constants.LUXURIOUS_CAR);}//add your code here
}
public static class CheapCar {
protected void printlnDesire() {
System.out.println(Constants.WANT_STRING + Constants.CHEAP_CAR);}//add your code here
}
}
/*
ООП - машинки
1. Для вывода используй только переменные из класса Constants.
2. В классе Ferrari реализуйте метод printlnDesire, чтобы он выводил на экран «Я хочу ездить на Феррари«.
3. В классе Lanos реализуйте метод printlnDesire, чтобы он выводил на экран «Я хочу ездить на Ланосе«.
4. Создайте public static класс LuxuriousCar(РоскошнаяМашина).
5. Создайте public static класс CheapCar(ДешеваяМашина).
6. Унаследуйте Ferrari и Lanos от CheapCar и LuxuriousCar, подумайте, какой класс для кого.
7. В классе LuxuriousCar реализуйте метод printlnDesire, чтобы он выводил на экран «Я хочу ездить на роскошной машине«.
8. В классе CheapCar реализуйте метод printlnDesire, чтобы он выводил на экран «Я хочу ездить на дешевой машине«.
9. В классах LuxuriousCar и CheapCar для метода printlnDesire расставьте различными способами модификаторы доступа так, чтобы в классах Ferrari и Lanos выполнялось расширение видимости.
Требования:
1. Класс Solution должен содержать public static класс LuxuriousCar.
2. Класс Solution должен содержать public static класс CheapCar.
3. Класс Ferrari должен быть потомком класса LuxuriousCar.
4. Класс Lanos должен быть потомком класса CheapCar.
5. Метод printlnDesire в классе LuxuriousCar, должен выводить на экран фразу "Я хочу ездить на роскошной машине".
6. Метод printlnDesire в классе CheapCar, должен выводить на экран фразу "Я хочу ездить на дешевой машине".
7. Метод printlnDesire в классе Ferrari, должен выводить на экран фразу "Я хочу ездить на Феррари".
8. Метод printlnDesire в классе Lanos, должен выводить на экран фразу "Я хочу ездить на Ланосе".
9. Область видимости методов printlnDesire в классах Ferrari и Lanos должна быть шире, чем в их классах родителях.
package com.javarush.task.task15.task1503;
*
ООП - машинки
*
public class Solution {
public static void main(String[] args) {
new Solution.LuxuriousCar().printlnDesire();
new Solution.CheapCar().printlnDesire();
new Solution.Ferrari().printlnDesire();
new Solution.Lanos().printlnDesire();
}
public static class Ferrari {
public void printlnDesire() {
//add your code here
}
}
public static class Lanos {
public void printlnDesire() {
//add your code here
}
}
public static class Constants {
public static String WANT_STRING = "Я хочу ездить на ";
public static String LUXURIOUS_CAR = "роскошной машине";
public static String CHEAP_CAR = "дешевой машине";
public static String FERRARI_NAME = "Феррари";
public static String LANOS_NAME = "Ланосе";
}
}
*/