hi i am trying to create an array that doesnt add items if the value/size is more than 20. this solution adds only 1 item and then stops even if the value is less than 20. how do i change it so that it accepts values only upto 20 max.
package business;
import java.io.Serializable;
import java.util.ArrayList;
public class Cart implements Serializable
{
private ArrayList<LineItem> items;
public Cart()
{
items = new ArrayList<LineItem>();
}
public ArrayList<LineItem> getItems()
{
return items;
}
public int getCount()
{
return items.size();
}
public void addItem(LineItem item)
{
String code = item.getProduct().getCode();
int quantity = item.getQuantity();
double credit = item.getProduct().getCHours();
String credit2 = Double.toString(item.getProduct().getCHours());
int isize = items.size();
for (int i = 0; i < items.size(); i++)
{
if(isize <= 20)
{
LineItem lineItem = items.get(i);
lineItem.setQuantityCredit(credit);
return;
}
}
items.add(item);
}
public void addItemCredit(LineItem item)
{
double credit = item.getProduct().getCHours();
String credit2 = Double.toString(item.getProduct().getCHours());
String code = item.getProduct().getCode();
for (int i = 0; i < 20; i++)
{
LineItem lineItem2 = items.get(i);
lineItem2.setQuantityCredit(credit);
return;
}
items.add(item);
}
public void removeItem(LineItem item)
{
String code = item.getProduct().getCode();
for (int i = 0; i < items.size(); i++)
{
LineItem lineItem = items.get(i);
if (lineItem.getProduct().getCode().equals(code))
{
items.remove(i);
return;
}
}
}
}
i think wat u said is right so i tried this
if(isize <= 20)
{
LineItem lineItem = items.get(i); lineItem.setQuantityCredit(credit);
}
return;
}
items.add(item);
}
and
if(isize <= 20)
{
LineItem lineItem = items.get(i); lineItem.setQuantityCredit(credit);
}
}
items.add(item);
return;
}
but neither worked. so whr do i place d return statement?