-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLab3 Homework.txt
334 lines (254 loc) · 8.63 KB
/
Lab3 Homework.txt
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
Homework####################################################################
task01---------------------------------------------------------
import java.util.Scanner;
public class Lab3 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the first number: ");
double a = scanner.nextDouble();
System.out.print("Enter the second number: ");
double b = scanner.nextDouble();
System.out.print("Enter the operator: ");
String op = scanner.next();
char ope = op.charAt(0);
double result = 0;
switch (ope) {
case '+' :
result = a+b;
break;
case '-' :
result = a-b;
break;
case '*':
result = a*b;
break;
case '/':
if (a<b) {
}
result = a/b;
break;
}
System.out.print(result);
/* ADD YOUR CODE HERE */
}
}
Alter task01---------------------------------------------------------------
import java.util.Scanner;
public class Lab3 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Input
System.out.println("Enter first number: ");
int num1 = scanner.nextInt();
System.out.println("Enter second number: ");
int num2 = scanner.nextInt();
System.out.println("Enter operator (+, -, *, /): ");
String operator = scanner.next();
// Calculation
int result = 0;
if (operator.equals("+")) {
result = num1 + num2;
} else if (operator.equals("-")) {
result = num1 - num2;
} else if (operator.equals("*")) {
result = num1 * num2;
} else if (operator.equals("/")) {
if (num2 != 0) {
result = num1 / num2;
} else {
System.out.println("Error: Division by zero.");
return;
}
} else {
System.out.println("Error: Invalid operator.");
return;
}
// Output
System.out.println("Result: " + result);
/* ADD YOUR CODE HERE */
}
}
task02-------------------------------------------------------------------
import java.util.Scanner;
public class Lab3 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter an integer number: ");
int number = scanner.nextInt();
if (number % 5 == 0 && number % 7 == 0) {
System.out.println("Divisible by Both");
}
else if (number%5==0) {
System.out.println("Invalid: Divisible by 5 Only ");
}
else if (number%7==0) {
System.out.println("Invalid: Divisible by 7 Only ");
}
else {
System.out.println("No");
}
/* ADD YOUR CODE HERE */
}
}
task03-------------------------------------------------------------------
import java.util.Scanner;
public class Lab3 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Input the value of 'X': ");
double num = scanner.nextInt();
double result = 0;
if (num<0) {
result = 2*num;
}
else if (num>=0 && num<2) {
result = num + 1;
}
else if (num>=2 && num<5) {
result = (num*num) - 1;
}
else {
result = (3*(num*num)) + 2;
}
System.out.println("Output: "+result);
/* ADD YOUR CODE HERE */
}
}
task04-------------------------------------------------------------------
import java.util.Scanner;
public class Lab3 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter BRACU Student ID: ");
int studentID = scanner.nextInt();
int year = studentID / 1000000; // Extracting the first two digits as year
int sessionCode = (studentID / 100000) % 10; // Extracting the 3rd digit as session code
String session = "";
switch (sessionCode) {
case 1:
session = "Spring";
break;
case 2:
session = "Fall";
break;
case 3:
session = "Summer";
break;
default:
session = "Unknown";
}
System.out.println("Student joined BRAC in " + session + " " + year);
/* ADD YOUR CODE HERE */
}
}
task05-------------------------------------------------------------------
import java.util.Scanner;
public class Lab3 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter payment: ");
double payment = scanner.nextDouble();
System.out.print("Enter age: ");
int age = scanner.nextInt();
double tax = 0;
if ((age < 18) || (payment < 10000)) {
System.out.println("Your tax amounts to 0 Tk");
}
else {
if (payment >= 10000 && payment <= 20000) {
tax = 0.05 * payment;
System.out.println("Your tax amounts to " + tax + " Tk");
}
else {
tax = 0.10 * payment;
System.out.println("Your tax amounts to " + tax + " Tk");
}
}
/* ADD YOUR CODE HERE */
}
}
task06-------------------------------------------------------------------
import java.util.Scanner;
public class Lab3 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter three float numbers:");
float num1 = scanner.nextFloat();
float num2 = scanner.nextFloat();
float num3 = scanner.nextFloat();
// Assume the first number is both max and min initially
float max = num1;
float min = num1;
// Update max and min accordingly
if (num2 > max) {
max = num2;
} else if (num2 < min) {
min = num2;
}
if (num3 > max) {
max = num3;
} else if (num3 < min) {
min = num3;
}
System.out.println("Maximum number is " + max);
System.out.println("Minimum number is " + min);
/* ADD YOUR CODE HERE */
}
}
task07-------------------------------------------------------------------
import java.util.Scanner;
public class Lab04 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the amount the customer need to pay(Taka) : ");
int payment = scanner.nextInt();
System.out.print("Enter the amount, customer gave(Taka) : ");
int gave =scanner.nextInt();
if (payment > gave) {
System.out.println("Please pay "+ (payment-gave) +" taka more.");
}
else if (payment == gave) {
System.out.println("The returned amount is 0 taka. ");
}
else {
int change = gave - payment;
System.out.println("The returned amount is "+ (gave-payment)+" taka.");
System.out.println("100 taka note: "+change/100);
change = change % 100;
System.out.println("50 taka note: "+change/50);
change = change % 50;
System.out.println("20 taka note: "+change/20);
change = change % 20;
System.out.println("10 taka note: "+change/10);
change = change % 10;
System.out.println("5 taka coin: "+change/5);
change = change % 5;
System.out.println("2 taka coin: "+change/2);
change = change % 2;
System.out.println("1 taka coin: "+change);
}
}
}
task08-------------------------------------------------------------------
import java.util.Scanner;
public class Lab3 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Input the 1st number:");
int num1 = scanner.nextInt();
System.out.println("Input the 2nd number:");
int num2 = scanner.nextInt();
System.out.println("Input the 3rd number:");
int num3 = scanner.nextInt();
if (num1 == num2 && num2 == num3) {
System.out.println("All numbers are equal");
}
else if (num1 != num2 && num2 != num3 && num1 != num3) {
System.out.println("All numbers are different");
}
else {
System.out.println("Neither all are equal or different");
}
/* ADD YOUR CODE HERE */
}
}