Proterty color Interior + prix pour les Part

This commit is contained in:
trochas
2024-12-04 17:04:18 +01:00
parent d9e14bdd9f
commit e1a5373c90
6 changed files with 80 additions and 46 deletions

View File

@@ -2,6 +2,7 @@ package src.fr.impl;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
@@ -16,9 +17,11 @@ import src.fr.api.PartType;
public class PartImpl implements Part {
private PartType type;
private int price;
public PartImpl(PartType type){
public PartImpl(PartType type, int price){
this.type = type;
this.price = price;
}
private class Property {
@@ -80,4 +83,8 @@ public class PartImpl implements Part {
public PartType getType(){
return this.type;
}
public int getPrice(){
return this.price;
}
}

View File

@@ -1,27 +1,18 @@
package src.fr.impl.Parts;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
import org.junit.Test.None;
import src.fr.impl.CategoryImpl;
import src.fr.impl.PartImpl;
import src.fr.impl.PartTypeImpl;
public class Engine extends PartImpl {
public Engine(String name, CategoryImpl category){
super(new PartTypeImpl(name,Engine.class, category));
//init_prix();
//this.addProperty("prix", () -> Integer.toString(getPrix()), null, getPropertyNames());
}
private HashMap<String,Integer> table_prix;
private void init_prix(){
table_prix.put("EG100",100);
}
public int getPrix(){
return table_prix.get(this.getName());
public Engine(String name, CategoryImpl category, int price){
super(new PartTypeImpl(name,Engine.class, category),price);
}
}

View File

@@ -1,11 +1,46 @@
package src.fr.impl.Parts;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
import src.fr.impl.CategoryImpl;
import src.fr.impl.PartImpl;
import src.fr.impl.PartTypeImpl;
public class Exterior extends PartImpl {
public Exterior(String name, CategoryImpl category){
super(new PartTypeImpl(name,Engine.class, category));
public class Exterior extends PartImpl {
private static final Set<String> colorSet;
static {
colorSet = new HashSet<>();
colorSet.add("white");
colorSet.add("green");
colorSet.add("red");
colorSet.add("blue");
colorSet.add("green");
colorSet.add("gray");
}
public Exterior(String name, CategoryImpl category, int price){
super(new PartTypeImpl(name,Engine.class, category),price);
Set<String> l = new HashSet<String>();
l.add("red");
this.addProperty("color", () -> getColor(), p -> setColor(p), colorSet);
}
public String getColor(){
String result = "white";
Optional<String> color = this.getProperty("color");
if(color.isPresent()){
result = color.get();
}
return result;
}
public void setColor(String newColor){
this.setProperty("color",newColor);
}
}

View File

@@ -5,7 +5,7 @@ import src.fr.impl.PartImpl;
import src.fr.impl.PartTypeImpl;
public class Interior extends PartImpl {
public Interior(String name, CategoryImpl category){
super(new PartTypeImpl(name,Engine.class, category));
public Interior(String name, CategoryImpl category, int price){
super(new PartTypeImpl(name,Engine.class, category), price);
}
}

View File

@@ -5,7 +5,7 @@ import src.fr.impl.PartImpl;
import src.fr.impl.PartTypeImpl;
public class Transmission extends PartImpl {
public Transmission(String name, CategoryImpl category){
super(new PartTypeImpl(name,Engine.class, category));
public Transmission(String name, CategoryImpl category, int price){
super(new PartTypeImpl(name,Engine.class, category),price);
}
}