-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbaitap123
180 lines (173 loc) · 3.45 KB
/
baitap123
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
import java.util.*;
import java.io.*;
abstract class developer{
String name;
int level;
developer() {
this.name =" ";
this.level = 0;
}
developer(String name, int level){
this.name = name;
this.level = level;
}
abstract float getpayment();
void input() {
Scanner ad = new Scanner(System.in);
System.out.println("Nhap ten:");
this.name = ad.nextLine();
System.out.println("Nhap level:");
this.level = ad.nextInt();
}
void output() {
System.out.println("| Ten: "+this.name+" | Level: "+this.level+" | Luong: "+getpayment());
}
}
class devpro extends developer{
int bonus;
float time;
devpro(){
this.bonus = 0;
this.time = 0;
}
devpro(int bonus, float time){
this.bonus = bonus;
this.time = time;
}
float getpayment() {
return (float) (bonus+time*2+1000000);
}
void input() {
super.input();
Scanner ad = new Scanner(System.in);
System.out.print("Nhap Bonus: ");
this.bonus = ad.nextInt();
System.out.print("Nhap time: ");
this.time = ad.nextFloat();
}
void output() {
super.output();
}
}
class devpm extends developer{
int bonus;
devpm(){
this.bonus=0;
}
devpm(int bonus){
this.bonus = bonus;
}
float getpayment() {
return (bonus*3+3000000);
}
void input() {
super.input();
Scanner ad = new Scanner(System.in);
System.out.print("Nhap Bonus: ");
this.bonus = ad.nextInt();
}
void output() {
super.output();
}
}
class data{
developer list[] = new developer[100];
int n=0;
char asd,dsa;
void input() throws IOException{
do {
System.out.println("DevPro hay DevPM (1/2): ");
asd = (char)System.in.read();
if(asd == '1')
list[n] = new devpro();
else
list[n] = new devpm();
System.in.skip(asd);
list[n++].input();
System.out.println("Tiep tuc? (y/n): ");
dsa = (char)System.in.read();
System.in.skip(dsa);
if(dsa == 'n'|| dsa == 'N')
break;
}while(true);
}
void output() {
for(int i=0;i<n;i++) {
list[i].output();
}
}
void tang() {
developer tmp;
for(int i=0;i<n-1;i++) {
for(int j=i+1;j<n;j++) {
if(list[i].getpayment()>list[j].getpayment()) {
developer tmp = list[i];
list[i] = list[j];
list[j] = tmp;
}
}
}
for(int i=0;i<n;i++) {
list[i].output();
}
}
void giam() {
for(int i=0;i<n-1;i++) {
for(int j=i+1;j<n;j++) {
if(list[i].getpayment()<list[j].getpayment()) {
developer tmp = list[i];
list[i] = list[j];
list[j] = tmp;
}
}
}
for(int i=0;i<n;i++) {
list[i].output();
}
}
void Max() {
float Max = list[0].getpayment();
for(int i=1;i<n;i++) {
if(Max<list[i].getpayment()) {
Max = list[i].getpayment();
}
}
for (int i=0;i<n;i++) {
if(Max == list[i].getpayment()) {
System.out.println("Nguoi co luong cao nhat la:" +Max);
list[i].output();
}
}
}
void Min() {
float Min = list[0].getpayment();
for(int i=1;i<n;i++) {
if(Min>list[i].getpayment()) {
Min = list[i].getpayment();
}
}
for (int i=0;i<n;i++) {
if(Min == list[i].getpayment()) {
System.out.println("Nguoi co luong thap nhat la:" +Min);
list[i].output();
}
}
}
}
public class Baitap3 {
public static void main(String[] args) throws IOException {
data list = new data();
System.out.println("Nhap du lieu");
data.input();
System.out.println();
data.output();
System.out.println("Tang dan:");
data.tang();
System.out.println("Giam dan:");
data.giam();
System.out.println();
data.Max();
System.out.println();
data.Min();
}
}