Advertisement
Guest User

ssd lab 5

a guest
Nov 24th, 2014
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. class Store{
  2. private boolean summer;
  3. private String [] products = new String [100];
  4. private int stock [] = new int [100];
  5. private static Store instance = null;
  6.  
  7. protected Store(){
  8. this.summer=summer;}
  9. //inplementation of Singleton
  10. public Store getInstance(boolean summer){
  11. if(instance == null) {
  12. instance = new Store(summer);
  13. }
  14. return instance;
  15. }
  16.  
  17. public void changeSeason(){
  18. if (summer == true)
  19. {summer = false;
  20. for (int i=0;i<products.length;i++){
  21. products[i]=NULL;
  22. stock[i]=0;}
  23. }
  24.  
  25. else
  26. {summer = true;
  27. for (int i=0;i<products.length;i++){
  28. products[i]=NULL;
  29. stock[i]=0;}
  30. }
  31. }
  32.  
  33.  
  34. public void printStock(){
  35. for (int i=0;i<products.length; i++){
  36. System.out.println("The stock for " + products[i] + " is " + stock[i]);
  37.  
  38. }
  39. }
  40.  
  41. public void addProduct(String prod){
  42. products[products.length+1]=prod;
  43. stock[products.length+1]=0;
  44. }
  45.  
  46. public void updateStock(String prod, int stock){
  47. for (int i=0;i<products.length; i++){
  48. if (prod.equals(products[i]))
  49. stock[i]=stock;
  50. }
  51. }
  52. public String printSeason(){
  53. if (season==true)
  54. System.out.println("The current season is summmer");
  55. else
  56. System.out.println("The current season is winter");
  57.  
  58.  
  59. }
  60. }
  61.  
  62. public class TestStore{
  63. public void main (String args[]){
  64.  
  65. Store store=new Store(true);
  66. store.printSeason();
  67. store.changeSeason(false);
  68. store.printSeason();
  69.  
  70. store.addProduct("Caciula");
  71. store.updateStock("Caciula",20);
  72. store.addProduct("Pantaloni");
  73. store.updateStock("Pantaloni",10);
  74. store.addProduct("Tricouri");
  75. store.updateStock("Tricouri",30);
  76.  
  77. store.printStock();
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement