Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 1. (30 marks) Consider the following code base that followb a bad SOLID principle, State which principle it is violating and why. Fix the

image text in transcribed
image text in transcribed
image text in transcribed
Question 1. (30 marks) Consider the following code base that followb a bad SOLID principle, State which principle it is violating and why. Fix the design of the system so that it follows the stated principle. Submit the fixed code. Explain what did you change to fix the design to follow that principle. Given code: class Library \{ private ArrayListeBook> books; public Library0 \{ books = new ArrayList (); ) public void addBook(Book book) \{ books.add(book): ) public void removeBook(Book book) \& books remove(book); 1 public void printBooks() \{ for (Book book : books) f if (book.getType().equals("Novel")) \{ System.out.printin("Novel: " + book.getTite()); ) else if (book.getType0.equals("Textbook")) \{ System.out.println("Textbook: + book.getTite()): \} else if (book.getType() equals( Comic) ) \{ System.out.printin("Comic: " + book.getTitle()): ) \} \} class Book \{ private String title; private String type; public Book(String title, String type) \{ this .title = title; this.type = type; \} public String getTitle() \{ return title; \} public String getType() \{ return type; \} \} Fixed code (10 marks): Explanation (10 marks)

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

Marketing Database Analytics

Authors: Andrew D. Banasiewicz

1st Edition

0415657881, 978-0415657884

More Books

Students also viewed these Databases questions