Last active
November 8, 2021 14:59
-
-
Save kurotori/81c7735baad1c5d320cd090a9926b152 to your computer and use it in GitHub Desktop.
Ejercicio de Código 02
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 Incio { | |
public static void main(String[] args) { | |
System.out.println("Iniciando una nueva partida..."); | |
Partida nuevaPartida = new Partida(); | |
nuevaPartida.VerPuntajes(); | |
} | |
} |
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 Partida { | |
private String titulo; | |
private Usuario propietario; | |
private Usuario[] jugadores = new Usuario[3]; | |
public Partida(){ | |
Scanner teclado = new Scanner(System.in); | |
System.out.println("Hola, ¿Cuál es tu nombre?"); | |
String nombre = teclado.nextLine(); | |
System.out.println("¿Cuál es tu apellido?"); | |
String apellido = teclado.nextLine(); | |
propietario = new Usuario(nombre, apellido); | |
System.out.println("Agrega un título a la partida:"); | |
titulo = teclado.nextLine(); | |
System.out.println("Agrega los datos de los jugadores:"); | |
for (int posicion = 0; posicion < jugadores.length ; posicion++) { | |
System.out.println("Jugador " + (posicion+1)); | |
System.out.println("Nombre:"); | |
String nombreJ = teclado.nextLine(); | |
System.out.println("Apellido:"); | |
String apellidoJ = teclado.nextLine(); | |
Usuario jugador = new Usuario(nombreJ, apellidoJ); | |
jugadores[posicion] = jugador; | |
} | |
teclado.close(); | |
} | |
public void VerPuntajes(){ | |
System.out.println("Propietario: "); | |
System.out.println(propietario.getNombre()); | |
System.out.println(propietario.getPuntaje() + " puntos"); | |
for (int posicion = 0; posicion < jugadores.length ; posicion++) { | |
System.out.println("Jugador " + (posicion+1)); | |
System.out.println(jugadores[posicion].getNombre()); | |
System.out.println(jugadores[posicion].getPuntaje() + " puntos"); | |
} | |
} | |
} |
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 Usuario { | |
private String nombre; | |
private String apellido; | |
private int puntaje; | |
public Usuario(String nombre, String apellido){ | |
this.nombre = nombre; | |
this.apellido = apellido; | |
this.puntaje = 0; | |
} | |
public Usuario(){ | |
this.nombre = ""; | |
this.apellido = ""; | |
this.puntaje = 0; | |
} | |
public String getNombre() { | |
return nombre; | |
} | |
public String getApellido() { | |
return apellido; | |
} | |
public int getPuntaje() { | |
return puntaje; | |
} | |
public void setPuntaje(int puntaje) { | |
this.puntaje = puntaje; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment