Autor Tema: [Java] Diganme retos (No muy complicados)  (Leído 2129 veces)

Desconectado Nasty35

  • PHPer@
  • **
  • Mensajes: 60
  • Karma: 0
  • Sexo: Masculino
  • Intento aprender
    • Ver Perfil
    • LioMet ~ Tu mejor opción
[Java] Diganme retos (No muy complicados)
« en: 18 de Abril de 2012, 16:05:01 pm »
Estoy aprendiendo Java, y quiero que me hagan retos para mejorar lo aprendido, así como practicar.
Que no sea muy difícil, y sea de lógica o pensar...

Bueno, gracias y saludos  ;)



<?php
class Phperos {
    
$private name;
    public static function 
setName($name) { self::name $name;  }
	
public static function 
getName() {  return self::name; }
}
Phperos::setName(&#39;Nasty35&#39;);
echo &#39;Soy &#39; . Phperos::getName();
?>

Comunidad PHPeros

[Java] Diganme retos (No muy complicados)
« en: 18 de Abril de 2012, 16:05:01 pm »

Desconectado Physlet

  • PHPero Experto
  • *****
  • Mensajes: 822
  • Karma: 41
  • Sexo: Masculino
  • Todo es posible con esfuerzo, dedicación e interés
    • Ver Perfil
    • PanamaDev
Re:[Java] Diganme retos (No muy complicados)
« Respuesta #1 en: 19 de Abril de 2012, 04:27:36 am »
Imprimir el código fuente de cualquier página web.

Desconectado Nasty35

  • PHPer@
  • **
  • Mensajes: 60
  • Karma: 0
  • Sexo: Masculino
  • Intento aprender
    • Ver Perfil
    • LioMet ~ Tu mejor opción
Re:[Java] Diganme retos (No muy complicados)
« Respuesta #2 en: 19 de Abril de 2012, 14:58:54 pm »
Imprimir el código fuente de cualquier página web.
Sinceramente eso no se como se hace ni haría,
¿Cómo se hace?

Dame otro reto  :P no tan raro como ese.



<?php
class Phperos {
    
$private name;
    public static function 
setName($name) { self::name $name;  }
	
public static function 
getName() {  return self::name; }
}
Phperos::setName(&#39;Nasty35&#39;);
echo &#39;Soy &#39; . Phperos::getName();
?>

Desconectado -Pituko-

  • PHPero Experto
  • *****
  • Mensajes: 954
  • Karma: 20
  • Sexo: Masculino
  • ¡Hala Madrid!
    • Ver Perfil
Re:[Java] Diganme retos (No muy complicados)
« Respuesta #3 en: 19 de Abril de 2012, 17:32:38 pm »
Sinceramente eso no se como se hace ni haría,
¿Cómo se hace?

Dame otro reto  :P no tan raro como ese.
Obtienes el contenido de una web y lo muestras como texto. Encima el tutorial circula por todo internet.

Desconectado Physlet

  • PHPero Experto
  • *****
  • Mensajes: 822
  • Karma: 41
  • Sexo: Masculino
  • Todo es posible con esfuerzo, dedicación e interés
    • Ver Perfil
    • PanamaDev
Re:[Java] Diganme retos (No muy complicados)
« Respuesta #4 en: 20 de Abril de 2012, 07:32:39 am »
Sinceramente eso no se como se hace ni haría,
¿Cómo se hace?

Dame otro reto  :P no tan raro como ese.
Mejor te pregunto, ¿qué sabes de Java?

Desconectado Nasty35

  • PHPer@
  • **
  • Mensajes: 60
  • Karma: 0
  • Sexo: Masculino
  • Intento aprender
    • Ver Perfil
    • LioMet ~ Tu mejor opción
Re:[Java] Diganme retos (No muy complicados)
« Respuesta #5 en: 03 de Agosto de 2012, 22:08:30 pm »
Siento revivir tema pero no quiero crear otro, estuve leyendo libros y ya se más de Java.
Digan retos! creo que estoy listo para cualquier cosa :P
Preferiblemente algoritmos de pensar, y cosas así, no tocar mucho librerías ni cosas tipo mostrar código de fuente.
Lo de mostrar el código de fuente hice un programa hace unos meses, aquí dejo el código de fuente:
Código: [Seleccionar]
package codigodefuente;
import java.io.*;
import java.net.*;
import java.util.*;

/**
 *
 * @author Daniel
 */
public class CodigoDeFuente extends javax.swing.JFrame {

    private URL url;
    private URLConnection con;
    private InputStream s;
    private BufferedReader b;
    private static Scanner sc;
   
    public CodigoDeFuente() {
        setTitle("Extrae la source de alguna página web.");
        initComponents();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton1 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextPane1 = new javax.swing.JTextPane();
        jTextField1 = new javax.swing.JTextField();
        jButton2 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jButton1.setText("Mostrar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jScrollPane1.setViewportView(jTextPane1);

        jTextField1.setText("http://");

        jButton2.setText("Guardar");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 470, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton2))
                    .addComponent(jScrollPane1))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton2))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 378, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        String link = jTextField1.getText();
        try {
        url = new java.net.URL(link);
        con = url.openConnection();
        s = con.getInputStream();
        b = new BufferedReader(new InputStreamReader(s));
        String line = "";
        jTextPane1.setText(line);
        while((line = b.readLine())!=null){
            String code = jTextPane1.getText();
            jTextPane1.setText(code + line + "\n");
        } } catch (Exception e) {
            e.printStackTrace();
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        String link2, link3;
        String link = jTextField1.getText();
        String tcode = jTextPane1.getText();
        link2 = link.replace("http://","");
        link3 = link2.replace("/","");
        try {
            BufferedWriter bw = new BufferedWriter(new FileWriter(link3 + ".html"));
            bw.append(tcode);
            bw.flush();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }//GEN-LAST:event_jButton2ActionPerformed

    public static void main(String args[]) {
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(CodigoDeFuente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(CodigoDeFuente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(CodigoDeFuente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(CodigoDeFuente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new CodigoDeFuente().setVisible(true);
            }
        });
        sc = new Scanner(System.in);
        String exi = sc.next();
        switch(exi) {
            case "Close":
            case "close":
            case "Cerrar":
            case "cerrar":
                System.exit(0);
            default:
                break;
        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextPane jTextPane1;
    // End of variables declaration//GEN-END:variables
}



<?php
class Phperos {
    
$private name;
    public static function 
setName($name) { self::name $name;  }
	
public static function 
getName() {  return self::name; }
}
Phperos::setName(&#39;Nasty35&#39;);
echo &#39;Soy &#39; . Phperos::getName();
?>