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