-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSmartTransportationSystem.java
More file actions
110 lines (85 loc) · 3.15 KB
/
Copy pathSmartTransportationSystem.java
File metadata and controls
110 lines (85 loc) · 3.15 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
// Below is a single-file legacy Java program for a Smart Transportation Management System. It intentionally contains:
// Poor variable names
// Poor method names
// Long methods
// Duplicate code
// Mixed responsibilities
// Temporary variables
// Unclear naming
// Methods that should be extracted
// Methods and variables that should be renamed
// Logic that should be moved to separate classes
// The students' task is to apply Extract Method, Move Method, Rename Variable, and Rename Method refactorings
public class SmartTransportationSystem {
public void print(String name, String transport, int distance, String payment) {
System.out.println("================================");
System.out.println("Passenger Name: " + name);
System.out.println("Vehicle Type: " + transport);
System.out.println("Distance: " + distance);
System.out.println("Base Fare: " + x);
System.out.println("Sending SMS Notification...");
System.out.println("Passenger " + name + ", your booking has been confirmed.");
System.out.println("Saving Booking Record...");
System.out.println("Passenger: " + name);
System.out.println("Vehicle: " + transport);
System.out.println("Distance: " + distance);
System.out.println("Amount Paid: " + fFare);
System.out.println("================================");
}
public void calculateTax(int x, int distance ){
double tax = 0;
if (distance > 100) {
tax = x * 0.10;
}
else {
tax = x * 0.05;
}
System.out.println("Tax: " + tax);
}
public void SpecialDiscount(int tax){
double sDiscount = x + tax;
if (n.equalsIgnoreCase("Ali")) {
fFare = fFare - (fFare * 0.15);
System.out.println("Special Discount Applied");
}
System.out.println("Final Fare: " + fFare);
}
public void calculateDistance(){
double x = 0;
if (transport.equals("BUS")) {
x = d * 2;
}
else if (transport.equals("TAXI")) {
x = d * 8;
}
else if (transport.equals("TRAIN")) {
x = d * 4;
}
else {
System.out.println("Invalid Vehicle");
return;
}
}
public void payment(){
if (payment.equals("CARD")) {
System.out.println("Processing Card Payment...");
System.out.println("Verifying Card...");
System.out.println("Deducting Amount...");
System.out.println("Payment Successful");
}
else if (payment.equals("CASH")) {
System.out.println("Receiving Cash...");
System.out.println("Generating Receipt...");
System.out.println("Payment Successful");
}
else if (payment.equals("ONLINE")) {
System.out.println("Connecting Gateway...");
System.out.println("Verifying Transaction...");
System.out.println("Payment Successful");
}
else {
System.out.println("Invalid Payment Method");
return;
}
}
}