QuestionAnswered step-by-stepCan someone QC my code and tell

QuestionAnswered step-by-stepCan someone QC my code and tell me why I am getting this error…Can someone QC my code and tell me why I am getting this error message:No enclosing instance accessible package cmis242week8;import java.io.File;import java.io.FileNotFoundException;import java.util.ArrayList;import java.util.Scanner;import java.util.Calendar;import java.util.List;public class CMIS242ASG4{public abstract class Media { // attributes private int id; private String title; private int year; private boolean rentStatus; // default constructor public Media() { } // parameterized constructor public Media(int id, boolean rentStatus, String title, int year) {  this.id = id;  this.rentStatus = rentStatus;  this.title = title;  this.year = year; } // get methods public int getId() {  return this.id; } public String getTitle() {  return this.title; } public int getYear() {  return this.year; } public boolean isRentStatus() { // checks rental status  return rentStatus; } // end get methods // set methods public void setId(int id) throws IdNotValidException {  if (!validateId(id)) { // checks that id is 5 digits long   throw new IdNotValidException(“Id should have 5 digits.”);  }  else {   this.id = id;  } } public void setTitle(String title) {  this.title = title; } public void setYear(int year) {  this.year = year; }  public void setRentStatus(boolean rentStatus) {  this.rentStatus = rentStatus; }// end set methods // calculate rental fee public double calculateRentalFee() {  return 1.50; // flat fee } // checks for exactly five digits and a number public boolean validateId(int id) {  String pattern = “^[0-9]{5}$”;  String uniqueId = String.valueOf(id);  return uniqueId.matches(pattern); } // display info @Override public String toString() {  String statusRental = rentStatus ? “Y” : “N”;  // storing class identifier character  String classPrefix = “”;  // get class name  String first = this.getClass().getSimpleName();  switch (first) {  case “EBook”:   classPrefix = “E”;   break;  case “MusicCD”:   classPrefix = “C”;   break;  case “MovieDVD”:   classPrefix = “D”;   break;  }  return id + “t” + statusRental + “t” + classPrefix + “t” + title + “ttt” + year + “t”; } } // end Media classpublic class EBook extends Media { // attribute private int numberOfChapters; // default constructor public EBook(int numberOfChapters) {  this.numberOfChapters = numberOfChapters; } // parameterized constructor public EBook(int id, boolean rentStatus, String title, int year, int numOfChapters) {  super(id, rentStatus, title, year);  this.numberOfChapters = numOfChapters; } // get/set methods public int getNumOfChapters() {  return this.numberOfChapters; } public void setNumOfChapters(int numOfChapters) {  this.numberOfChapters = numOfChapters; } // end get/set methods // calculate rental fee public double calculateRentalFee() {  // to get current year  int currentYear = Calendar.getInstance().get(Calendar.YEAR);  if(this.getYear() == currentYear) {   return this.numberOfChapters * 0.10 + 1.50 + 1.00;  }  else {   return this.numberOfChapters * 0.10 + 1.50;  } } // display info @Override public String toString() {  return super.toString() + numberOfChapters + “t” + calculateRentalFee(); } } // end EBook classpublic class MusicCD extends Media { // attribute private int length; // default constructor public MusicCD(int length) { } // parameterized constructor public MusicCD(int id, boolean rentStatus, String title, int year, int length) {  super(id, rentStatus, title, year);  this.length = length; } // get method public int getLength() {  return this.length; } //set method public void setLength(int length) {  this.length = length; } // calculate rental fee @Override public double calculateRentalFee() {  // to get current year   int currentYear = Calendar.getInstance().get(Calendar.YEAR);  if (this.getYear() == currentYear) {   return this.length * 0.045 + 1.50 + 2.00;  }   else {   return this.length * 0.045 + 1.50;  } } // display info @Override public String toString() {  String result = new String().format(“%-20s%-20s%-20s”, super.toString(), length, calculateRentalFee());  return result; }} // end MusicCD classpublic class MovieDVD extends Media { // attribute private int size; // default constructor public MovieDVD() { } // parameterized constructor public MovieDVD(int id, boolean rentStatus, String title, int year, int size) {  super(id, rentStatus, title, year);  this.size = size; } // get method public int getSize() {  return this.size; } // set method public void setSize(int size) {  this.size = size; } // calculate rental fee @Override public double calculateRentalFee() {  // to get current year  int currentYear = Calendar.getInstance().get(Calendar.YEAR);  if (this.getYear() == currentYear) {   return 5.00;  } else {   return 3.25 + 1.50;  } } // display info @Override public String toString() {  return super.toString() + size + “t” + calculateRentalFee(); }} // end MovieDVD classpublic class IdNotValidException extends Exception { private static final long serialVersionUID = 1L; public IdNotValidException(String message) {  super(message); }} // end IdNotValidExceptionpublic class Manager { List mediaList = new ArrayList<>(); // array list // default constructor public Manager() { } public void loadMediaFromFile() throws Exception {  try {   File mediaObject = new File(“PRJ4Rentals.txt”);   try (Scanner fileReader = new Scanner(mediaObject)) {    while (fileReader.hasNextLine()) {     String data = fileReader.nextLine();     String[] str = data.split(“,”);     switch (str[2]) {     case “E”:      mediaList.add(new EBook(Integer.parseInt(str[0]), Boolean.parseBoolean(str[1]), str[3], Integer.parseInt(str[4]), Integer.parseInt(str[5])));      break;     case “C”:      mediaList.add(new MusicCD(Integer.parseInt(str[0]), Boolean.parseBoolean(str[1]), str[3], Integer.parseInt(str[4]), Integer.parseInt(str[5])));      break;     case “D”:      mediaList.add(new MovieDVD(Integer.parseInt(str[0]), Boolean.parseBoolean(str[1]), str[3], Integer.parseInt(str[4]), Integer.parseInt(str[5])));      break;     default:      break;     }    }   }  } catch (FileNotFoundException e) {   System.out.println(“File cannot be found.”);  } } // add media object public void addMedia() throws Exception {  Scanner scannerAdd = new Scanner(System.in); // scanner  System.out.println(“”);  System.out.println(“ttChoose item to add:”);  System.out.println(“tt1. Ebook”);  System.out.println(“tt2. MusicCD”);  System.out.println(“tt3. MovieDVD”);  System.out.print(“ttEnter your selection: “);  int choice = Integer.parseInt(scannerAdd.nextLine());  switch (choice) {  case 1:   System.out.print(“Enter id: “);   int id = scannerAdd.nextInt();   scannerAdd.nextLine();   System.out.print(“Enter title: “);   String title = scannerAdd.nextLine();   System.out.print(“Enter year: “);   int year = scannerAdd.nextInt();   System.out.print(“Enter rental status(true for rented/false for not rented) : “);   boolean available = scannerAdd.nextBoolean();   scannerAdd.nextLine();   System.out.print(“Enter number of chapters: “);   String numberOfChapters = scannerAdd.nextLine();   mediaList.add(new EBook(id, available, title, year, Integer.parseInt(numberOfChapters)));   System.out.println(“E-Book added.”);   break;  case 2:   System.out.print(“Enter id: “);   int cId = scannerAdd.nextInt();   scannerAdd.nextLine();   System.out.print(“Enter title: “);   String cTitle = scannerAdd.nextLine();   System.out.print(“Enter year: “);   int cYear = scannerAdd.nextInt();   System.out.print(“Enter rental status(true for rented/false for not rented) : “);   boolean cAvailable = scannerAdd.nextBoolean();   scannerAdd.nextLine();   System.out.print(“Enter length in minutes: “);   String length = scannerAdd.nextLine();   mediaList.add(new MusicCD(cId, cAvailable, cTitle, cYear, Integer.parseInt(length)));   System.out.println(“Music CD added.”);   break;  case 3:   System.out.print(“Enter id: “);   int mId = scannerAdd.nextInt();   scannerAdd.nextLine();   System.out.print(“Enter title: “);   String mTitle = scannerAdd.nextLine();   System.out.print(“Enter year: “);   int mYear = scannerAdd.nextInt();   System.out.print(“Enter rental status(true for rented/false for not rented) : “);   boolean mAvailable = scannerAdd.nextBoolean();   scannerAdd.nextLine();   System.out.print(“Enter size in megabytes: “);   String mb = scannerAdd.nextLine();   mediaList.add(new MovieDVD(mId, mAvailable, mTitle, mYear, Integer.parseInt(mb)));   System.out.println(“Movie DVD added.”);   break;  default:   System.out.println(“Invalid choice, select from the menu.”);   break;  } } // end Add media // find media objects public void findMedia(int mediaID) {  boolean found = false;  for (int i = 0; i < mediaList.size(); i++) {   if (mediaList.get(i).getId() == mediaID) {    System.out.print(mediaList.get(i));    found = true;   }  }  if (!found) {   System.out.println("Media cannot be found.");  } } // end find media objects // remove media public void remove(int mediaId) {  Media del = null;  // iterate list  for (Media st : mediaList) {   // find media to delete by id   if (st.getId() == mediaId) {    del = st;   }  }  if (del == null) { // if null, show error message   System.out.println("Invalid media id.");  }   else {   mediaList.remove(del); // remove from list   System.out.println("Media removed.");  } } // end remove media // rent media public void rentMedia(int id) {  boolean found = false;  for (Media md : mediaList) {   if (md.getId() == id) {    found = true;    // check if media is rented or not    if (md.isRentStatus()) {     System.out.println("Media successfully rented. Rental Fee = $" + md.calculateRentalFee());                                          md.setRentStatus(false); // change status to false if successfully rented    }     else {     System.out.println("Media with id: " + id + " is not available for rental.");     break;    }   }  }  if (!found) {   System.out.println("Media with id: " + id + " cannot be found.");  } } // end rent media // update media public void modifyMedia(int id) {  boolean found = false;  for (Media md : mediaList) {   Scanner scannerEdit = new Scanner(System.in); //  scanner   System.out.println("");   System.out.println("ttChoose Item To Update : ");   System.out.println("tt1. Ebook");   System.out.println("tt2. MovieDVD");   System.out.println("tt3. MusicCD");   System.out.print("ttEnter your selection: ");   int itemChoice = Integer.parseInt(scannerEdit.nextLine());   EBook eB;   MovieDVD mDvd;   MusicCD mCd;   switch (itemChoice) {   case 1:    if (md instanceof EBook && md.getId() == id) {     found = true;     eB = (EBook) md;    }     else {     System.out.println("The Ebook with id: " + id + " cannot be found.");     return;    }    System.out.print("Enter title: ");    String title = scannerEdit.nextLine();    System.out.print("Enter year: ");    int year = scannerEdit.nextInt();    System.out.print("Enter number of chapters: ");    int chapter = scannerEdit.nextInt();    System.out.print("Enter rental status(true for rented/false for not rented) : ");    boolean available = scannerEdit.nextBoolean();    eB.setTitle(title);    eB.setYear(year);    eB.setRentStatus(available);    eB.setNumOfChapters(chapter);    System.out.println("Media successfully updated.");    break;   case 2:    if (md instanceof MusicCD && md.getId() == id) {     found = true;     mCd = (MusicCD) md;    }     else {     System.out.println("The MusicCD with id: " + id + " cannot be found.");     return;    }    scannerEdit.nextLine();    System.out.print("Enter title: ");    String cTitle = scannerEdit.nextLine();    System.out.print("Enter year: ");    int cYear = scannerEdit.nextInt();    System.out.print("Enter rental status(true for rented/false for not rented) : ");    boolean cAvailable = scannerEdit.nextBoolean();    scannerEdit.nextLine();    System.out.print("Enter length in minutes: ");    String length = scannerEdit.nextLine();    mCd.setTitle(cTitle);    mCd.setYear(cYear);    mCd.setRentStatus(cAvailable);    mCd.setLength(Integer.parseInt(length));    System.out.println("Media updated successfully.");    break;   case 3:    if (md instanceof MovieDVD && md.getId() == id) {     found = true;     mDvd = (MovieDVD) md;    }     else {     System.out.println("The MovieDVD with id: " + id + " cannot be found.");     return;    }    scannerEdit.nextLine();    System.out.print("Enter title: ");    String mTitle = scannerEdit.nextLine();    System.out.print("Enter year: ");    int mYear = scannerEdit.nextInt();    System.out.print("Enter rental status(true for rented/false for not rented) : ");    boolean mAvailable = scannerEdit.nextBoolean();    scannerEdit.nextLine();    System.out.print("Enter size in megabytes: ");    String mb = scannerEdit.nextLine();    mDvd.setTitle(mTitle);    mDvd.setYear(mYear);    mDvd.setRentStatus(mAvailable);    mDvd.setSize(Integer.parseInt(mb));    System.out.println("Media updated successfully.");    break;   default:    System.out.println("Invalid choice.");    break;   }   break;  }  if (!found) {   System.out.println("The media object with id: " + id + " cannot be found.");  } } // display current media available public void displayCurrentMedia() {  if (mediaList.isEmpty()) {   System.out.println("Media cannot be found.");   return;  }  for (Media media : mediaList) {   System.out.println(media.toString());  } } // end display current media // display one object public void displayOneMedia(int mediaId) {  if (mediaList.isEmpty()) {   System.out.println("Media cannot be found.");   return;  }  for (Media media : mediaList) {   if (media.getId() == mediaId) {    System.out.println(media.toString());    break;   }    else {    System.out.println("No media containing that id.");    break;   }  } } // end display one object // display all media objects public void displayAllMedia(String mediaType) {  if (mediaList.isEmpty()) {   System.out.println("Media cannot be found.");   return;  }  for (Media media : mediaList) {   System.out.println(media);  } } // end display all media objects // display all media types public void displayEbook() {  if (mediaList.isEmpty()) {   System.out.println("Media cannot be found.");   return;  }  for (Media media : mediaList) {   if (media instanceof EBook) {    System.out.println(media.toString());   }  } } // end display EBook public void displayMusicCD() {  if (mediaList.isEmpty()) {   System.out.println("Media cannot be found.");   return;  }  for (Media media : mediaList) {   if (media instanceof MusicCD) {    System.out.println(media.toString());   }  } } // end display MusicCD public void displayMovieDVD() {  if (mediaList.isEmpty()) {   System.out.println("Media cannot be found.");   return;  }  for (Media media : mediaList) {   if (media instanceof MovieDVD) {    System.out.println(media.toString());   }  } } // end display MovieDVD   public static void main(String[] args) throws Exception {   // instance of manager   Manager manager = new Manager();   // load media data from file   manager.loadMediaFromFile();   System.out.println("Media List: ");   // title   System.out.println("IDtRenttTypetTitletttPubtScopetCalc");   manager.displayCurrentMedia();   //  ArrayList to hold the media library   ArrayList media = new ArrayList<>();   Scanner input = new Scanner(System.in); // scanner   // loop until exit   while (CMIS242ASG4.menu()) {    int choice = 0;    System.out.print(“Enter your selection: “);    choice = Integer.parseInt(input.nextLine());    switch (choice) {    case 1:     manager.addMedia();     break;    case 2:     System.out.print(“Enter media id to find: “);     int idMedia = Integer.parseInt(input.nextLine());     manager.findMedia(idMedia);     break;    case 3:     System.out.print(“Enter media id to remove: “);     int id = Integer.parseInt(input.nextLine());     manager.remove(id);     break;    case 4:     System.out.print(“Enter media id to rent: “);     int idRentMedia = Integer.parseInt(input.nextLine());     manager.rentMedia(idRentMedia);     break;    case 5:     System.out.print(“Enter media id to modify: “);     int mediaIdModify = Integer.parseInt(input.nextLine());     manager.modifyMedia(mediaIdModify);     break;    case 6:     System.out.println(“”);     System.out.println(“tChoose Display type: “);     System.out.println(“t1. Display all items”);     System.out.println(“t2. Display one item”);     System.out.println(“t3. Display all selections of a type(Ebook, MovieDVD, MusicCD)”);     System.out.print(“Enter your selection: “);     int displayChoice = Integer.parseInt(input.nextLine());     // loop to display a specific media category     switch (displayChoice) {     case 1:      manager.displayCurrentMedia();      break;     case 2:      System.out.print(“Enter media id: “);      int displayId = Integer.parseInt(input.nextLine());      manager.displayOneMedia(displayId);      break;     case 3:      System.out.println(“”);      System.out.println(“ttChoose Display Item : “);      System.out.println(“tt1. Ebook”);      System.out.println(“tt2. MovieDVD”);      System.out.println(“tt3. MusicCD”);      System.out.print(“ttEnter your selection: “);      int itemChoice = Integer.parseInt(input.nextLine());      // loop to display specific media type      switch (itemChoice) {      case 1:       manager.displayEbook();       break;      case 2:       manager.displayMovieDVD();       break;      case 3:       manager.displayMusicCD();       break;      default:       System.out.println(“Invalid choice.”);       break;      }      break;     default:      System.out.println(“Invalid choice.”);      break;     }     break;    case 7:     System.out.println(“Thank you for using the program. Goodbye!”);     System.exit(0);     break;    default:     System.out.println(“Enter valid choice.”);     break;    }   }   input.close();  } }  private static boolean menu() {   System.out.println(“”);   System.out.println(“Media Rental System”);   System.out.println(“1. Add “);   System.out.println(“2. Find “);   System.out.println(“3. Remove “);   System.out.println(“4. Rent “);   System.out.println(“5. Modify “);   System.out.println(“6. Display One Media Object “);   System.out.println(“7. Display All Media of One Type “);   System.out.println(“8. Display Whole Library of Media Objects “);   System.out.println(“9. Exit “);   return true;  } }// end menuComputer ScienceEngineering & TechnologyC++ ProgrammingCMIS 242Share Question

How it works

  1. Paste your instructions in the instructions box. You can also attach an instructions file
  2. Select the writer category, deadline, education level and review the instructions 
  3. Make a payment for the order to be assignment to a writer
  4.  Download the paper after the writer uploads it 

Will the writer plagiarize my essay?

You will get a plagiarism-free paper and you can get an originality report upon request.

Is this service safe?

All the personal information is confidential and we have 100% safe payment methods. We also guarantee good grades

Calculate the price of your order

550 words
We'll send you the first draft for approval by September 11, 2018 at 10:52 AM
Total price:
$26
The price is based on these factors:
Academic level
Number of pages
Urgency
Basic features
  • Free title page and bibliography
  • Unlimited revisions
  • Plagiarism-free guarantee
  • Money-back guarantee
  • 24/7 support
On-demand options
  • Writer’s samples
  • Part-by-part delivery
  • Overnight delivery
  • Copies of used sources
  • Expert Proofreading
Paper format
  • 275 words per page
  • 12 pt Arial/Times New Roman
  • Double line spacing
  • Any citation style (APA, MLA, Chicago/Turabian, Harvard)

Our guarantees

Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.

Money-back guarantee

You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.

Read more

Zero-plagiarism guarantee

Each paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.

Read more

Free-revision policy

Thanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.

Read more

Privacy policy

Your email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.

Read more

Fair-cooperation guarantee

By sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.

Read more

Order your essay today and save 20% with the discount code ESSAYHELP