Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reto #49-java #7368

Closed
wants to merge 13 commits into from
113 changes: 113 additions & 0 deletions Roadmap/46 - X VS BLUESKY/java/JohnAlexGuerrero.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package org.example;

import java.util.HashSet;
import java.util.Objects;

// Press Shift twice to open the Search Everywhere dialog and type `show whitespaces`,
// then press Enter. You can now see whitespace characters in your code.
public class Main {
public static void main(String[] args) {
SocialNetwork socialnetwork = new SocialNetwork();

//- Registrar un usuario por defecto con nombre e identificador único.
socialnetwork.registerUser("u123", "alexander guerrero");
socialnetwork.registerUser("u456", "sandra estacio");
socialnetwork.registerUser("u467", "carolina maigual");
socialnetwork.registerUser("u897", "mileidy cruz");
socialnetwork.registerUser("u230", "daniel botina");
socialnetwork.registerUser("u239", "diego botina");
socialnetwork.registerUser("u348", "gloria maigual");
socialnetwork.registerUser("u438", "teresa maigual");
socialnetwork.registerUser("u489", "alejandra rojas");

//- Seleccionar un usuario
User u1 = socialnetwork.getUser("u489");
//- Un usuario puede seguir/dejar de seguir a otro.
u1.followUser("u348");
u1.followUser("u467");
u1.followUser("u897");

//- Mostrar usuarios
for (User user : socialnetwork.getUsers()) {
System.out.println(user.toString());
}
}
}

class SocialNetwork{
private static HashSet<User> users;
public SocialNetwork() {
users = new HashSet<>();
}
public void registerUser(String id, String name){
users.add(new User(id, name));
}
public User getUser(String id){
for(User user: users){
if(user.getId().equals(id)){
return user;
}
}
return null;
}
public void unfollowUser(){}
public HashSet<User> getUsers() {
return users;
}
}

class User{
private String id;
private String name;
private HashSet<String> followers;
private HashSet<String> following;
public void followUser(String followIdUser){
followers.add(followIdUser);
}

public User(String id, String name) {
this.id = id;
this.name = name;
this.followers = new HashSet<String>();
this.following = new HashSet<String>();
}

public String getId() {
return id;
}

public String getName() {
return name;
}

public HashSet<String> getFollowers() {
return followers;
}

public HashSet<String> getFollowing() {
return following;
}

@Override
public String toString() {
return "User{" +
"id='" + id + '\'' +
", name='" + name + '\'' +
", followers=" + followers +
", following=" + following +
'}';
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
User user = (User) o;
return Objects.equals(id, user.id) && Objects.equals(name, user.name) && Objects.equals(followers, user.followers) && Objects.equals(following, user.following);
}

@Override
public int hashCode() {
return Objects.hash(id, name, followers, following);
}
}
38 changes: 38 additions & 0 deletions Roadmap/46 - X VS BLUESKY/java/JohnAlexGuerrero/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr

### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/

### Mac OS ###
.DS_Store
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package org.example;

import java.util.HashSet;
import java.util.Objects;

// Press Shift twice to open the Search Everywhere dialog and type `show whitespaces`,
// then press Enter. You can now see whitespace characters in your code.
public class Main {
public static void main(String[] args) {
SocialNetwork socialnetwork = new SocialNetwork();

//- Registrar un usuario por defecto con nombre e identificador único.
socialnetwork.registerUser("u123", "alexander guerrero");
socialnetwork.registerUser("u456", "sandra estacio");
socialnetwork.registerUser("u467", "carolina maigual");
socialnetwork.registerUser("u897", "mileidy cruz");
socialnetwork.registerUser("u230", "daniel botina");
socialnetwork.registerUser("u239", "diego botina");
socialnetwork.registerUser("u348", "gloria maigual");
socialnetwork.registerUser("u438", "teresa maigual");
socialnetwork.registerUser("u489", "alejandra rojas");

//- Seleccionar un usuario
User u1 = socialnetwork.getUser("u489");
//- Un usuario puede seguir/dejar de seguir a otro.
u1.followUser("u348");
u1.followUser("u467");
u1.followUser("u897");

//- Mostrar usuarios
for (User user : socialnetwork.getUsers()) {
System.out.println(user.toString());
}
}
}

