-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRailwayTicket.java
More file actions
49 lines (43 loc) · 1.35 KB
/
RailwayTicket.java
File metadata and controls
49 lines (43 loc) · 1.35 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
import java.util.Scanner;
import java.lang.String;
public class RailwayTicket {
public String name;
public String coach;
public long mobno;
public int amt;
public int totalamt;
public void accept() {
Scanner sc = new Scanner(System.in);
System.out.printf("Enter name: ");
name = sc.nextLine();
System.out.print("Enter coach: ");
coach = sc.nextLine();
System.out.print("Enter mobile no: ");
mobno = sc.nextLong();
System.out.print("Enter amount: ");
amt = sc.nextInt();
sc.close();
}
public void update() {
if (coach.equalsIgnoreCase("First_AC"))
totalamt = amt + 700;
else if (coach.equalsIgnoreCase("Second_AC"))
totalamt = amt + 500;
else if (coach.equalsIgnoreCase("Third_AC"))
totalamt = amt + 250;
else if (coach.equalsIgnoreCase("Sleeper"))
totalamt = amt;
}
public void display() {
System.out.println("\n\nName: " + name);
System.out.println("Coach: " + coach);
System.out.println("Total Amount: " + totalamt);
System.out.println("Mobile number: " + mobno);
}
public static void main(String args[]) {
RailwayTicket obj = new RailwayTicket();
obj.accept();
obj.update();
obj.display();
}
}