Skip to content

Instantly share code, notes, and snippets.

@alvareztech
Last active June 11, 2017 00:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alvareztech/1b75cf4393ac4887bed5afcf8627e1e0 to your computer and use it in GitHub Desktop.
Save alvareztech/1b75cf4393ac4887bed5afcf8627e1e0 to your computer and use it in GitHub Desktop.
Java: Uso de de la clase Scanner.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// Scanner scanner = new Scanner(System.in);
// System.out.print("Nombre:");
// String nombre = scanner.nextLine();
// System.out.println(nombre);
// System.out.print("Edad:");
// int edad = Integer.parseInt(scanner.nextLine(3));
// System.out.println(edad);
Scanner scanner = new Scanner(System.in);
Materia m1 = new Materia();
System.out.print("Nombre: ");
String nombre = scanner.nextLine();
System.out.print("Sigla: ");
String sigla = scanner.nextLine();
System.out.print("Docente: ");
String docente = scanner.nextLine();
System.out.print("Nota: ");
int nota = Integer.parseInt(scanner.nextLine());
m1.setNombre(nombre);
m1.setSigla(sigla);
m1.setDocente(docente);
m1.setNota(nota);
System.out.println(m1.getNombre() + " " + m1.getSigla() + " " + m1.getDocente() + " " + m1.getNota());
}
}
public class Materia {
private String nombre;
private String sigla;
private String docente;
private int nota;
public Materia(String nombre, String sigla, String docente, int nota) {
this.nombre = nombre;
this.sigla = sigla;
this.docente = docente;
this.nota = nota;
}
public Materia() {
this.nombre = "";
this.sigla = "";
this.docente = "";
this.nota = 0;
}
public String getNombre() {
return nombre;
}
public void setNombre(String nombre) {
this.nombre = nombre;
}
public String getSigla() {
return sigla;
}
public void setSigla(String sigla) {
this.sigla = sigla;
}
public String getDocente() {
return docente;
}
public void setDocente(String docente) {
this.docente = docente;
}
public int getNota() {
return nota;
}
public void setNota(int nota) {
this.nota = nota;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment