Skip to content

Commit 2d17700

Browse files
committed
OOPS - designing of railway service of a ticket
1 parent a7cc576 commit 2d17700

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

src/OOPS/RailwayService.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy