Advertisement
natanfechete

Untitled

Jun 19th, 2025
367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.37 KB | None | 0 0
  1. %% IMPLEMENTACION EN EL MAIN %%
  2.  
  3. case 10: // implementacion de una query adicional, crear artistas y anadirlos en la lista y al programa
  4.                         boolean caso = true; // esto es pra el while que te obliga a seguir hasta que pongas uno que no existe
  5.  
  6.                         try (FileWriter escribir = new FileWriter("Artistas.txt", true);
  7.                              BufferedWriter buffer = new BufferedWriter(escribir);
  8.                              PrintWriter salida = new PrintWriter(buffer)) { // todo el porro de meter archivos de texto
  9.  
  10.                             System.out.println("Registering new artist. Please enter the name");
  11.                             while (caso) {
  12.                                 artistName = scanner.next();
  13.                                 if (festival.doesArtisExist(artistName)) { // espero que tengas este metodo o algo similar
  14.                                     System.out.println("This artist exists!");
  15.                                 } else {
  16.                                     caso = false; // para que el while loop no siga
  17.                                     // variables predeterminadas porque no puedes pasar un metodo que le falte parametros
  18.                                     boolean mainArtist;
  19.                                     int ticketPrice;
  20.                                     int duration;
  21.                                     int capacity;
  22.                                     boolean assisting;
  23.                                     int numMembers = 0;
  24.                                     boolean sellMerch = false;
  25.                                     boolean needsDressingRoom = false; // estas variables las inicializo porq no puedes pasar params vacios a un metodo. De todas formas, el metodo de crear artistas
  26.                                     int managerPhone = 0;              // es listo y no va a meter valores equivocados por lo q no pasa nada si pasas por ej 0 en un tipo grupo
  27.  
  28.                                     System.out.println("Group or solo? please write 'g' or 's'");
  29.                                     String type = scanner.next();
  30.  
  31.                                     if (!type.equals("g") && !type.equals("s")) {
  32.                                         throw new InputMismatchException("invalid input"); // cosa opcional que no estaria feo que pongas
  33.                                     }
  34.  
  35.                                     System.out.println("Genre?");
  36.                                     String genre = scanner.next();
  37.                                     System.out.println("Is main artist?");
  38.                                     mainArtist = scanner.nextBoolean();
  39.                                     System.out.println("Ticket Price?");
  40.                                     ticketPrice = scanner.nextInt();
  41.                                     System.out.println("Duration?");
  42.                                     duration = scanner.nextInt();
  43.                                     System.out.println("Capacity? (in thousands, write the number compacted)");
  44.                                     capacity = scanner.nextInt();
  45.                                     System.out.println("Is assisting?");
  46.                                     assisting = scanner.nextBoolean();
  47.  
  48.                                     salida.println();
  49.                                     salida.print(type + " ");
  50.                                     salida.print(artistName + " ");
  51.                                     salida.print(genre + " ");
  52.                                     salida.print(mainArtist + " ");
  53.                                     salida.print(ticketPrice + " ");
  54.                                     salida.print(duration + " ");
  55.                                     salida.print(capacity + " ");
  56.                                     salida.print(assisting + " ");
  57.  
  58.                                     if (type.equals("g")) {
  59.                                         System.out.println("Number of members?");
  60.                                         numMembers = scanner.nextInt();
  61.                                         salida.print(numMembers + " ");
  62.  
  63.                                         System.out.println("Sells merch?");
  64.                                         sellMerch = scanner.nextBoolean();
  65.                                         salida.print(sellMerch + " ");
  66.                                     }
  67.  
  68.                                     if (type.equals("s")) {
  69.                                         System.out.println("needs dressing room?");
  70.                                         needsDressingRoom = scanner.nextBoolean();
  71.                                         salida.print(needsDressingRoom + " ");
  72.  
  73.                                         System.out.println("Enter manager phone number (only numbers!)");
  74.                                         managerPhone = scanner.nextInt();
  75.                                         salida.print(managerPhone + " ");
  76.                                         System.out.println("finished!");
  77.                                     }
  78.  
  79.                                     System.out.println("Creating artist...");
  80.                                     festival.artistMaker(type, artistName, genre, mainArtist, ticketPrice, duration, capacity, assisting, numMembers, sellMerch, needsDressingRoom, managerPhone);
  81.                                 }
  82.                             }
  83.                         }
  84.                         break;
  85.  
  86.  
  87. %% IMPLEMENTACION DEL METODO DENTRO DE LA CLASE FESTIVAL %%
  88.  
  89. public void artistMaker(String type, String artistName, String genre, boolean mainArtist, int ticketPrice, int duration,int capacity, boolean assisting, int numMembers, boolean sellMerch, boolean needsDressRoom, int mngrPhone) {
  90.         for (int i = 0; i < artistList.length; i++) {
  91.             if (artistList[i] == null) {
  92.                 if (type.equalsIgnoreCase("g")) {
  93.                     Artist newGroup = new Group(type, artistName, genre, mainArtist, ticketPrice, duration, capacity, assisting, numMembers, sellMerch);
  94.                     artistList[i] = newGroup;
  95.                 }
  96.                 else {
  97.                     Artist newSolo = new Solo(type, artistName, genre, mainArtist, ticketPrice, duration, capacity, assisting, needsDressRoom, mngrPhone);
  98.                     artistList[i] = newSolo;
  99.                 }
  100.                 return;
  101.             }
  102.         }
  103.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement