Code example for Scanner

Methods: hasNextnext

0
		root = null;
		filename = fn;
		if(filename.contains("A")){}
		try{ 
			fstream = new FileInputStream(filename);
			sc = new Scanner(fstream);
			if(sc.hasNext()){type = sc.next(); setProto(type);}
			if(sc.hasNext()){setRoot(sc);}
		}catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} 
	} 
 
	public void setProto(String s) {
		if(s.equals("A")){
			protoNT = new ConcreteProtoANT();
			protoT = new ConcreteProtoAT();
			fact = new ConcreteFactoryA();
		}else{ 
			fact = new ConcreteFactoryB();
			if(s.equals("B")){
				protoNT = new ConcreteProtoBNT();
				protoT = new ConcreteProtoBT(); 
			} 
		} 
 
	} 
	 
	public void setRoot(Scanner s){
		if(s.next().equals("N")){
			int x = Integer.parseInt(s.next()); int y = Integer.parseInt(s.next());
				root = 
					fact.makenonterminal(
							new Point(x,y), null, 0);
 
		}else{ 
			int x = Integer.parseInt(s.next()); int y = Integer.parseInt(s.next()); int v = Integer.parseInt(s.next());
			root = fact.maketerminal(new Point(x,y), null, v);
		} 
			 
		System.out.println(root.toString());
	}