Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!