Skip to content

Commit 4021875

Browse files
authored
Merge pull request #7534 from JohnAlexGuerrero/main
reto #50
2 parents c37ae7a + 2ef7033 commit 4021875

File tree

5 files changed

+740
-0
lines changed

5 files changed

+740
-0
lines changed
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
package org.example;
2+
3+
import java.util.HashSet;
4+
import java.util.Objects;
5+
6+
// Press Shift twice to open the Search Everywhere dialog and type `show whitespaces`,
7+
// then press Enter. You can now see whitespace characters in your code.
8+
public class Main {
9+
public static void main(String[] args) {
10+
SocialNetwork socialnetwork = new SocialNetwork();
11+
12+
//- Registrar un usuario por defecto con nombre e identificador único.
13+
socialnetwork.registerUser("u123", "alexander guerrero");
14+
socialnetwork.registerUser("u456", "sandra estacio");
15+
socialnetwork.registerUser("u467", "carolina maigual");
16+
socialnetwork.registerUser("u897", "mileidy cruz");
17+
socialnetwork.registerUser("u230", "daniel botina");
18+
socialnetwork.registerUser("u239", "diego botina");
19+
socialnetwork.registerUser("u348", "gloria maigual");
20+
socialnetwork.registerUser("u438", "teresa maigual");
21+
socialnetwork.registerUser("u489", "alejandra rojas");
22+
23+
//- Seleccionar un usuario
24+
User u1 = socialnetwork.getUser("u489");
25+
//- Un usuario puede seguir/dejar de seguir a otro.
26+
u1.followUser("u348");
27+
u1.followUser("u467");
28+
u1.followUser("u897");
29+
30+
//- Mostrar usuarios
31+
for (User user : socialnetwork.getUsers()) {
32+
System.out.println(user.toString());
33+
}
34+
}
35+
}
36+
37+
class SocialNetwork{
38+
private static HashSet<User> users;
39+
public SocialNetwork() {
40+
users = new HashSet<>();
41+
}
42+
public void registerUser(String id, String name){
43+
users.add(new User(id, name));
44+
}
45+
public User getUser(String id){
46+
for(User user: users){
47+
if(user.getId().equals(id)){
48+
return user;
49+
}
50+
}
51+
return null;
52+
}
53+
public void unfollowUser(){}
54+
public HashSet<User> getUsers() {
55+
return users;
56+
}
57+
}
58+
59+
class User{
60+
private String id;
61+
private String name;
62+
private HashSet<String> followers;
63+
private HashSet<String> following;
64+
public void followUser(String followIdUser){
65+
followers.add(followIdUser);
66+
}
67+
68+
public User(String id, String name) {
69+
this.id = id;
70+
this.name = name;
71+
this.followers = new HashSet<String>();
72+
this.following = new HashSet<String>();
73+
}
74+
75+
public String getId() {
76+
return id;
77+
}
78+
79+
public String getName() {
80+
return name;
81+
}
82+
83+
public HashSet<String> getFollowers() {
84+
return followers;
85+
}
86+
87+
public HashSet<String> getFollowing() {
88+
return following;
89+
}
90+
91+
@Override
92+
public String toString() {
93+
return "User{" +
94+
"id='" + id + '\'' +
95+
", name='" + name + '\'' +
96+
", followers=" + followers +
97+
", following=" + following +
98+
'}';
99+
}
100+
101+
@Override
102+
public boolean equals(Object o) {
103+
if (this == o) return true;
104+
if (o == null || getClass() != o.getClass()) return false;
105+
User user = (User) o;
106+
return Objects.equals(id, user.id) && Objects.equals(name, user.name) && Objects.equals(followers, user.followers) && Objects.equals(following, user.following);
107+
}
108+
109+
@Override
110+
public int hashCode() {
111+
return Objects.hash(id, name, followers, following);
112+
}
113+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package org.example;
2+
3+
import java.util.Scanner;
4+
5+
// Press Shift twice to open the Search Everywhere dialog and type `show whitespaces`,
6+
// then press Enter. You can now see whitespace characters in your code.
7+
public class Main {
8+
// * - El calendario mostrará los días del 1 al 24 repartidos
9+
// * en 6 columnas a modo de cuadrícula.
10+
//- Cada cuadrícula correspondiente a un día tendrá un tamaño
11+
// * de 4x3 caracteres, y sus bordes serán asteríscos.
12+
//* Ejemplo de cuadrículas:
13+
//* **** **** ****
14+
//* *01* *02* *03* ...
15+
//* **** **** ****
16+
static int [][] calendar = {
17+
{1,2,3,4,5,6}, {7,8,9,10,11,12}, {13,14,15,16,17,18}, {19,20,21,22,23,24}
18+
};
19+
20+
public static void showCalendar(){
21+
for(int[] row: calendar){
22+
System.out.println("**** **** **** **** **** **** ");
23+
for(int i: row){
24+
String day = (i < 10)? "0"+i : ""+i;
25+
if(i == 0){
26+
day = "**";
27+
}
28+
System.out.printf("*"+day+"* ");
29+
}
30+
System.out.println();
31+
}
32+
System.out.println("**** **** **** **** **** **** ");
33+
System.out.println();
34+
}
35+
36+
public static boolean avalableDay(int d){
37+
for (int i = 0; i < calendar.length; i++){
38+
for (int j = 0; j < calendar[i].length; j++){
39+
if(calendar[i][j] == d){
40+
selectDayInCalendar(i,j);
41+
return true;
42+
}
43+
}
44+
}
45+
return false;
46+
}
47+
48+
public static void selectDayInCalendar(int indexX, int indexY){
49+
// * cubierta de asteríscos (sin mostrar el día).
50+
// * Ejemplo de selección del día 1
51+
// * **** **** ****
52+
// * **** *02* *03* ...
53+
// * **** **** ****
54+
calendar[indexX][indexY] = 0;
55+
}
56+
57+
public static void main(String[] args) {
58+
// Press Alt+Intro with your caret at the highlighted text to see how
59+
Scanner scanner = new Scanner(System.in);
60+
boolean flag = true;
61+
62+
while(flag){
63+
showCalendar();
64+
//* - El usuario seleccioná qué día quiere descubrir.
65+
System.out.println("select one day or exit: ");
66+
String selectDay = scanner.nextLine();
67+
68+
if(selectDay.equals("exit")){
69+
flag = false;
70+
}
71+
72+
try{
73+
int selectedDay = Integer.parseInt(selectDay);
74+
75+
//Si está sin descubrir, se le dirá que ha abierto ese día
76+
if(avalableDay(selectedDay)){
77+
System.out.println("This day is avalable.");
78+
}else{
79+
//* - Si se selecciona un número ya descubierto, se le notifica
80+
// * al usuario.
81+
System.out.println("Day is not avalable.");
82+
}
83+
84+
}catch(NumberFormatException ex){
85+
System.out.println("select on number.");
86+
}
87+
}
88+
89+
// * y se mostrará de nuevo el calendario con esa cuadrícula
90+
91+
}
92+
}

0 commit comments

Comments
 (0)