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

View file

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

View file

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

View file

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

View file

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

View file

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