B. Long Answer Questions.
1. Design a class Railway Ticket with following description:
Instance variables/data members
(ICSE 2018
String name
: To store the name of the customer
: To store the type of coach customer wants to travel
String coacha
Answers
Answer:
see below.........
Explanation:
import java.io.*;
import java.util.Scanner;
class RailwayTicket {
String name, coach;
long mobno;
int amt, totalamt;
void accept( ) throws IOException{
Scanner sc = new Scanner(System.in);
System.out.print(“Enter Passenger’s Name: “);
name = sc.next( );
System.out.print(“Enter Mobile Number:”); mobno = sc.nextlnt( );
Systein.out.print(“Enter Coach (FirstAC/SecondAC/ThirdAC/sleeper):”);
coach = sc.next( ); System.out.print(“Enter basic amount of ticket:”);
amt = sc.nexdnt( ); } void update!) { if (coach.equals(“First_AC”)) totalamt = amt + 700; else if (coach.equals(“Second_AC”)) totalamt = amt + 500; . else if (coach.equals!”Third_AC”)) totalamt = amt + 250; else totalamt = amt; } void display() { System.out.println(“\n\n Name :” +name); System.out.println(“Coach :” +coach); System.out.prindn(”Total Amount:” +totalaint); System.out.prindn(“Mobile No.:” +name); } public static void main (String args[ ]) throws IOException { RailwayTicket t = new RailwayTicket!); t.accept(); t.update(); t.display(); } }
plz check for because this answer is type by phone.......I hope you that this answer helpful
thankQ