Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package uk.ac.brunel.cs1702;
- import java.util.ArrayList;
- import java.util.List;
- public class MyStore {
- 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
- public MyStore() {
- this.items = new ArrayList<ItemForSale>();//creation of my store construcor which assigns this class's list as an array list//
- }
- 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
- this.items = items;
- }
- public static void main(String[] args) {//main method//
- MyStore myStore = new MyStore();//creating a new object of this very class (My store)//
- 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.
- myStore.items.add(new ItemForSale("Aged Parmesan cheese", 20, 10));
- myStore.items.add(new ItemForSale("Local soda drink", 20, 3));
- 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.
- myStore.items.add(new ItemForSale("Tickets to Iron Maiden concert", 15, 20));
- 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.
- myStore.updateInventory();
- System.out.println("Inventory Updated!");//will outprint the update inventory//
- }
- public void updateInventory() {//update inventory is a variable for all the updates that will occur//
- herbalSodas();//items//
- parmesans();//items//
- worldwarMedals();//items//
- Concertticket();//items//
- Spcake();//items//
- }
- public void herbalSodas () {
- for (int i=0; i< items.size(); i++) {
- 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
- if (items.get(i).getPrice() > 0 ) {//If the price is greater than 0 then subtract one from the price of the soda drink//
- items.get(i).setPrice(items.get(i).getPrice() -1);
- }
- if (items.get(i).getNumberOfDaysToSellIn() > 0) {
- 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//
- }
- }
- }
- }
- public void parmesans () { //METHOD FOR parmesans
- for (int i = 0; i < items.size();i++) {
- if (items.get(i).getName().equals("Aged Parmesan cheese") && items.get(i).getPrice() < 50){
- 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
- if (items.get(i).getNumberOfDaysToSellIn() > 0){
- 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
- }
- }
- }
- }
- public void worldwarMedals (){
- for (int i=0; i<items.size();i++) {
- if (items.get(i).getName().equals("World War Medals"))//If item equals a product named "World war Medals"
- items.get(i).setPrice(items.get(i).getPrice());//find price and set the price. war medals are fixed price. never changes//
- 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
- }
- }
- public void Concertticket (){
- for(int i = 0; i < items.size(); i++){
- if(items.get(i).getName().equals("Tickets to Iron Maiden concert")){//if item equals iron maiden concert//
- if (items.get(i).getNumberOfDaysToSellIn() == 0){//if number of days to sell in were 0 then return true.
- items.get(i).setNumberOfDaysToSellIn(0);//set number of days to sell to 0
- items.get(i).setPrice(0);//and set the price to 0.
- }//if the above statement is not true then follow the below statement
- 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/
- items.get(i).setNumberOfDaysToSellIn(items.get(i).getNumberOfDaysToSellIn() - 1);
- if(items.get(i).getPrice() < 50){// if the price for a ticket is greater than 50
- items.get(i).setPrice(items.get(i).getPrice() + 1);//the price increases by 2 units
- }
- }
- 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
- if (items.get(i).getPrice() < 50){ //if the price of a ticket is greater than 50
- items.get(i).setPrice(items.get(i).getPrice() + 2);//the price increases by 2 units
- }
- items.get(i).setNumberOfDaysToSellIn(items.get(i).getNumberOfDaysToSellIn() - 1);//the number of days to sell decreases by one unit//
- }
- else{
- if (items.get(i).getPrice() < 50){//if the price of a unit is over 50
- items.get(i).setPrice(items.get(i).getPrice() + 3);//price increases by 3 units
- }
- if(items.get(i).getNumberOfDaysToSellIn() > 0){//if days to sell are greater than 0
- 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//
- }
- }
- }
- }
- }
- public void Spcake (){//method for special cakes
- for (int i=0; i< items.size(); i++) {
- if (items.get(i).getName().equals("Special cake baked in store")) { //if the item equals special cake baked in store
- 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
- items.get(i).setPrice(items.get(i).getPrice() -2);
- }
- if (items.get(i).getNumberOfDaysToSellIn() > 0) {//If the days to sell is bigger than 0 then subtract one from the days to sell in//
- items.get(i).setNumberOfDaysToSellIn(items.get(i).getNumberOfDaysToSellIn() -1);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement