File tree Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change
1
+ package OOPS ;
2
+
3
+ import java .util .Scanner ;
4
+
5
+ public class RailwayService {
6
+ String name ;
7
+ String coach ;
8
+ long contact ;
9
+ int amount ;
10
+ int totalAmount ;
11
+
12
+ RailwayService (){
13
+ name = "" ;
14
+ coach = "" ;
15
+ contact = 0 ;
16
+ amount = 0 ;
17
+ totalAmount = 0 ;
18
+ }
19
+ void accept (){
20
+ Scanner sc = new Scanner (System .in );
21
+ System .out .print ("Enter full name: " );
22
+ name = sc .nextLine ();
23
+ System .out .print ("Enter coach: " );
24
+ coach = sc .nextLine ();
25
+ System .out .print ("Enter mobile number: " );
26
+ contact = sc .nextLong ();
27
+ System .out .print ("Enter amount: " );
28
+ amount = sc .nextInt ();
29
+ }
30
+ void update (){
31
+ switch (this .coach ){
32
+ case "First_AC" -> totalAmount = 700 + amount ;
33
+ case "Second_AC" -> totalAmount = 500 + amount ;
34
+ case "Third_AC" -> totalAmount = 300 + amount ;
35
+ default -> totalAmount = amount ;
36
+ }
37
+ }
38
+ void display (){
39
+ System .out .println ("Name: " + name );
40
+ System .out .println ("Coach: " + coach );
41
+ System .out .println ("Mobile No: " + contact );
42
+ System .out .println ("Total Amount to be paid: " + totalAmount );
43
+ }
44
+
45
+ public static void main (String [] args ) {
46
+ RailwayService r1 = new RailwayService ();
47
+ r1 .accept ();
48
+ r1 .update ();
49
+ r1 .display ();
50
+ }
51
+ }
You can’t perform that action at this time.
0 commit comments