Discuss / Java / 交作业

交作业

Topic source

伍亦勤

#1 Created at ... [Delete] [Delete and Lock User]

Main方法中

		AbstractFactory Factory = AbstractFactory.createFactory("good");
		HtmlDocument Html = Factory.createHtml("#Hello\nHello, world!");
		System.out.println(Html.toHtml());
		goodHtml.save(Paths.get(".", "good.html"));
		WordDocument Word = Factory.createWord("#Hello\nHello, world!");
		goodWord.save(Paths.get(".", "good.doc"));	

AbstractFactory.java

	public static AbstractFactory createFactory(String name) {
		if (name.equalsIgnoreCase("fast")) {
			return new FastFactory();
		} else if (name.equalsIgnoreCase("good")) {
			return new GoodFactory();
		} else {
			throw new IllegalArgumentException("Invalid factory name");
		}
	}

  • 1

Reply