Java: Uso de de la clase Scanner.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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