Advertisement
Guest User

A4 COMMENTS

a guest
Jan 17th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.75 KB | None | 0 0
  1. package uk.ac.brunel.cs1702;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5.  
  6.  
  7. public class MyStore {
  8.  
  9.  
  10.  
  11.  private List<ItemForSale> items = null;//creating a new  private list called items  with the data type as the items for sale object and setting it to null
  12.  
  13.  public MyStore() {
  14.   this.items = new ArrayList<ItemForSale>();//creation of my store construcor which assigns this class's list as an array list//
  15.  }
  16.  
  17.  public void setItems(List<ItemForSale> items){//takes in a list as its parameters. this sets the class's items list to the items list passed in through the parameters
  18.   this.items = items;
  19.  }
  20.  
  21.  public static void main(String[] args) {//main method//
  22.        
  23.         MyStore myStore = new MyStore();//creating a new object of this very class (My store)//
  24.         myStore.items.add(new ItemForSale("Herbal Health Supplement", 10, 5));//In mystore.items.add" this is creation of adding new times to the list called "items". Those items are objects of the itemsforsale class.
  25.         myStore.items.add(new ItemForSale("Aged Parmesan cheese", 20, 10));
  26.         myStore.items.add(new ItemForSale("Local soda drink", 20, 3));
  27.         myStore.items.add(new ItemForSale("World War Medals", 0, 80));//i am assigning a new itemsfor sale object and calling the objects constructor to set the inital values of the 3 variables.
  28.         myStore.items.add(new ItemForSale("Tickets to Iron Maiden concert", 15, 20));
  29.         myStore.items.add(new ItemForSale("Special cake baked in store", 3, 6));//the 2 numbers at the end are days to selling and the price.
  30.  
  31.         myStore.updateInventory();
  32.        
  33.    
  34.         System.out.println("Inventory Updated!");//will outprint the update inventory//
  35.     }
  36.  
  37.    public void updateInventory() {//update inventory is a variable for all the updates that will occur//
  38.         herbalSodas();//items//
  39.         parmesans();//items//
  40.         worldwarMedals();//items//
  41.         Concertticket();//items//
  42.         Spcake();//items//
  43.        
  44.     }
  45.    
  46.     public void herbalSodas () {
  47.      for (int i=0; i< items.size(); i++) {
  48.       if (items.get(i).getName().equals("Herbal Health Supplements")||items.get(i).getName().equals("Local soda drink")) { //If items equal both herbal supplements and soda drinks
  49.        if (items.get(i).getPrice() > 0 ) {//If the price is greater  than 0 then subtract one from the price of the soda drink//
  50.         items.get(i).setPrice(items.get(i).getPrice() -1);
  51.        }
  52.        if (items.get(i).getNumberOfDaysToSellIn() > 0) {
  53.         items.get(i).setNumberOfDaysToSellIn(items.get(i).getNumberOfDaysToSellIn() -1); //If the days to sell is bigger than 0 then subtract one from the days to sell in//
  54.        
  55.        }
  56.       }
  57.      }
  58.      
  59.      
  60.  
  61.  }
  62.      
  63.         public void parmesans () {   //METHOD FOR parmesans
  64.          for (int i = 0; i < items.size();i++) {
  65.           if (items.get(i).getName().equals("Aged Parmesan cheese") && items.get(i).getPrice() < 50){
  66.             items.get(i).setPrice(items.get(i).getPrice() + 1);//price of item is never more than 50 units,. The price of parmesan increases as days get closer hence the +1
  67.            if (items.get(i).getNumberOfDaysToSellIn() > 0){
  68.              items.get(i).setNumberOfDaysToSellIn(items.get(i).getNumberOfDaysToSellIn() - 1);//If the days to sell is bigger than 0 then subtract one from the days to sell in
  69.            }
  70.           }
  71.          }        
  72.        
  73.         }  
  74.    
  75.        
  76.     public void worldwarMedals (){
  77.      for (int i=0; i<items.size();i++) {
  78.       if (items.get(i).getName().equals("World War Medals"))//If item equals a product named "World war Medals"
  79.       items.get(i).setPrice(items.get(i).getPrice());//find  price and set the price. war medals are fixed price. never changes//
  80.       items.get(i).setNumberOfDaysToSellIn(items.get(i).getNumberOfDaysToSellIn());//this price never has to be sold or never decreases in price. Thats why i never put -1 or +1
  81.          
  82.      
  83.      }
  84.        
  85.    
  86.     }
  87.        
  88.     public void Concertticket (){
  89.      for(int i = 0; i < items.size(); i++){
  90.       if(items.get(i).getName().equals("Tickets to Iron Maiden concert")){//if item equals iron maiden concert//
  91.        if (items.get(i).getNumberOfDaysToSellIn() == 0){//if number of days to sell in were 0 then return true.
  92.         items.get(i).setNumberOfDaysToSellIn(0);//set number of days to sell to 0
  93.         items.get(i).setPrice(0);//and set the price to 0.
  94.        }//if the above statement is not true then follow the below statement
  95.        else if(items.get(i).getNumberOfDaysToSellIn() > 10){//If the days to sell is bigger than 10 then subtract one from the days to sell in/
  96.         items.get(i).setNumberOfDaysToSellIn(items.get(i).getNumberOfDaysToSellIn() - 1);
  97.         if(items.get(i).getPrice() < 50){// if the price for a ticket is greater than 50
  98.          items.get(i).setPrice(items.get(i).getPrice() + 1);//the price increases by 2 units
  99.         }
  100.        }
  101.        else if(items.get(i).getNumberOfDaysToSellIn() < 11 && items.get(i).getNumberOfDaysToSellIn() > 5){// If the number of days to sell is greater than 11 and the number of days to sell is greater than 5
  102.         if (items.get(i).getPrice() < 50){ //if the price of a ticket is greater than 50
  103.          items.get(i).setPrice(items.get(i).getPrice() + 2);//the price increases by 2 units
  104.         }
  105.         items.get(i).setNumberOfDaysToSellIn(items.get(i).getNumberOfDaysToSellIn() - 1);//the number of days to sell decreases by one unit//
  106.        }
  107.        else{
  108.         if (items.get(i).getPrice() < 50){//if the price of a unit is over 50
  109.          items.get(i).setPrice(items.get(i).getPrice() + 3);//price increases by 3 units
  110.         }
  111.         if(items.get(i).getNumberOfDaysToSellIn() > 0){//if days to sell are greater than 0
  112.  
  113.          items.get(i).setNumberOfDaysToSellIn(items.get(i).getNumberOfDaysToSellIn() - 1);//if the days to sell is bigger than 0 then subtract one from the days to sell in//
  114.         }
  115.        }
  116.       }
  117.      }
  118.     }
  119.  
  120.     public void Spcake (){//method for special cakes
  121.      for (int i=0; i< items.size(); i++) {
  122.       if (items.get(i).getName().equals("Special cake baked in store")) { //if the item equals special  cake baked in store
  123.        if (items.get(i).getPrice() > 1) {//If the selling  price is bigger than 1 then subtract 2 from the price and this will be set as a new price.// This is becasue they degrade twice as fast than normal items
  124.         items.get(i).setPrice(items.get(i).getPrice() -2);
  125.              
  126.        }
  127.        if (items.get(i).getNumberOfDaysToSellIn() > 0) {//If the days to sell is bigger than 0 then subtract one from the days to sell in//
  128.         items.get(i).setNumberOfDaysToSellIn(items.get(i).getNumberOfDaysToSellIn() -1);
  129.        
  130.        }
  131.       }
  132.      }
  133.  
  134. }
  135.  
  136.  
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement