Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 11th, 2012  |  syntax: None  |  size: 4.73 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package discotecapersonal;
  6.  
  7. import java.io.File;
  8. import java.io.FileNotFoundException;
  9. import java.io.PrintWriter;
  10. import java.util.*;
  11.  
  12. public class GestDisco {
  13.  
  14.     static Scanner kbd = new Scanner(System.in);
  15.  
  16.     public static int menu() {
  17.         int opc;
  18.         do {
  19.             System.out.println("\n********* Discoteca **********");
  20.             System.out.println(" 1. Add Album");
  21.             System.out.println(" 2. Show Albums");
  22.             System.out.println(" 3. Delete Album");
  23.             System.out.println(" 4. Modify Album");
  24.             System.out.println(" 5. Save list to other file");
  25.             System.out.println(" 0. End");
  26.             System.out.println("*****************************");
  27.             System.out.print("Choose an option: ");
  28.             opc = kbd.nextInt();
  29.             if (opc < 0 || opc > 4) {
  30.                 System.out.println("\nIncorrect option.\n");
  31.             }
  32.         } while (opc < 0 || opc > 5);
  33.         return opc;
  34.     }
  35.  
  36.     public static void main(String[] args) throws FileNotFoundException {
  37.         Album alb = new Album();
  38.         int opcion;
  39.         do {
  40.             opcion = menu();
  41.             switch (opcion) {
  42.                 case 1: // Add album
  43.                     kbd.nextLine();
  44.                     System.out.println("Title? ");
  45.                     String t = kbd.nextLine();
  46.                     System.out.println("Year? ");
  47.                     int y = kbd.nextInt();
  48.                     kbd.nextLine();
  49.                     System.out.println("Publisher? ");
  50.                     String p = kbd.nextLine();
  51.                     System.out.println("Genre? ");
  52.                     String g = kbd.nextLine();
  53.                     System.out.println("Number of songs? ");
  54.                     int x = kbd.nextInt();
  55.                     kbd.nextLine();
  56.                     Song[] s = new Song[x];
  57.                     for (int i = 0; i < x; i++) {
  58.  
  59.                         System.out.println("Title Song " + i + "?");
  60.                         String tS = kbd.nextLine();
  61.  
  62.                         System.out.println("Year Song " + i + "?");
  63.                         int yS = kbd.nextInt();
  64.                         kbd.nextLine();
  65.                         System.out.println("Compositor Song " + i + "?");
  66.                         String com = kbd.nextLine();
  67.                         System.out.println("Writer Song " + i + "?");
  68.                         String w = kbd.nextLine();
  69.                         alb.addSong(tS, i + 1, yS, com, p, w);
  70.                     }
  71.  
  72.                     alb.addAlbum(t, y, p, g, s);
  73.                     break;
  74.                 case 2: // show album
  75.                     int i = 0;
  76.                     Scanner scanner = null;
  77.  
  78.                     try {
  79.                         File df = new File("cosas.txt");
  80.  
  81.                         if (df.exists()) {
  82.                             Scanner sf = new Scanner(df);
  83.  
  84.                             while (sf.hasNext()) {
  85.                                 String title = sf.nextLine().trim();
  86.                                 String artist = sf.nextLine().trim();
  87.                                 int numson = sf.nextInt();
  88.                                 String Song = sf.nextLine().trim();
  89.                                 Song songs[] = new Song[numson];
  90.  
  91.                                 Albums A = new Albums(artist, title, songs[]);
  92.                             }
  93.                         }
  94.                     } catch (FileNotFoundException e) {
  95.                         System.err.println("el fichero no existe" + e.getMessage());
  96.                         System.exit(0);
  97.                     }
  98.  
  99.  
  100.                     break;
  101.                 case 3: // show album
  102.  
  103.                     break;
  104.                 case 4: // show album
  105.  
  106.                     break;
  107.                 case 5:
  108.                     break;
  109.                 default: // Terminar
  110.                     System.out.println("\n*** End ***");
  111.  
  112.                     break;
  113.             }
  114.         } while (opcion != 0);
  115.  
  116.  
  117.  
  118.     }
  119.  
  120.     public void saveToFile(String nomfic) {
  121.         try {
  122.             PrintWriter pw = new PrintWriter(new File(nomfic));
  123.             int counter = listAlb.length;
  124.             for (int i = 0; i < counter; i++) {
  125.                 Album a = listAlb[i];
  126.  
  127.                 pw.println(e.getDate().toString());
  128.                 pw.println(e.getTitle());
  129.                 pw.println(e.getPlace());
  130.                 pw.println(e.getDescription());
  131.             }
  132.             pw.close();
  133.         } catch (Exception e) {
  134.             e.printStackTrace(System.err);
  135.             System.exit(-1);
  136.         }
  137.     }
  138. }