Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package edith;//Derived class
- import java.io.BufferedWriter;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.io.PrintWriter;
- import java.util.*;
- public class DVD extends Video
- {
- //Declares a constant variable
- public final int SIZE = 3;
- //data fields
- private String[] specialFeatures = new String[SIZE];
- private boolean wideScreenFormat;
- private boolean tvFormat;
- private String[] soundOptions = new String[SIZE];
- //Default constructor
- public DVD()
- {
- super();
- specialFeatures[0] = "no special feature";
- specialFeatures[1] = "no special feature";
- specialFeatures[2] = "no special feature";
- wideScreenFormat = false;
- tvFormat = false;
- soundOptions[0] = "no sound option";
- soundOptions[1] = "no sound option";
- soundOptions[2] = "no sound option";
- }
- //Constructor with parameters
- public DVD(String theTitle, String theMajorArtist, int thePlayingTime,
- int theNumPlays, String[] theSupportingActors,
- String theDirector, String theFormat,
- String[] specialFeatures, boolean wideScreenFormat, boolean tvFormat, String[] soundOptions)
- {
- super(theTitle, theMajorArtist, thePlayingTime, theNumPlays,
- theSupportingActors, theDirector, theFormat);
- this.specialFeatures = specialFeatures;
- // this.specialFeatures[1] = specialFeatures[1];
- // this.specialFeatures[2] = specialFeatures[2];
- this.wideScreenFormat = wideScreenFormat;
- this.tvFormat = tvFormat;
- this.soundOptions= soundOptions;
- }
- //Accessor methods
- public String getSpecialFeatures()
- {
- String str = "";
- for(int i = 0; i < specialFeatures.length; i++)
- str += specialFeatures[i] +"\n";
- return str;
- }
- public boolean getWideScreenFormat()
- {
- return wideScreenFormat;
- }
- public boolean getTvFormat()
- {
- return tvFormat;
- }
- public String getSoundOptions()
- {
- String str = "";
- for(int i = 0; i < soundOptions.length; i++)
- str += soundOptions[i] +"\n";
- return str;
- }
- //Mutator methods
- public void setSpecialFeatures(String[] newSpecialFeatures)
- {
- specialFeatures[0] = newSpecialFeatures[0];
- specialFeatures[1] = newSpecialFeatures[1];
- specialFeatures[2] = newSpecialFeatures[2];
- }
- public void setWideScreenFormat(boolean newWideScreenFormat)
- {
- wideScreenFormat = newWideScreenFormat;
- }
- public void setTvFormat(boolean newTvFormat)
- {
- tvFormat = newTvFormat;
- }
- public void setSoundOptions(String[] newSoundOptions)
- {
- soundOptions[0] = newSoundOptions[0];
- soundOptions[1] = newSoundOptions[1];
- soundOptions[2] = newSoundOptions[2];
- }
- //displays a text
- public void playMedia()
- {
- System.out.println("Play DVD Media!");
- }
- //displays all the information in the DVD class
- public String toString()
- {
- String str = "";
- String str1 = "";
- for(int i = 0; i < specialFeatures.length; i++)
- str += specialFeatures[i] +", ";
- for(int i = 0; i < soundOptions.length; i++)
- str1 += soundOptions[i] +", ";
- return super.toString()+"\nSpecial Features: "+str+"Wide Screen Format: "+wideScreenFormat+"."+" Tv Format: "+
- tvFormat+". Sound Options: "+str1;
- }
- public void readDvd()
- {
- Scanner keyboard = new Scanner(System.in);
- // public DVD(String theTitle, String theMajorArtist, int thePlayingTime,
- // int theNumPlays, String[] theSupportingActors,
- // String theDirector, String theFormat,
- // String[] specialFeatures, boolean wideScreenFormat, boolean tvFormat, String[] soundOptions)
- System.out.println("Enter the following information:\n");
- System.out.print("Title:");
- String title = keyboard.next();
- System.out.print("Major Artist:");
- String majorArtist = keyboard.next();
- System.out.print("Playing Time: (Integer Only)");
- String playingTime = keyboard.next();
- System.out.print("Num Plays: (Integer Only)");
- String numPlays = keyboard.next();
- System.out.print("Supporting Actors:");
- String supportingActorsinput = keyboard.next();
- String [] supportingActors = new String[]{supportingActorsinput};
- System.out.print("Director:");
- String director = keyboard.next();
- System.out.print("Format:");
- String format = keyboard.next();
- System.out.print("Special Features:");
- String specialFeaturesinput = keyboard.next();
- String [] specialFeatures = new String[]{specialFeaturesinput};
- System.out.print("wideScreenFormat: Boolean");
- String wideScreenFormat = keyboard.next();
- System.out.print("tvFormat: Boolean");
- String tvFormat = keyboard.next();
- System.out.print("Sound Options:");
- String soundOptionsinput = keyboard.next();
- String [] soundOptions = new String[]{soundOptionsinput};
- System.out.println();
- 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);
- userDefinedDVD.save();
- }
- public void save(){
- try(PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("C:\\Users\\joe\\workspace\\KidsHomework\\bin\\edith\\test.txt", true)))) {
- out.println("Type: " +"DVD");
- out.println(this.getTitle() + "//title");
- out.println(this.getMajorArtist() + "//Major Artist");
- out.println(this.getPlayingTime() + "//Playing Time Integer Value");
- out.println(this.getNumPlays() + "//Num Plays Integer Value");
- out.println(this.getSupportingActors() + "//Support Artist String Array");
- out.println(this.getDirector() + "//Director");
- out.println(this.getFormat() + "//Format");
- out.println(this.getSpecialFeatures() + "//Special Features String Array");
- out.println(this.getWideScreenFormat() + "//WideScreen Format boolean");
- out.println(this.getTvFormat() + "//TV Format boolean");
- out.println(this.getSoundOptions() + "//Sound options String Array");
- }catch (IOException e) {
- //exception handling left as an exercise for the reader
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement