Java Handson Questions
Java Handson Questions
Description:
automate its online booking process based on various para
wants to
Yatra, a popular tourist agency
below to achieve the same.
Implement the class diagram given
Class Diagram:
Registration
+counter int- static
visitor Visitor
paymentMode Strine
Visitor
registrationld String
totalAmount double
perHeadCost int nationality :String
emailid String
phoneNumber String
+Registration(visitor:Visitor noOfTickets :int
paymentMode: String
+tostring: String +Visitor(nationality String, emailid
+getVisitor) Visitor String, phoneNumber String
+getPerHead Cost() int noofTickets int)
+getPaymentModel:String +toString0 String
+setPerHeadCost(perHeadCost int) :void +getNationalityt) Strin
+getRegistrationidl) String +getEmailtd) String
+setRegistrationidregistrationld :String) +getPhoneNumber() String
void
+EetNoofTickets( int
+generateRegistrationid0 vold
+getTotalAmount{) double +verifyVisitorDetails Boalean
+setTotalAmount totalAmount :double)
void
+validatePaymentMode() :boolean
+calculateAmount() void abstract
TouristRegistration
+tourTypeArr Stringll>static
+tourCostArr int[l>static
tourType -String
+TouristRegistration(visitorVisitor,
paymentMode :String tourType String)
Registration(visitor, paymentMode)
+toString(): String
+getTourTypeArrl Stringl >static
+getTourCostArr({): int-static
+identifyTourCost) integer
tcalculateAmountl ynid
Reference Question x
Notes:
Regstration jvs Tester jva
urnstRegestration javs Vistor evs
ainees Do not include any extra
instance/static variables
Case-insensitive
Do not change anycomparison
is to be done
if not
and
instance/static methods in the given classes
value or case explicitly mentioned
singjavaa of the
Read notes and examples for better given variables
stration java In the derived classes, the order of understanding of the logic
passing arguments to the constructor
rjava would be- base class
Implementation Details: variables followed by derived dass variables
tRegistratio
java Class Name
Registration Implementation Details
Partially implemented bmF2Z
Tourist Registratioon
Visitor Partially implemented
Partially implemented
Registration Class:
generate Registrationid 0:
This method auto-generates and sets the
The registrationld (String)
registrationld must be prefixed by the first three
Subsequent registrationid must be incremented by 1 characters nationality of Visitor class in uppercase followed by the
of
verifyVisitorDetails0:
This method validates the visitor details and returnsa Boolean value
Check if nationality is either "INDIAN or "FOREIGNER and length of phoneNumber is 10 and emailld
if all the above conditions are satisfied, then return true otherwise return talse ends with".com
Example:ifthenationality is "Indian", length of phoneNumber is 10 and enmaild [email protected] then theabove method must retum true
TouristRegistration class:
o t the tourCost
Otherwise, set the tourCost elements in the
tourTypeArr, (Integer) tourType(String) from
of
Return tourCost to -1
identify the corresponding tourTypeArr array
tourCost from
Note: Perform
the tourCostArr
case-sensitive comparison
Example: If the tourType is
"Entertainment", then the tourCost would
be 1000
currency
calculateAmount0:
This method sets the
Invoke validate registrationld (String) and totalAmount (double) based
PaymentMode)
Ifthe above method method of
returns true, then Registration class
on the following logic:
oInvoke identify tourCost(int) by invoking
verifyVisitorDetails0
o If tourCost is not -1 and the above
method of
Visitor class identifyTourCost() method
method returns true,
Check if nationality of the Visitor class
is "FOREIGNER", if so, then
Note: Perform case insensitive add extra 10% of
comparison for
nationality tourCost to tourCost as extra charge
Add 500 currencies to tourCost as food
Set cost
perHeadCostint) with above obtained tourCost
Obtain finalCost(double) by multiplying perHeadCost and noofTickets(int) of
Set the totalAmount with the obtained Visitor class
finalCost
Generate the
registrationld by invoking generateRegistrationld0 of Registration class
O Otherwise, set totalAmount
and registrationld -1.0 and "NA" respectively
as
this.visitor=visitor;
this.paymentMode=paymentMode;
8
this.registrationId=null;
this.totalAmount=0,
this.perHeadcost=0;
gOverride
24
public string tostring()
25
0
return "Registration( visitor: +this.visitor+ paymentMode:
27 +this.paymentMode+ S
28
public void
setperHeadCost (int perHeadcost)
un Teminal Exam Help
return this.visitor;
this.registrationId registrationId;
//To Trainee
public void generateRegistrationId ()
return this.totalAmount;
this.totalAmount-totalAmount;
public boolean
validatePaymentMode ()
f (this.paymentMode equals ("PAYTM") | this.paymentMode. equals("Go=
Run Termunal Exam Hop
this.total Amount=totalAmount;
else
return false;
Feforece
episoton jv Tester jvax
puckage progus ingjava; Tounsttegistsen pmi
//Do NO7 MOOIFY THE COOE
PROVIDED TO YOU
super(visitor, paymentMode);
this.tourType=touriype;
gOverride
public string tostring() (
return "TouristRegistration (visitor: + this.getvisitor()+" paymerntMode:
+this.getPaymentMode() + tourType: this.tourType +)
return TouristRegistration.tourCostArrs
I/To Trainee
public Integer identifyTourCost0
here
//Implement your 1ogic
I/To Trainee
calculateAmount ()
public void
logic here
//Tmplement your
h Terminal Exam Help
this.nationality-nationality;
this.emailid-emailId;
this.phoneNumber-phoneNlumber
this.noofTickets=noofTickets
@Override
public string tostring() {
return rvisitor (nationality: +this.nationality+, emailrd:
this.emailId + phonelNumber:+this.phonetiumber
",noofTickets:+this.no0fTickets +")"
return this.emailId;
return this.noofTickets;
return this.emailId;
public int
getNoofTickets ()
return this.noofTickets;
//To Trainee
public Boolean verifyvisitorDetails)
// Implement your 1logic here