Permalink
Browse files

1ª versão exercicio template method

  • Loading branch information...
1 parent 061132f commit 7611ac6f06c8e7c8d5dcc9127bc81d20fcc057fc @sergiocampos committed May 20, 2012
Showing with 142 additions and 0 deletions.
  1. +75 −0 src/templateMethod/Documento.java
  2. +29 −0 src/templateMethod/HTML.java
  3. +11 −0 src/templateMethod/Main.java
  4. +27 −0 src/templateMethod/MarkDown.java
@@ -0,0 +1,75 @@
+package templateMethod;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+public abstract class Documento {
+
+ private String nome;
+ private String profissao;
+ private String email;
+
+
+ public Documento(String n, String p, String e){
+ this.nome = n;
+ this.profissao = p;
+ this.email = e;
+
+ }
+
+
+ public String getNome() {
+ return nome;
+ }
+
+
+
+ public String getProfissao() {
+ return profissao;
+ }
+
+
+ public String getEmail() {
+ return email;
+ }
+
+
+ public File criarArquivo(String nome){
+ File arq = new File(nome);
+ try {
+ arq.createNewFile();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return arq;
+ }
+ /*
+ public void escreverMarkDown(String st) throws IOException{
+ File arq = criarArquivo(st);
+ FileOutputStream saida = null;
+ try {
+ saida = new FileOutputStream(arq);
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ }
+ saida.write(("# "+getNome()+"\n\n"+getProfissao()+"\n\n"+getEmail()).getBytes());
+ }
+
+ public void escreverHtml(String st) throws IOException{
+ File arq = criarArquivo(st);
+ FileOutputStream saida = null;
+ try {
+ saida = new FileOutputStream(arq);
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ }
+ saida.write(("<html>\n<body>\n<h1>"+getNome()+ "</h1>\n<p>" + getProfissao() + "</p>\n<p>" + getEmail() + "</p>\n</body>\n</html>\n").getBytes());
+ }*/
+
+ protected abstract String escrever(String texto) throws IOException;
+
+
+
+}
@@ -0,0 +1,29 @@
+package templateMethod;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+public class HTML extends Documento{
+
+ public HTML(String n, String p, String e) {
+ super(n, p, e);
+ }
+ protected String escrever(String texto) throws IOException{
+
+ File arq = criarArquivo(texto);
+ FileOutputStream saida = null;
+ try {
+ saida = new FileOutputStream(arq);
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ }
+ saida.write(("<html>\n<body>\n<h1>"+getNome()+ "</h1>\n<p>" + getProfissao() + "</p>\n<p>" + getEmail() + "</p>\n</body>\n</html>\n").getBytes());
+
+
+ return null;
+
+ }
+
+}
@@ -0,0 +1,11 @@
+package templateMethod;
+
+public class Main {
+
+ public static void main(String[] args) {
+ Documento d = new HTML("sergio", "tecnico", "sergio@gmail.com");
+ d.criarArquivo("pas1");
+
+ }
+
+}
@@ -0,0 +1,27 @@
+package templateMethod;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+public class MarkDown extends Documento{
+
+ public MarkDown(String n, String p, String e) {
+ super(n, p, e);
+ }
+ protected String escrever(String texto) throws IOException{
+ File arq = criarArquivo(texto);
+ FileOutputStream saida = null;
+ try {
+ saida = new FileOutputStream(arq);
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ }
+ saida.write(("# "+getNome()+"\n\n"+getProfissao()+"\n\n"+getEmail()).getBytes());
+
+
+ return null;
+ }
+
+}

0 comments on commit 7611ac6

Please sign in to comment.