-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathBusmain.java
More file actions
53 lines (46 loc) · 1.82 KB
/
Copy pathBusmain.java
File metadata and controls
53 lines (46 loc) · 1.82 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
import java.util.Scanner;
public class Busmain {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter your source: ");
String source=sc.nextLine();
System.out.println("Enter your destination: ");
String destination=sc.nextLine();
System.out.println("Enter the distance between source and destination: ");
double distance=sc.nextDouble();
System.out.println("Source: "+source);
System.out.println("Destination: "+destination);
System.out.println("Distance: "+distance+" km");
System.out.println("For AC bus= Rs 3 per km");
System.out.println("For Non AC bus= Rs 2 per km");
Bus b = new Bus(source, destination, distance);
b.busidgenerator();
b.busfarecalculator();
}
}
class Bus{
String source;
String destination;
double distance;
int acfare = 3;
int nacfare = 2;
String busId;
Bus(String source, String destination, double distance) {
this.source = source;
this.destination = destination;
this.distance = distance;
this.busId = generateBusId();
}
private String generateBusId() {
return source.substring(0, 1) + source.substring(1, 2).toLowerCase() +
source.substring(2, 3).toUpperCase() + "-" +
destination.substring(0, 1) + destination.substring(1, 2).toLowerCase() +
destination.substring(2, 3).toUpperCase();
}
void busidgenerator() {
System.out.println("BUS_ID: " + busId);
}
void busfarecalculator(){
System.out.println("BUS_FARE: For AC -> "+distance+"*"+acfare+"="+distance*acfare+","+"For NONAC -> "+distance+"*"+nacfare+"="+distance*nacfare);
}
}