class SocialNetwork{
private static HashSet<User> users;
public SocialNetwork() {
users = new HashSet<>();
}
public void registerUser(String id, String name){
users.add(new User(id, name));
}
public User getUser(String id){
for(User user: users){
if(user.getId().equals(id)){
return user;
}
}
return null;
}
public void unfollowUser(){}
public HashSet<User> getUsers() {
return users;
}
}

class User{
private String id;
private String name;
private HashSet<String> followers;
private HashSet<String> following;
public void followUser(String followIdUser){
followers.add(followIdUser);
}

public User(String id, String name) {
this.id = id;
this.name = name;
this.followers = new HashSet<String>();
this.following = new HashSet<String>();
}

public String getId() {
return id;
}

public String getName() {
return name;
}

public HashSet<String> getFollowers() {
return followers;
}

public HashSet<String> getFollowing() {
return following;
}

@Override
public String toString() {
return "User{" +
"id='" + id + '\'' +
", name='" + name + '\'' +
", followers=" + followers +
", following=" + following +
'}';
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
User user = (User) o;
return Objects.equals(id, user.id) && Objects.equals(name, user.name) && Objects.equals(followers, user.followers) && Objects.equals(following, user.following);
}

@Override
public int hashCode() {
return Objects.hash(id, name, followers, following);
}
}
92 changes: 92 additions & 0 deletions Roadmap/47 - CALENDARIO DE ADVIENTO/java/JohnAlexGuerrero.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package org.example;

import java.util.Scanner;

// Press Shift twice to open the Search Everywhere dialog and type `show whitespaces`,
// then press Enter. You can now see whitespace characters in your code.
public class Main {
// * - El calendario mostrará los días del 1 al 24 repartidos
// * en 6 columnas a modo de cuadrícula.
//- Cada cuadrícula correspondiente a un día tendrá un tamaño
// * de 4x3 caracteres, y sus bordes serán asteríscos.
//* Ejemplo de cuadrículas:
//* **** **** ****
//* *01* *02* *03* ...
//* **** **** ****
static int [][] calendar = {
{1,2,3,4,5,6}, {7,8,9,10,11,12}, {13,14,15,16,17,18}, {19,20,21,22,23,24}
};

public static void showCalendar(){
for(int[] row: calendar){
System.out.println("**** **** **** **** **** **** ");
for(int i: row){
String day = (i < 10)? "0"+i : ""+i;
if(i == 0){
day = "**";
}
System.out.printf("*"+day+"* ");
}
System.out.println();
}
System.out.println("**** **** **** **** **** **** ");
System.out.println();
}

public static boolean avalableDay(int d){
for (int i = 0; i < calendar.length; i++){
for (int j = 0; j < calendar[i].length; j++){
if(calendar[i][j] == d){
selectDayInCalendar(i,j);
return true;
}
}
}
return false;
}

public static void selectDayInCalendar(int indexX, int indexY){
// * cubierta de asteríscos (sin mostrar el día).
// * Ejemplo de selección del día 1
// * **** **** ****
// * **** *02* *03* ...
// * **** **** ****
calendar[indexX][indexY] = 0;
}

public static void main(String[] args) {
// Press Alt+Intro with your caret at the highlighted text to see how
Scanner scanner = new Scanner(System.in);
boolean flag = true;

while(flag){
showCalendar();
//* - El usuario seleccioná qué día quiere descubrir.
System.out.println("select one day or exit: ");
String selectDay = scanner.nextLine();

if(selectDay.equals("exit")){
flag = false;
}

try{
int selectedDay = Integer.parseInt(selectDay);

//Si está sin descubrir, se le dirá que ha abierto ese día
if(avalableDay(selectedDay)){
System.out.println("This day is avalable.");
}else{
//* - Si se selecciona un número ya descubierto, se le notifica
// * al usuario.
System.out.println("Day is not avalable.");
}

}catch(NumberFormatException ex){
System.out.println("select on number.");
}
}

// * y se mostrará de nuevo el calendario con esa cuadrícula

}
}
Loading