- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package discotecapersonal;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.PrintWriter;
- import java.util.*;
- public class GestDisco {
- static Scanner kbd = new Scanner(System.in);
- public static int menu() {
- int opc;
- do {
- System.out.println("\n********* Discoteca **********");
- System.out.println(" 1. Add Album");
- System.out.println(" 2. Show Albums");
- System.out.println(" 3. Delete Album");
- System.out.println(" 4. Modify Album");
- System.out.println(" 5. Save list to other file");
- System.out.println(" 0. End");
- System.out.println("*****************************");
- System.out.print("Choose an option: ");
- opc = kbd.nextInt();
- if (opc < 0 || opc > 4) {
- System.out.println("\nIncorrect option.\n");
- }
- } while (opc < 0 || opc > 5);
- return opc;
- }
- public static void main(String[] args) throws FileNotFoundException {
- Album alb = new Album();
- int opcion;
- do {
- opcion = menu();
- switch (opcion) {
- case 1: // Add album
- kbd.nextLine();
- System.out.println("Title? ");
- String t = kbd.nextLine();
- System.out.println("Year? ");
- int y = kbd.nextInt();
- kbd.nextLine();
- System.out.println("Publisher? ");
- String p = kbd.nextLine();
- System.out.println("Genre? ");
- String g = kbd.nextLine();
- System.out.println("Number of songs? ");
- int x = kbd.nextInt();
- kbd.nextLine();
- Song[] s = new Song[x];
- for (int i = 0; i < x; i++) {
- System.out.println("Title Song " + i + "?");
- String tS = kbd.nextLine();
- System.out.println("Year Song " + i + "?");
- int yS = kbd.nextInt();
- kbd.nextLine();
- System.out.println("Compositor Song " + i + "?");
- String com = kbd.nextLine();
- System.out.println("Writer Song " + i + "?");
- String w = kbd.nextLine();
- alb.addSong(tS, i + 1, yS, com, p, w);
- }
- alb.addAlbum(t, y, p, g, s);
- break;
- case 2: // show album
- int i = 0;
- Scanner scanner = null;
- try {
- File df = new File("cosas.txt");
- if (df.exists()) {
- Scanner sf = new Scanner(df);
- while (sf.hasNext()) {
- String title = sf.nextLine().trim();
- String artist = sf.nextLine().trim();
- int numson = sf.nextInt();
- String Song = sf.nextLine().trim();
- Song songs[] = new Song[numson];
- Albums A = new Albums(artist, title, songs[]);
- }
- }
- } catch (FileNotFoundException e) {
- System.err.println("el fichero no existe" + e.getMessage());
- System.exit(0);
- }
- break;
- case 3: // show album
- break;
- case 4: // show album
- break;
- case 5:
- break;
- default: // Terminar
- System.out.println("\n*** End ***");
- break;
- }
- } while (opcion != 0);
- }
- public void saveToFile(String nomfic) {
- try {
- PrintWriter pw = new PrintWriter(new File(nomfic));
- int counter = listAlb.length;
- for (int i = 0; i < counter; i++) {
- Album a = listAlb[i];
- pw.println(e.getDate().toString());
- pw.println(e.getTitle());
- pw.println(e.getPlace());
- pw.println(e.getDescription());
- }
- pw.close();
- } catch (Exception e) {
- e.printStackTrace(System.err);
- System.exit(-1);
- }
- }
- }