Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Question 3 [Refactoring] (48 marks) The AMC Travel Company provides services to book for flight and train tickets for the customer. After each booking from
Question 3 [Refactoring] (48 marks) 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: 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. (iii) 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 from Place; String name; public Booking (String to, String from, String name) { toPlace=to; from Place=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 printThankyou() { // 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); } 11************************ **"); public void printHeading() { System.out.println("** System.out.println("*** AMC Travel Company***"); System.out.println(" ******"); } 11************************ @Override protected void printThankyou() { 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started