👔 Code the model

main
Alexis Drai 3 years ago
parent 6ff2fdfd95
commit 6dddd3bdcf

@ -4,12 +4,15 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="39201d7d-d87b-4c10-b0b0-e462b4f0b033" name="Changes" comment="">
<change afterPath="$PROJECT_DIR$/resources/fxml/MainWindow.fxml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/launcher/Launcher.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/view/MainWindow.java" afterDir="false" />
<list default="true" id="39201d7d-d87b-4c10-b0b0-e462b4f0b033" name="Changes" comment=":truck: Set up main window">
<change afterPath="$PROJECT_DIR$/src/data/Loadable.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/data/Stub.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/model/Garment.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/model/Perfume.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/model/Product.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/model/Shop.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/model/Size.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/EShop.iml" beforeDir="false" afterPath="$PROJECT_DIR$/EShop.iml" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -65,6 +68,21 @@
<option name="presentableId" value="Default" />
<updated>1665142782644</updated>
</task>
<task id="LOCAL-00001" summary=":truck: Set up main window">
<created>1665143728540</created>
<option name="number" value="00001" />
<option name="presentableId" value="LOCAL-00001" />
<option name="project" value="LOCAL" />
<updated>1665143728540</updated>
</task>
<task id="LOCAL-00002" summary=":truck: Set up main window">
<created>1665143741578</created>
<option name="number" value="00002" />
<option name="presentableId" value="LOCAL-00002" />
<option name="project" value="LOCAL" />
<updated>1665143741578</updated>
</task>
<option name="localTasksCounter" value="3" />
<servers />
</component>
<component name="Vcs.Log.Tabs.Properties">
@ -78,4 +96,8 @@
</map>
</option>
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value=":truck: Set up main window" />
<option name="LAST_COMMIT_MESSAGE" value=":truck: Set up main window" />
</component>
</project>

@ -0,0 +1,7 @@
package data;
import model.Shop;
interface Loadable {
Shop load();
}

@ -0,0 +1,34 @@
package data;
import model.*;
public class Stub implements Loadable {
@Override
public Shop load() {
Shop shop = new Shop();
Garment p1 = new Garment("shirt", 15.9);
p1.addAllSizes();
Garment p2 = new Garment("sweater", 34.9);
p1.addSize(Size.valueOf("XXL"));
p1.addSize(Size.valueOf("XXS"));
p1.addSize(Size.valueOf("XS"));
Perfume p3 = new Perfume("spiderman", 89.9);
p3.addSmell("woody");
p3.addSmell("musky");
Perfume p4 = new Perfume("boring", 143.9);
p3.addSmell("flowery");
p3.addSmell("acidic");
shop.addProduct(p1);
shop.addProduct(p2);
shop.addProduct(p3);
shop.addProduct(p4);
return shop;
}
}

@ -0,0 +1,38 @@
package model;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class Garment extends Product {
// private List<Color> colors = new ArrayList<>();
/**
* if there are 3 shirts in M, the list will contain M, M, M
*/
private final List<Size> sizes = new ArrayList<>();
public Garment(String name, double price) {
super(name, price);
}
public void addSize(Size size) {
sizes.add(size);
}
public void addAllSizes() {
sizes.addAll(Arrays.asList(Size.values()));
}
public List<Size> getSizes() {
return Collections.unmodifiableList(sizes);
}
public void removeSize(Size size) {
sizes.remove(size);
}
}

@ -0,0 +1,27 @@
package model;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Perfume extends Product {
private final List<String> smells = new ArrayList<>();
public Perfume(String name, double price) {
super(name, price);
}
public void addSmell(String smell) {
smells.add(smell);
}
public List<String> getSmells() {
return Collections.unmodifiableList(smells);
}
public void removeSmell(String smell) {
smells.remove(smell);
}
}

@ -0,0 +1,30 @@
package model;
public abstract class Product {
private String name;
private double price;
public Product(String name, double price) {
this.name = name;
this.price = price;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(float price) {
this.price = price;
}
}

@ -0,0 +1,22 @@
package model;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Shop {
private final List<Product> products = new ArrayList<>();
public void addProduct(Product product) {
products.add(product);
}
public List<Product> getProducts() {
return Collections.unmodifiableList(products);
}
public void removeProduct(Product product) {
products.remove(product);
}
}

@ -0,0 +1,14 @@
package model;
/**
* XXS to XXL
*/
public enum Size {
XXS,
XS,
S,
M,
L,
XL,
XXL
}
Loading…
Cancel
Save