This commit is contained in:
Anyx 2023-11-03 22:04:30 +02:00
parent 3821a5ca26
commit 909243510c
Signed by: a
GPG key ID: 43D8165FD2251985
6 changed files with 26 additions and 18 deletions

View file

@ -24,10 +24,10 @@ public class Bookcase extends Furniture{
public String chooseCategory() { public String chooseCategory() {
String aCategory=""; String aCategory="";
if(this.getCategory()==1) { if(this.getCategory()==1) {
return aCategory ="Plastic"; aCategory ="Plastic";
} }
else if(this.getCategory()==2) { else if(this.getCategory()==2) {
return aCategory = "Metallic"; aCategory = "Metallic";
}else if(this.getCategory()==3) { }else if(this.getCategory()==3) {
aCategory = "Wooden"; aCategory = "Wooden";
} }
@ -39,8 +39,7 @@ public class Bookcase extends Furniture{
} }
public String getInfo() { public String getInfo() {
super.getInfo(); return super.getInfo() + "Shelves: "+this.getShelves();
return "Shelves: "+this.getShelves();
} }

View file

@ -28,7 +28,7 @@ public class Chair extends Furniture{
return aCategory ="Office chair"; return aCategory ="Office chair";
} }
else if(this.getCategory()==2) { else if(this.getCategory()==2) {
return aCategory = "Cooperation Chair"; return aCategory = "Cooperation chair";
}else if(this.getCategory()==3) { }else if(this.getCategory()==3) {
aCategory = "Armchair"; aCategory = "Armchair";
} }
@ -36,7 +36,6 @@ public class Chair extends Furniture{
} }
public String getInfo() { public String getInfo() {
super.getInfo(); return super.getInfo() + "Fabric color: "+this.getColor();
return "Shelves: "+this.getColor();
} }
} }

View file

@ -38,8 +38,8 @@ public abstract class Furniture implements Comparable{
return model; return model;
} }
public String getInfo() { public String getInfo() {
return "-"+this.getClass()+"info:\n"+ return "- "+this.getClass().getName()+" info:\n"+
this.getModel()+","+this.calculatePrice()+"Euro: \n"+ this.getModel()+", "+this.calculatePrice()+" Euro: \n"+
"Category: "+this.chooseCategory()+"\n"+ "Category: "+this.chooseCategory()+"\n"+
"Weight: "+this.getWeight()+"\n"; "Weight: "+this.getWeight()+"\n";

View file

@ -17,5 +17,8 @@ public class FurnitureCompany{
return this.allFurniture; return this.allFurniture;
} }
public void addFurniture(Furniture furniture) {
allFurniture.add(furniture);
}
} }

View file

@ -42,14 +42,17 @@ public class FurnitureFrame extends JFrame{
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
String modelName =t1.getText(); String modelName =t1.getText();
boolean found = false;
for(Furniture furniture: allFurniture) { for(Furniture furniture: allFurniture) {
if(furniture.getModel().equals(modelName)) { if(furniture.getModel().equals(modelName)) {
furniture.getInfo(); found = true;
} System.out.println(furniture.getInfo());
else { break;
System.out.println("There is no furniture of model "+modelName);
} }
} }
if(!found) {
System.out.println("There is no furniture of model "+modelName);
}
} }
}); });
@ -64,11 +67,11 @@ public class FurnitureFrame extends JFrame{
FileWriter write = new FileWriter(f); FileWriter write = new FileWriter(f);
for(Furniture furniture:furnitures) { for(Furniture furniture:furnitures) {
if(furniture.chooseCategory().equals(textCategory)) { if(furniture.chooseCategory().equals(textCategory)) {
write.write(furniture.getInfo()); write.write(furniture.getInfo());
write.write(System.lineSeparator()); for(int i=0; i<2; i++) write.write(System.lineSeparator());
} }
} }
write.close();
} catch (IOException e1) { } catch (IOException e1) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e1.printStackTrace(); e1.printStackTrace();

View file

@ -8,7 +8,11 @@ public class Main {
Furniture c1 = new Chair("HermanMiller",40,2,"Grey"); Furniture c1 = new Chair("HermanMiller",40,2,"Grey");
FurnitureCompany bestFurniture = new FurnitureCompany(b1,c1); FurnitureCompany bestFurniture = new FurnitureCompany(b1,c1);
bestFurniture.addFurniture(b1);
bestFurniture.addFurniture(c1);
new FurnitureFrame(bestFurniture.getAllFurnitures()); new FurnitureFrame(bestFurniture.getAllFurnitures());
} }
} }