Computer Applications ICSE Worksheet
Computer Applications ICSE Worksheet
Computer Applications ICSE Worksheet
Member methods
void accept ( ) — To take input for name, coach, mobile number and amount
void update ( )— To update the amount as per the coach selected
void display( ) — To display all details of a customer such as name, coach, total
amount and mobile number.
Write a main method to create an object of the class and call the above member
methods.
Solution:
import java.io.*;
import java.util.Scanner;
class RailwayTicket
{
String name, coach;
long mobno;
int amt, totalamt;
void accept( )
{
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[ ])
{
RailwayTicket t = new RailwayTicket!);
t.accept();
t.update();
t.display();
}
}