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() {
|
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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";
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,9 @@ public class FurnitureCompany{
|
||||||
public ArrayList<Furniture> getAllFurnitures() {
|
public ArrayList<Furniture> getAllFurnitures() {
|
||||||
return this.allFurniture;
|
return this.allFurniture;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addFurniture(Furniture furniture) {
|
||||||
|
allFurniture.add(furniture);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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());
|
||||||
|
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);
|
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();
|
||||||
|
|
|
@ -7,8 +7,12 @@ public class Main {
|
||||||
Furniture b1 = new Bookcase("Ikea",70,3,8);
|
Furniture b1 = new Bookcase("Ikea",70,3,8);
|
||||||
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());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue