Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Programming language is Java*** 11.7.1. A Car is a Sports Car if ... After three months of analysis a team of business analysts have decided

image text in transcribedimage text in transcribed

Programming language is Java***

11.7.1. A Car is a Sports Car if ... After three months of analysis a team of business analysts have decided that a car can be marked with the "sports" tag if it satisfies all of the following requirements: it is red, it was manufactured by Ferrari, its engine has more than 6 cylinders. Based on these detailed requirements a team of top-notch developers have come up with the following implementation of the CarSearch class: Listing 11.14. CarSearch class implementation public class CarSearch { private List cars = new ArrayList(); public void addCar (Car car) { cars.add (car); public List findSportCars() { List sport Cars = new ArrayList(); for (Car car : cars) { if (car.getEngine ().getNbofCylinders() > 6 && Color. RED == car.getColor() && "Ferrari".equals (car.getManufacturer().getName())) { sportcars.add(car); return sport Cars; The Car, Engine and Manufacturer interfaces are presented below: Listing 11.15. Car interface public interface Car { Engine getEngine(); Color getColor(); Manufacturer getManufacturer(); Listing 11.16. Engine interface public interface Engine { int getNbOfCylinders(); Listing 11.17. Manufacturer interface public interface Manufacturer { String getName(); Your task is to write some tests for the findSportCars () method of the CarSearch class. Basically, what you have to do is pass some cars to the CarSearch class (using its addCar()) method, and then verify, whether only sports cars are being returned by the findSportsCars () method. Initially, do this for the original implementation of the CarSearch class. Then, redesign the car interface, so that the CarSearch class does not violate either the "Law of Demeter" or the "Tell, Don't Ask!" principles, and write the tests once again. Compare the amount of work involved in each case. 11.7.1. A Car is a Sports Car if ... After three months of analysis a team of business analysts have decided that a car can be marked with the "sports" tag if it satisfies all of the following requirements: it is red, it was manufactured by Ferrari, its engine has more than 6 cylinders. Based on these detailed requirements a team of top-notch developers have come up with the following implementation of the CarSearch class: Listing 11.14. CarSearch class implementation public class CarSearch { private List cars = new ArrayList(); public void addCar (Car car) { cars.add (car); public List findSportCars() { List sport Cars = new ArrayList(); for (Car car : cars) { if (car.getEngine ().getNbofCylinders() > 6 && Color. RED == car.getColor() && "Ferrari".equals (car.getManufacturer().getName())) { sportcars.add(car); return sport Cars; The Car, Engine and Manufacturer interfaces are presented below: Listing 11.15. Car interface public interface Car { Engine getEngine(); Color getColor(); Manufacturer getManufacturer(); Listing 11.16. Engine interface public interface Engine { int getNbOfCylinders(); Listing 11.17. Manufacturer interface public interface Manufacturer { String getName(); Your task is to write some tests for the findSportCars () method of the CarSearch class. Basically, what you have to do is pass some cars to the CarSearch class (using its addCar()) method, and then verify, whether only sports cars are being returned by the findSportsCars () method. Initially, do this for the original implementation of the CarSearch class. Then, redesign the car interface, so that the CarSearch class does not violate either the "Law of Demeter" or the "Tell, Don't Ask!" principles, and write the tests once again. Compare the amount of work involved in each case

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

Privacy In Statistical Databases International Conference Psd 2022 Paris France September 21 23 2022 Proceedings Lncs 13463

Authors: Josep Domingo-Ferrer ,Maryline Laurent

1st Edition

3031139445, 978-3031139444

More Books

Students also viewed these Databases questions