Update
This commit is contained in:
parent
3821a5ca26
commit
909243510c
6 changed files with 26 additions and 18 deletions
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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";
|
||||
|
||||
|
|
|
@ -17,5 +17,8 @@ public class FurnitureCompany{
|
|||
return this.allFurniture;
|
||||
}
|
||||
|
||||
public void addFurniture(Furniture furniture) {
|
||||
allFurniture.add(furniture);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -42,15 +42,18 @@ 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 {
|
||||
}
|
||||
if(!found) {
|
||||
System.out.println("There is no furniture of model "+modelName);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
b2.addActionListener(new ActionListener() {
|
||||
|
@ -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();
|
||||
|
|
|
@ -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());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue