Advertisement
Guest User

Untitled

a guest
May 24th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. package projectjava;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. /**
  5. *
  6. * @author Mirela
  7. */
  8. public class NotEnoughCommodityException extends Exception {
  9. private Commodity com;
  10. private int amountToBuy;
  11. List<Commodity>listOfCommodities;
  12.  
  13.  
  14. public NotEnoughCommodityException(Commodity com, int amountToBuy, List<Commodity>listOfCommodities)
  15. {
  16. this.com = com;
  17. this.amountToBuy = amountToBuy;
  18. this.listOfCommodities = listOfCommodities;
  19.  
  20. }
  21.  
  22. @Override
  23. public String toString() {
  24. return "NotEnoughCommodityException{" + "com=" + com.getNameOfCom() + (amountToBuy - listOfCommodities.size()) + '}';
  25. }
  26.  
  27.  
  28. }
  29.  
  30.  
  31. ////.........
  32. @Override
  33. public void sellCommodity(Commodity com, int amountToBuy) throws NotEnoughCommodityException
  34. {
  35. if(listOfCommodities.contains(com) && listOfCommodities.size()<amountToBuy)
  36. {
  37. listOfCommoditiesToSell.add(com);
  38. listOfCommodities.remove(com);
  39. }
  40. else
  41. {
  42. throw new NotEnoughCommodityException(com,amountToBuy, listOfCommodities);
  43. System.out.print(com.getNameOfCom()) + (amountToBuy - listOfCommodities.size())); //greshka tuk :P
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement