Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Store{
- private boolean summer;
- private String [] products = new String [100];
- private int stock [] = new int [100];
- private static Store instance = null;
- protected Store(){
- this.summer=summer;}
- //inplementation of Singleton
- public Store getInstance(boolean summer){
- if(instance == null) {
- instance = new Store(summer);
- }
- return instance;
- }
- public void changeSeason(){
- if (summer == true)
- {summer = false;
- for (int i=0;i<products.length;i++){
- products[i]=NULL;
- stock[i]=0;}
- }
- else
- {summer = true;
- for (int i=0;i<products.length;i++){
- products[i]=NULL;
- stock[i]=0;}
- }
- }
- public void printStock(){
- for (int i=0;i<products.length; i++){
- System.out.println("The stock for " + products[i] + " is " + stock[i]);
- }
- }
- public void addProduct(String prod){
- products[products.length+1]=prod;
- stock[products.length+1]=0;
- }
- public void updateStock(String prod, int stock){
- for (int i=0;i<products.length; i++){
- if (prod.equals(products[i]))
- stock[i]=stock;
- }
- }
- public String printSeason(){
- if (season==true)
- System.out.println("The current season is summmer");
- else
- System.out.println("The current season is winter");
- }
- }
- public class TestStore{
- public void main (String args[]){
- Store store=new Store(true);
- store.printSeason();
- store.changeSeason(false);
- store.printSeason();
- store.addProduct("Caciula");
- store.updateStock("Caciula",20);
- store.addProduct("Pantaloni");
- store.updateStock("Pantaloni",10);
- store.addProduct("Tricouri");
- store.updateStock("Tricouri",30);
- store.printStock();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement