Advertisement
Guest User

Untitled

a guest
Sep 14th, 2014
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.51 KB | None | 0 0
  1. package edith;//Derived class
  2.  
  3. import java.io.BufferedWriter;
  4. import java.io.FileWriter;
  5. import java.io.IOException;
  6. import java.io.PrintWriter;
  7. import java.util.*;
  8.  
  9. public class DVD extends Video
  10. {
  11.    //Declares a constant variable
  12.    public final int SIZE = 3;
  13.    
  14.    //data fields
  15.    private String[] specialFeatures = new String[SIZE];
  16.    private boolean wideScreenFormat;
  17.    private boolean tvFormat;
  18.    private String[] soundOptions = new String[SIZE];
  19.    
  20.    //Default constructor
  21.    public DVD()
  22.    {
  23.       super();
  24.       specialFeatures[0] = "no special feature";
  25.       specialFeatures[1] = "no special feature";
  26.       specialFeatures[2] = "no special feature";
  27.       wideScreenFormat = false;
  28.       tvFormat = false;
  29.       soundOptions[0] = "no sound option";
  30.       soundOptions[1] = "no sound option";
  31.       soundOptions[2] = "no sound option";
  32.    }
  33.    
  34.    //Constructor with parameters
  35.    public DVD(String theTitle, String theMajorArtist, int thePlayingTime,
  36.               int theNumPlays, String[] theSupportingActors,
  37.               String theDirector, String theFormat,
  38.               String[] specialFeatures, boolean wideScreenFormat, boolean tvFormat, String[] soundOptions)
  39.    {
  40.       super(theTitle, theMajorArtist, thePlayingTime, theNumPlays,  
  41.             theSupportingActors, theDirector, theFormat);
  42.       this.specialFeatures = specialFeatures;
  43. //      this.specialFeatures[1] = specialFeatures[1];
  44. //      this.specialFeatures[2] = specialFeatures[2];
  45.       this.wideScreenFormat = wideScreenFormat;
  46.       this.tvFormat = tvFormat;
  47.       this.soundOptions= soundOptions;
  48.    }
  49.    
  50.    //Accessor methods
  51.    public String getSpecialFeatures()
  52.    {
  53.       String str = "";
  54.      
  55.       for(int i = 0; i < specialFeatures.length; i++)
  56.           str += specialFeatures[i] +"\n";
  57.          
  58.       return str;
  59.    }
  60.    
  61.    public boolean getWideScreenFormat()
  62.    {
  63.       return wideScreenFormat;
  64.    }
  65.    
  66.    public boolean getTvFormat()
  67.    {
  68.       return tvFormat;
  69.    }
  70.    
  71.    public String getSoundOptions()
  72.    {
  73.       String str = "";
  74.      
  75.       for(int i = 0; i < soundOptions.length; i++)
  76.           str += soundOptions[i] +"\n";
  77.          
  78.       return str;
  79.    }
  80.    
  81.    //Mutator methods
  82.    public void setSpecialFeatures(String[] newSpecialFeatures)
  83.    {
  84.       specialFeatures[0] = newSpecialFeatures[0];
  85.       specialFeatures[1] = newSpecialFeatures[1];
  86.       specialFeatures[2] = newSpecialFeatures[2];
  87.    }
  88.    
  89.    public void setWideScreenFormat(boolean newWideScreenFormat)
  90.    {
  91.       wideScreenFormat = newWideScreenFormat;
  92.    }  
  93.    
  94.    public void setTvFormat(boolean newTvFormat)
  95.    {
  96.       tvFormat = newTvFormat;
  97.    }
  98.    
  99.    public void setSoundOptions(String[] newSoundOptions)
  100.    {
  101.       soundOptions[0] = newSoundOptions[0];
  102.       soundOptions[1] = newSoundOptions[1];
  103.       soundOptions[2] = newSoundOptions[2];
  104.    }
  105.    
  106.    //displays a text
  107.    public void playMedia()
  108.    {
  109.       System.out.println("Play DVD Media!");
  110.    }
  111.    
  112.    //displays all the information in the DVD class
  113.    public String toString()
  114.    {
  115.       String str = "";
  116.       String str1 = "";
  117.      
  118.       for(int i = 0; i < specialFeatures.length; i++)
  119.           str += specialFeatures[i] +", ";
  120.          
  121.       for(int i = 0; i < soundOptions.length; i++)
  122.           str1 += soundOptions[i] +", ";
  123.              
  124.       return super.toString()+"\nSpecial Features: "+str+"Wide Screen Format: "+wideScreenFormat+"."+" Tv Format: "+
  125.              tvFormat+". Sound Options: "+str1;
  126.    }
  127.    
  128.    public void readDvd()
  129.    {
  130.      Scanner keyboard = new Scanner(System.in);
  131. //     public DVD(String theTitle, String theMajorArtist, int thePlayingTime,
  132. //             int theNumPlays, String[] theSupportingActors,
  133. //             String theDirector, String theFormat,
  134. //             String[] specialFeatures, boolean wideScreenFormat, boolean tvFormat, String[] soundOptions)
  135.      System.out.println("Enter the following information:\n");
  136.      System.out.print("Title:");
  137.      String title = keyboard.next();
  138.      System.out.print("Major Artist:");
  139.      String majorArtist = keyboard.next();
  140.      System.out.print("Playing Time: (Integer Only)");
  141.      String playingTime = keyboard.next();
  142.      System.out.print("Num Plays: (Integer Only)");
  143.      String numPlays = keyboard.next();
  144.      System.out.print("Supporting Actors:");
  145.      String supportingActorsinput = keyboard.next();
  146.      String [] supportingActors = new String[]{supportingActorsinput};
  147.      System.out.print("Director:");
  148.      String director = keyboard.next();
  149.      System.out.print("Format:");
  150.      String format = keyboard.next();
  151.      System.out.print("Special Features:");
  152.      String specialFeaturesinput = keyboard.next();
  153.      String [] specialFeatures = new String[]{specialFeaturesinput};
  154.      System.out.print("wideScreenFormat: Boolean");
  155.      String wideScreenFormat = keyboard.next();
  156.      System.out.print("tvFormat: Boolean");
  157.      String tvFormat = keyboard.next();
  158.      System.out.print("Sound Options:");
  159.      String soundOptionsinput = keyboard.next();
  160.      String [] soundOptions = new String[]{soundOptionsinput};
  161.      System.out.println();
  162.      DVD userDefinedDVD = new DVD(title, majorArtist,Integer.valueOf(playingTime), Integer.valueOf(numPlays), (String [])supportingActors, director, format, (String [])specialFeatures, Boolean.valueOf(wideScreenFormat),Boolean.valueOf(tvFormat),(String []) soundOptions);
  163.      userDefinedDVD.save();
  164.    }
  165.    public void save(){
  166.        try(PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("C:\\Users\\joe\\workspace\\KidsHomework\\bin\\edith\\test.txt", true)))) {
  167.             out.println("Type: " +"DVD");
  168.             out.println(this.getTitle() + "//title");
  169.             out.println(this.getMajorArtist() + "//Major Artist");
  170.             out.println(this.getPlayingTime() + "//Playing Time Integer Value");
  171.             out.println(this.getNumPlays() + "//Num Plays Integer Value");
  172.             out.println(this.getSupportingActors() + "//Support Artist String Array");
  173.             out.println(this.getDirector() + "//Director");
  174.             out.println(this.getFormat() + "//Format");
  175.             out.println(this.getSpecialFeatures() + "//Special Features String Array");
  176.             out.println(this.getWideScreenFormat() + "//WideScreen Format boolean");
  177.             out.println(this.getTvFormat() + "//TV Format boolean");
  178.             out.println(this.getSoundOptions() + "//Sound options String Array");
  179.         }catch (IOException e) {
  180.             //exception handling left as an exercise for the reader
  181.         }
  182.    }
  183. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement