Guest User

Java database

a guest
Apr 30th, 2013
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.85 KB | None | 0 0
  1. import java.util.*;
  2.  
  3.  
  4.  
  5. public class UserInterface
  6.  {
  7.     static UserInterface intFace = new UserInterface();
  8.     static SongDatabase dataMain = new SongDatabase();
  9.     public static String artist;
  10.     public static String name;
  11.     public static double duration;
  12.     public static int fileSize;
  13.    
  14.    
  15.    
  16.    
  17.    
  18.     private void run() {
  19.        
  20.        
  21.  
  22.     }
  23.    
  24.    
  25.    
  26.    
  27.    
  28.     public static void main(String[] args){
  29.  
  30.            
  31.            
  32.             Scanner console = new Scanner(System.in);
  33.            
  34.            
  35.            
  36.             do
  37.             {
  38.          
  39.            
  40.              
  41.              
  42.                 System.out.println("\t MENU");  
  43.                 System.out.println("0 EXIT");            
  44.                 System.out.println("1 IMPORT TRACK");
  45.                 System.out.println("2 SHOW ALL");      
  46.                
  47.                 int switchOption = console.nextInt();
  48.            
  49.             switch(switchOption)  {
  50.                
  51.                     case 0 :
  52.                         System.out.println("Exiting");
  53.                         break;
  54.                     case 1 :
  55.                         System.out.println("Adding new track");
  56.                         userImport();
  57.                         break;
  58.                     case 2 :
  59.                         System.out.println("Scanning file system");
  60.                         showFileSystem();
  61.                         break;
  62.                     default:
  63.                         System.out.println("Invalid option");
  64.                         break;
  65.                        
  66.            
  67.            
  68.             }
  69.         }while(true);
  70.        
  71.            
  72.     }
  73.  
  74.    
  75.     public static void showFileSystem()
  76.     {
  77.        
  78.        
  79.         int check = 1;
  80.         Scanner console = new Scanner(System.in);
  81.  
  82.        
  83.         System.out.println("Welcome to the system file scanner!");
  84.         System.out.println("Scan now? (0)=yes, (1)=no."); check = console.nextInt();
  85.        
  86.             if (check==0) {
  87.                 System.out.println("System contents:"+dataMain.dataSlotCheck());
  88.                
  89.  
  90.                
  91.             }else{ System.out.println("Exiting file scanner..");
  92.                    
  93.                 }
  94.            
  95.            
  96.            
  97.     }
  98.    
  99.    
  100.    
  101.    
  102.     public  static void userImport()
  103.     {
  104.         String userin1;
  105.         String userin2;
  106.         double userin3;
  107.         int userin4;
  108.    
  109.        
  110.        
  111.        
  112.  
  113.         Scanner console = new Scanner(System.in);
  114.         Song songMain = new Song();
  115.        
  116.        
  117.            
  118.         System.out.println("Welcome to the music importer!");
  119.         System.out.println("Music can be imported in the format Artist:TrackName:Duration(mm.ss):FIleSize(kb)");
  120.         System.out.println("Enter the artist:.."); userin1 = console.nextLine();
  121.         System.out.println("Enter the track title:.."); userin2 = console.nextLine();
  122.         System.out.println("Enter the duration:.."); userin3 = console.nextDouble();
  123.         System.out.println("Enter the file size:.."); userin4 = console.nextInt();
  124.        
  125.         intFace.importAssign(userin1, userin2, userin3, userin4);
  126.        
  127.         dataMain.addSong();
  128.        
  129.        
  130.         songMain.returnData();
  131.        
  132.        
  133.        
  134.        
  135.        
  136.     }
  137.    
  138.     public void importAssign(String userin1, String userin2, double userin3, int userin4) {
  139.    
  140.         intFace.artist = userin1;
  141.         intFace.name = userin2;
  142.         intFace.duration = userin3;
  143.         intFace.fileSize = userin4;
  144.        
  145.     }
  146.  
  147. }
  148.  
  149.  
  150.  
  151. __________________________________________________________________________________________
  152.  
  153.  
  154. public class SongDatabase
  155. {
  156.    
  157.     UserInterface intFace = new UserInterface();
  158.     Song Set = new Song();
  159.     private Song a = new Song();
  160.     private Song b = new Song();
  161.     private Song c = new Song();
  162.     private Song d = new Song();
  163.    
  164.    
  165.    
  166.     public void addSong()
  167.     {
  168.        
  169.  
  170.  
  171.        
  172.        
  173.         if (a.songfileSize==0) {
  174.                        
  175.                         setData(a.songartist, a.songname, a.songduration, a.songfileSize);
  176.                    
  177.                     } else if (b.songfileSize==0) {
  178.                    
  179.                         setData(b.songartist, b.songname, b.songduration, b.songfileSize);
  180.                    
  181.                     } else if (c.songfileSize==0) {
  182.                    
  183.                         setData(c.songartist, c.songname, c.songduration, c.songfileSize);
  184.                    
  185.                     } else if (d.songfileSize==0) {
  186.                    
  187.                         setData(c.songartist, c.songname, c.songduration, c.songfileSize);
  188.                    
  189.                     } else {
  190.                         System.out.println("Error: there is no free space in the database");
  191.                     }
  192.                    
  193.      
  194.        
  195.        
  196.        
  197.     }
  198.    
  199.    
  200.     public void setData( String artist, String name, double duration, int fileSize)
  201.     {
  202.         Set.setArtist(intFace.artist);
  203.         Set.setName(intFace.name);
  204.         Set.setDuration(intFace.duration);
  205.         Set.setFileSize(intFace.fileSize);
  206.     }
  207.    
  208.     public String dataSlotCheck()
  209.     {
  210.         String finalScan;
  211.          
  212.         if (a.songfileSize==0 && b.songfileSize==0 && c.songfileSize==0 && d.songfileSize==0) {
  213.             finalScan=("There is no music stored in the database.");
  214.         }
  215.         else if (d.songfileSize==0 && c.songfileSize==0 && b.songfileSize==0) {
  216.             finalScan=("SlotA:"+a.songartist+":"+a.songname+":"+a.songduration+":"+a.songfileSize);
  217.         } else if (d.songfileSize==0 && c.songfileSize==0) {
  218.             finalScan= ("SlotA:"+a.songartist+":"+a.songname+":"+a.songduration+":"+a.songfileSize+
  219.             "SlotB:"+b.songartist+":"+b.songname+":"+b.songduration+":"+b.songfileSize);
  220.         } else if (d.songfileSize==0) {
  221.             finalScan= ("SlotA:"+a.songartist+":"+a.songname+":"+a.songduration+":"+a.songfileSize+
  222.              "SlotB:"+b.songartist+":"+b.songname+":"+b.songduration+":"+b.songfileSize+
  223.              "SlotC:"+c.songartist+":"+c.songname+":"+c.songduration+":"+c.songfileSize);
  224.         } else {
  225.             finalScan= ("SlotA:"+a.songartist+":"+a.songname+":"+a.songduration+":"+a.songfileSize+
  226.              "SlotB:"+b.songartist+":"+b.songname+":"+b.songduration+":"+b.songfileSize+
  227.              "SlotC:"+c.songartist+":"+c.songname+":"+c.songduration+":"+c.songfileSize+
  228.              "SlotD:"+d.songartist+":"+d.songname+":"+d.songduration+":"+d.songfileSize);
  229.         }
  230.        
  231.         return (finalScan);
  232.    
  233.     }
  234. }
  235.  
  236.  
  237. ________________________________________________________________________________________________
  238.  
  239. public class Song
  240. {
  241.    
  242.        
  243.        
  244.         public Song(){
  245.             /*Artist;
  246.                * TrackName;
  247.                  * Duration(mm:ss);
  248.                    * fileSize(kB);*/
  249.          }
  250.        
  251.        UserInterface intFace = new UserInterface();
  252.        String songartist = intFace.artist;
  253.        String songname = intFace.name;
  254.        double songduration = intFace.duration;
  255.        int songfileSize = intFace.fileSize;
  256.            
  257.    
  258.         public void Song(String artist, String name, double duration, int fileSize){
  259.        
  260.            this.artist=artist;
  261.            this.name=name;
  262.            this.duration=duration;
  263.            this.fileSize=fileSize;
  264.            
  265.            
  266.          }
  267.        
  268.         public void setArtist(String newArtist)
  269.         {
  270.            
  271.             artist = newArtist;
  272.        
  273.         }
  274.        
  275.         public String getArtist()
  276.         {
  277.            
  278.            
  279.            
  280.             return artist;
  281.         }
  282.        
  283.         public void setName(String newName)
  284.         {
  285.            
  286.             name = newName;
  287.        
  288.         }
  289.        
  290.         public String getName()
  291.         {
  292.        
  293.            
  294.            
  295.             return name;
  296.         }
  297.        
  298.         public void setDuration(double newDuration)
  299.         {
  300.            
  301.             duration = newDuration;
  302.            
  303.         }
  304.        
  305.         public double getDuration()
  306.         {
  307.            
  308.            
  309.            
  310.             return duration;
  311.         }
  312.        
  313.         public void setFileSize(int newFileSize)
  314.         {
  315.            
  316.             fileSize = newFileSize;
  317.        
  318.         }
  319.        
  320.         public int getFileSize()
  321.         {
  322.            
  323.            
  324.            
  325.             return fileSize;
  326.         }
  327.        
  328.         public String returnData()
  329.         {
  330.        
  331.             return ("You have imported: "+intFace.name+" By: "+intFace.artist+" || "
  332.             +intFace.duration+"(mm.ss), "+intFace.fileSize+"(kB)");
  333.            
  334.         }
  335.     }
Advertisement
Add Comment
Please, Sign In to add comment