Obeject-oriented Design: Furniture

Design a OO system for furniture where there are wooden chairs and tables, metal chairs and tables. There are stress and fire tests for each products.

这段是java代码,而且有两段忘记写了,可以作为参考

  1 public interface Furniture {

  2     public void stressTest();

  3     public void fireTest();

  4 }

  5 

  6 public abstract class Chair implements Furniture {

  7 public abstract String chairType();

  8 

  9 }

 10 public abstract class Table implements Furniture {

 11  public abstract String tableType();

 12 }

 13 

 14 public class MetalChair extends Chair {

 15     @Override

 16     public void stressTest() {

 17         //To change body of implemented methods use File | Settings | File Templates.

 18     }

 19 

 20     @Override

 21     public void fireTest() {

 22         //To change body of implemented methods use File | Settings | File Templates.

 23     }

 24 }

 25 

 26 public class MetalTable extends Table {

 27     @Override

 28     public void stressTest() {

 29 

 30         System.out.println("Passed Stress Test");

 31         //To change body of implemented methods use File | Settings | File Templates.

 32     }

 33 

 34     @Override

 35     public void fireTest() {

 36         //To change body of implemented methods use File | Settings | File Templates.

 37         System.out.println("Passed Fire Test");

 38     }

 39 

 40     @Override

 41     public String tableType() {

 42         //To change body of implemented methods use File | Settings | File Templates.

 43         String s = "This is a metal Table";

 44         return s;

 45     }

 46 }

 47 

 48 

 49 public class WoodenTable extends Table {

 50     @Override

 51     public void stressTest() {

 52         //To change body of implemented methods use File | Settings | File Templates.

 53         System.out.println("Failed Stress Test");

 54     }

 55 

 56     @Override

 57     public void fireTest() {

 58         //To change body of implemented methods use File | Settings | File Templates.

 59         System.out.println("Failed Fire Test");

 60     }

 61 

 62     @Override

 63     public String tableType() {

 64         //To change body of implemented methods use File | Settings | File Templates.

 65         String s = "This is a wooden Table";

 66         return s;

 67     }

 68 }

 69 

 70 

 71 public class WoodenChair extends Chair {

 72     @Override

 73     public void stressTest() {

 74         //To change body of implemented methods use File | Settings | File Templates.

 75     }

 76 

 77     @Override

 78     public void fireTest() {

 79         //To change body of implemented methods use File | Settings | File Templates.

 80     }

 81 }

 82 

 83 public class MainClass {

 84     public static void main(String[] args){

 85         Table table = null;

 86         Scanner input =  new Scanner(System.in);

 87         String str = input.next();

 88         if(str.equals("wooden")){

 89             table = new WoodenTable();

 90 

 91 

 92         }   else if (str.equals("metal")){

 93             table = new MetalTable();

 94 

 95 

 96         }

 97 

 98         System.out.println(table.tableType());

 99         table.stressTest();

100         table.fireTest();

101 

102     }

103 }

 

你可能感兴趣的:(design)