Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Find 2 code smells in the given code a. Mention the name of the smell code b. Explain why it's called code smell c. Give

Find 2 code smells in the given code

a. Mention the name of the smell code
b. Explain why it's called code smell
c. Give a solution how to fix the smell code

- Product.java

package pert1;

public class Product {
   private String productID;
   private String name;
   private int stock,price;
   public String getProductID() {
       return productID;
   }
   public void setProductID(String productID) {
       this.productID = productID;
   }
   public String getName() {
       return name;
   }
   public void setName(String name) {
       this.name = name;
   }
 
   public void setPrice(int price) {
       this.price = price;
   }
   public int getPrice() {
       return price;
   }
   public void setStock(int stock) {
       this.stock = stock;
   }
 
}
 

- ProductList.java

package pert1;

import java.util.Vector;

public class ProductList {
   private Vector productList = new Vector<>();
   int maxProduct = 100;
 
   public void addProduct(Product product) throws Exception{
       if (productList.size() > maxProduct){
           throw new Exception("Product list has exceeded the limit");
       }
       productList.add(product);
   }
 
   public Vector getProductList(){
       return productList;
   }
 
   public Product getProduct(int idx){
       return productList.get(idx);
   }
}
 

- ViewProductList.java

package pert1;

public class ViewProductList {
   public void view(ProductList productList){
       int totalData = productList.getProductList().size();
       System.out.println("ProductId - Name - Price");
       for(int i=0;i           Product product = productList.getProduct(i);
           System.out.printf("%s - %s - %d\n",product.getProductID(),product.getName(),product.getPrice());
       }
   }
}

 


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

Elements Of Chemical Reaction Engineering

Authors: H. Fogler

6th Edition

013548622X, 978-0135486221

More Books

Students also viewed these Programming questions

Question

Why is the national security argument for tariffs questionable?

Answered: 1 week ago