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

@ -16,6 +16,9 @@ public class FurnitureCompany{
public ArrayList<Furniture> getAllFurnitures() {
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();
found = true;
System.out.println(furniture.getInfo());
break;
}
else {
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);
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

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