Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The AMC Travel Company provides services to book for flight and train tickets for the customer. After each booking from the customer, AMC will send

image text in transcribedimage text in transcribed

The AMC Travel Company provides services to book for flight and train tickets for the customer. After each booking from the customer, AMC will send a short letter of appreciation with an advertised statement about member points offered for a return journey booking. Identify the code smells in the code snippets provided and refactor the code to solve issues, such as: (i) Data Clump that could cause accidental parameter reversal where too many parameters are passed to a constructor. E.g. Journey from Kuala Lumpur to Penang can be accidentally reversed to be Penang to Kuala Lumpur. (ii) Duplicate codes that could be avoided. (ii) Long method code, which could be grouped or extracted to show its own features. (48 marks) The codes before refactoring are shown below: public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Booking booking = new Flight("Kuala Lumpur", "Penang", "Helen"); System.out.println(" "); System.out.println("***AMC Travel Company***"); System.out.println(" ******"); booking.printGreeting(); booking.printThankyou(); booking.printPoint(); } } public abstract class Booking { String toPlace; String fromPlace; String name; public Booking (String to, String from, String name) { toPlace-to; fromPlace=from; this.name=name; } public void printGreeting() { System.out.println("Hello " + name + ","); } abstract void printThankyou(); abstract void printPoint(); } public class Flight extends Booking { public Flight (String to, String from, String name) { super(to, from, name); } public void printHeading() { System.out.println("** System.out.println("***AMC Travel Company**** '); System.out.println("***** } @Override protected void print Thankyou() { // TODO Auto-generated method stub System.out.println("Thank you for booking your flight with us"); } @Override protected void printPoint() { // TODO Auto-generated method stub System.out.println("You will earn 1000 member points with each return flight booking"); } } public class Train extends Booking { public Train (String to, String from, String name) { super(to, from, name); } public void printHeading() { System.out.println("* System.out.println("***AMC Travel Company***"); System.out.println("** "); } @Override protected void print Thankyou() { System.out.println("Thank you for booking your train ticket with } us"); @Override protected void printPoint() { System.out.println("You will earn 300 member points with each return trip booking"); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Focus On Geodatabases In ArcGIS Pro

Authors: David W. Allen

1st Edition

1589484452, 978-1589484450

More Books

Students also viewed these Databases questions

Question

Ty e2y Evaluate the integral dy

Answered: 1 week ago