Return to Home Courses

 

Homework (a)

class DoMain {

public static void main (String[] args) throws IOException {

  NameFactory nA, nB;
	
  System.out.println("ASking for the 1st Singleton");
  nA = NameFactory.Instance();
  if(nA != null) System.out.println("got 1st Singleton");  
  
  System.out.println("Asking for another Singleton");
  nB = NameFactory.Instance();
  if(nB == null) System.out.println("Singleton is already created"); 
      
  Name n;
  String line;

  BufferedReader in = new BufferedReader(new InputStreamReader(System.in));  
  
  while (true) {        
    line = in.readLine();
    if (line.equals("/")) break;
	 
    //send the text to the factory and get a class back
    n = nA.getName(line);
	 
    //compute the first and last names
    //using the returned class   
	 System.out.println(
	   "F:" + n.getFirst() + "  L:" + n.getLast());
  }
}
}

Homework (b)

[DoMain.java] [GardenMaker.java] [Garden.java] [FlowerGarden.java] [HerbGarden.java] [VeggieGarden.java] [Plant.java]

© 2014–2015 Dinghuang Ji