Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %% IMPLEMENTACION EN EL MAIN %%
- case 10: // implementacion de una query adicional, crear artistas y anadirlos en la lista y al programa
- boolean caso = true; // esto es pra el while que te obliga a seguir hasta que pongas uno que no existe
- try (FileWriter escribir = new FileWriter("Artistas.txt", true);
- BufferedWriter buffer = new BufferedWriter(escribir);
- PrintWriter salida = new PrintWriter(buffer)) { // todo el porro de meter archivos de texto
- System.out.println("Registering new artist. Please enter the name");
- while (caso) {
- artistName = scanner.next();
- if (festival.doesArtisExist(artistName)) { // espero que tengas este metodo o algo similar
- System.out.println("This artist exists!");
- } else {
- caso = false; // para que el while loop no siga
- // variables predeterminadas porque no puedes pasar un metodo que le falte parametros
- boolean mainArtist;
- int ticketPrice;
- int duration;
- int capacity;
- boolean assisting;
- int numMembers = 0;
- boolean sellMerch = false;
- boolean needsDressingRoom = false; // estas variables las inicializo porq no puedes pasar params vacios a un metodo. De todas formas, el metodo de crear artistas
- 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
- System.out.println("Group or solo? please write 'g' or 's'");
- String type = scanner.next();
- if (!type.equals("g") && !type.equals("s")) {
- throw new InputMismatchException("invalid input"); // cosa opcional que no estaria feo que pongas
- }
- System.out.println("Genre?");
- String genre = scanner.next();
- System.out.println("Is main artist?");
- mainArtist = scanner.nextBoolean();
- System.out.println("Ticket Price?");
- ticketPrice = scanner.nextInt();
- System.out.println("Duration?");
- duration = scanner.nextInt();
- System.out.println("Capacity? (in thousands, write the number compacted)");
- capacity = scanner.nextInt();
- System.out.println("Is assisting?");
- assisting = scanner.nextBoolean();
- salida.println();
- salida.print(type + " ");
- salida.print(artistName + " ");
- salida.print(genre + " ");
- salida.print(mainArtist + " ");
- salida.print(ticketPrice + " ");
- salida.print(duration + " ");
- salida.print(capacity + " ");
- salida.print(assisting + " ");
- if (type.equals("g")) {
- System.out.println("Number of members?");
- numMembers = scanner.nextInt();
- salida.print(numMembers + " ");
- System.out.println("Sells merch?");
- sellMerch = scanner.nextBoolean();
- salida.print(sellMerch + " ");
- }
- if (type.equals("s")) {
- System.out.println("needs dressing room?");
- needsDressingRoom = scanner.nextBoolean();
- salida.print(needsDressingRoom + " ");
- System.out.println("Enter manager phone number (only numbers!)");
- managerPhone = scanner.nextInt();
- salida.print(managerPhone + " ");
- System.out.println("finished!");
- }
- System.out.println("Creating artist...");
- festival.artistMaker(type, artistName, genre, mainArtist, ticketPrice, duration, capacity, assisting, numMembers, sellMerch, needsDressingRoom, managerPhone);
- }
- }
- }
- break;
- %% IMPLEMENTACION DEL METODO DENTRO DE LA CLASE FESTIVAL %%
- 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) {
- for (int i = 0; i < artistList.length; i++) {
- if (artistList[i] == null) {
- if (type.equalsIgnoreCase("g")) {
- Artist newGroup = new Group(type, artistName, genre, mainArtist, ticketPrice, duration, capacity, assisting, numMembers, sellMerch);
- artistList[i] = newGroup;
- }
- else {
- Artist newSolo = new Solo(type, artistName, genre, mainArtist, ticketPrice, duration, capacity, assisting, needsDressRoom, mngrPhone);
- artistList[i] = newSolo;
- }
- return;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement