Constuctor 1
Constuctor 1
First_AC 700
Second_AC 500
Third_AC 250
sleeper None
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.
import java.util.*;
class RailwayTicket
{
String name, coach;
long mobno;
int amt ,totalamt;
void accept()
{
Scanner sc = new Scanner(System.in);
System.out.println("enter name , coach and mobile no and amount");
name=sc.next();
coach=sc.next();
mobno=sc.nextLong();
amt=sc.nextInt(); }
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
totalamt=amt;
}
void display() {
System.out.println("name is :"+name);
System.out.println("mobile no is :"+mobno);
System.out.println("coach is :"+ coach);
System.out.println("total amount is :"+totalamt); }
public static void main ()
{
RailwayTicket ob =new RailwayTicket();
ob.accept();
ob.update();
Define a class called ParkingLot with the following description :
Instance variables/data members :
int vno - To store the vehicle number
int hours - To store the number of hours the vehicle is parked in the
parking lot
double bill - To store the bill amount
Member methods :
void input() - To input and store the vno and hours.
void calculate() - To compute the parking charge at the rate of 3 for
the first hour or part thereof,
and 1.50 for each additional hour or part thereof.
void display() - To display the detail
Write a main method to create an object of the class and call the
above methods
import java.util.*;
class ParkingLot
{
int vno;
int hours;
double bill;
void input()
{Scanner sc=new Scanner(System.in);
System.out.println("Enter the vehicle number and number of hours");
vno=sc.nextInt();
hours=sc.nextInt();
}
void calculate()
{
if(hours<=1)
bill= 3;
else
bill=3+(hours-1)*1.50;
}
void display()
{
System.out.println("Vechicle Number:"+vno);
System.out.println("Hours:"+hours);
System.out.println("Bill:"+bill);
}