0% found this document useful (0 votes)
61 views

Java Handson Questions

- Yatra wants to automate its online booking process based on various parameters using object oriented programming principles. - A class diagram is given with the Registration, Visitor, and TouristRegistration classes. - The Registration class should generate a unique registration ID prefixed by the visitor's nationality in uppercase. It should also validate payment mode. - The Visitor class should validate visitor details like nationality, phone number format, and email domain. - The TouristRegistration class should identify the tour cost based on type, calculate the total amount based on logic in Registration, and generate the registration ID.

Uploaded by

Nitesh Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views

Java Handson Questions

- Yatra wants to automate its online booking process based on various parameters using object oriented programming principles. - A class diagram is given with the Registration, Visitor, and TouristRegistration classes. - The Registration class should generate a unique registration ID prefixed by the visitor's nationality in uppercase. It should also validate payment mode. - The Visitor class should validate visitor details like nationality, phone number format, and email domain. - The TouristRegistration class should identify the tour cost based on type, calculate the total amount based on logic in Registration, and generate the registration ID.

Uploaded by

Nitesh Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Question1: Object Oriented Programming:

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

Use static variable counter auto-generated value startir


appropriately to implement the auto-generation logic
Example: The first registrationld would be "IND101 if the
nationality is "INDIAN" the second would be FOR102" if the
nationality is FOREIGNER" and=
Visitor class:

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

Note: Perform case-insensitive comparison for nationality

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

Otherwise, set totalAmount and registrationld as -1.0 and "NA" respectively

Note: noofTickets would always be greater than O(zero)

Example: If the nationality is "Indian, emailld is "[email protected] phoneNumber is'8765980954,noofTtickets is 3, paymentModeis


would be 3000.0 currency and registrationld would be "IND101 (Assuming as first registration).
WISH YOU ALL THE BEST
G0 Run ferminal Exam Help

olereh.ce Question Registration java x Tesfer jnva TouristRegistration java Visitor


Package progusinE)ava;

3 //00 NOT MODIFY THE CODE PROVIDED TO YOU

viityract public clas5s Registration

publie static intt counter-100;


private Visitor visitor;
private string paymentAode
private string registrationId;
private double totalAmount;
2 private int perHeadcost;
3

public Registration (Visitor visitor, string paymentMode)


5

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 string getPaymentMode()


31
return this .paymentMode;
32
33
public visitor
34 getvisitor ()
35 return this.visitor;
6

public int getperHeadCost()


8
return this.perHeadcost;

public void
setperHeadCost (int perHeadcost)
un Teminal Exam Help

e Questiorn Registration jnva x Toster java TourstRegistration jiava Visite

return this.visitor;

public int getperHeadcost(Ot


return this.perHeadcost;

public void setPerHeadCost (int perHeadCost) (


this.perHeadcostt = perHe adcost;

public string getRegistrationId()


return this.registrationId

public void setRegistrationId(string registrationId)

this.registrationId registrationId;

//To Trainee
public void generateRegistrationId ()

I/ Impl ement your 1logic here

public double getTotalAmount ()

return this.totalAmount;

public void setTotalAmount (double totalAmount)

this.totalAmount-totalAmount;

public boolean
validatePaymentMode ()
f (this.paymentMode equals ("PAYTM") | this.paymentMode. equals("Go=
Run Termunal Exam Hop

Queston Registration java x Tosta, java TouristRegistration java Visitor javi

public void setTotal Amount (double totalAmount )

this.total Amount=totalAmount;

public boolean validatePaymentMode ()

if(this.paymenthode.equals ("PAYTHN") this.paymentHode. equals("GooGLEPAY"))


return true;

else

return false;

public abstract void calculateAmount (0


ction Vew GoRu ema l

Feforece
episoton jv Tester jvax
puckage progus ingjava; Tounsttegistsen pmi
//Do NO7 MOOIFY THE COOE
PROVIDED TO YOU

Dulnyic class Tester


ava

tio Rhl setkkgitic void main(String args[0)


9 Visitor visitor1=new Visitor ("Indian", "[email protected]","8765980954",3);
10
TouristRegistration touristi=new
TouristRegistration(visitor1,"GOOGLEPAY Vacation );
11
tourist1.calculateAmount();
12 System.out.println("Registration Id: "+touristi.getRegistrationId());
13 System.out.println ("Total Amount:"+touristi.getTotalAmount ()) ;
14
15
n Tetmd Erar o

Hepatrafo java ster jaya Joifiegiti ation jnvn x Vsitr va


Pous 3ava;

FO0 NOT MODTEY THE CODE PROVIOED TO YOu

ovlic class TourlstRegistration pxtends Registration


public statie stringt] tourTypeArr ("Pilgrimage", "Entertainment, "Vacation");
publie static int[0 tourCostArr(2000, 1008,500);
private String touriype

public Tourist Registration(visitor visitor, string paymentMode,String tourType)

super(visitor, paymentMode);
this.tourType=touriype;

gOverride
public string tostring() (
return "TouristRegistration (visitor: + this.getvisitor()+" paymerntMode:
+this.getPaymentMode() + tourType: this.tourType +)

public static string[] getTour TypeArrO

return TouristRegistration, tourTypeArr;

public static int[] getTourCostarr()

return TouristRegistration.tourCostArrs

I/To Trainee
public Integer identifyTourCost0

//Tmplement your logic here

//Change the return statement


accorOingiy
return null;
Registraton java Tester java Touristke
Queston
//To Trainee
public Integer identifyTourCost()

here
//Implement your 1ogic

//Change the return statement accordingly


return null;

I/To Trainee
calculateAmount ()
public void

logic here
//Tmplement your
h Terminal Exam Help

Qbestion Registration java Tester java TouristRegistration java Visitor java X


public class Visitor

private string nationality;


private string ema11 1dg
private String phoneNumber;
private int noofTickets

publie Visitor(string nationality, Stringg email1d, String phoneiumber, int noof

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 +")"

public String getNationality)


return this.nationality;

public string getEmailId()

return this.emailId;

public string getPhoneNumber)


return this.phonetNumber;

public int getNoofTickets()

return this.noofTickets;
return this.emailId;

public string getPhoneNumber ()


return this.phoneNumber;

public int
getNoofTickets ()
return this.noofTickets;

//To Trainee
public Boolean verifyvisitorDetails)
// Implement your 1logic here

//change the return statement accordingly


return null;

You might also like