Question: Question: Write the Java code below in IDE ECLIPSE enviroment and provide screenshots of the execution. Project Media Rental System Before attempting this project, be

Question: Write the Java code below in IDE ECLIPSE enviroment and provide screenshots of the execution.

Project Media Rental System Before attempting this project, be sure you have completed all of the reading assignments, non- graded exercises, examples, discussions, and assignments to date. Design and implement Java program as follows: 1) Media hierarchy: Create Media, EBook, MovieDVD, and MusicCD classes from Week 3 -> Practice Exercise - Inheritance solution. Add an attribute to Media class to store indication when media object is rented versus available. Add code to constructor and create get and set methods as appropriate. Add any additional constructors and methods needed to support the below functionality 2) Design and implement Manager class which (Hint: check out Week 8 Reading and Writing files example): stores a list of Media objects has functionality to load Media objects from files creates/updates Media files has functionality to add new Media object to its Media list has functionality to find all media objects for a specific title and returns that list has functionality to rent Media based on id (updates rental status on media, updates file, returns rental fee) 3) Design and implement MediaRentalSystem which has the following functionality: user interface which is either menu driven through console commands or GUI buttons or menus. Look at the bottom of this project file for sample look and feel. (Hint: for command-driven menu check out Week 2: Practice Exercise - EncapsulationPlus and for GUI check out Week 8: Files in GUI example) selection to load Media files from a given directory (user supplies directory) selection to find a media object for a specific title value (user supplies title and should display to user the media information once it finds it - should find all media with that title) selection to rent a media object based on its id value (user supplies id and should display rental fee value to the user) selection to exit program 4) Program should throw and catch Java built-in and user-defined exceptions as appropriate 5) Your classes must be coded with correct encapsulation: private/protected attributes, get methods, and set methods and value validation 6) There should be appropriate polymorphism: overloading, overriding methods, and dynamic binding 7) Program should take advantage of the inheritance properties as appropriate

Expert Answer

This solution was written by a subject matter expert. It's designed to help students like you learn core concepts.

SOLUTION-

Note :- I have solve the problem in Java code if you have any doubt just let me know

import java.io.File;

import java.io.FileNotFoundException;

import java.util.ArrayList;

import java.util.List;

import java.util.Scanner;

class Media {

int id;

String title;

int year, chapter;

boolean available;

Media() {

}

public Media(int id, String title, int year, int chapter, boolean available) {

this.id = id;

this.title = title;

this.year = year;

this.chapter = chapter;

this.available = available;

}

public int getId() {

return id;

}

public void setId(int id) {

this.id = id;

}

public String getTitle() {

return title;

}

public void setTitle(String title) {

this.title = title;

}

public int getYear() {

return year;

}

public void setYear(int year) {

this.year = year;

}

public int getChapter() {

return chapter;

}

public void setChapter(int chapter) {

this.chapter = chapter;

}

public boolean isAvailable() {

return available;

}

public void setAvailable(boolean available) {

this.available = available;

}

}

class EBook extends Media {

EBook(int id, String title, int year, int chapter, boolean available) {

super(id, title, year, chapter, available);

}

@Override

public String toString() {

return "EBook [id:" + this.id + " title:" + this.title + " chapter:" + this.chapter + " year:" + this.year

+ " available:" + this.available + "] ";

}

}

class MovieDVD extends Media {

MovieDVD(int id, String title, int year, int chapter, boolean available) {

super(id, title, year, chapter, available);

}

@Override

public String toString() {

return "MovieDVD [id:" + this.id + " title:" + this.title + " chapter:" + this.chapter + " year:" + this.year

+ " available:" + this.available + "] ";

}

}

class MusicCD extends Media {

MusicCD(int id, String title, int year, int chapter, boolean available) {

super(id, title, year, chapter, available);

}

@Override

public String toString() {

return "MusicCD [id:" + this.id + " title:" + this.title + " chapter:" + this.chapter + " year:" + this.year

+ " available:" + this.available + "] ";

}

}

class Manager {

static List list=new ArrayList<>();;

Manager() {

}

public boolean LoadMedia(String path) {

try {

File myObj = new File(path);

Scanner myReader = new Scanner(myObj);

while (myReader.hasNextLine()) {

String data = myReader.nextLine();

String[] str = data.split(" ");

if (str[0].equals("EBook")) {

list.add(new EBook(Integer.parseInt(str[1]), str[2], Integer.parseInt(str[3]),

Integer.parseInt(str[4]), Boolean.parseBoolean(str[5])));

}else if(str[0].equals("MusicCD")) {

list.add(new MusicCD(Integer.parseInt(str[1]), str[2], Integer.parseInt(str[3]),

Integer.parseInt(str[4]), Boolean.parseBoolean(str[5])));

}else {

list.add(new MovieDVD(Integer.parseInt(str[1]), str[2], Integer.parseInt(str[3]),

Integer.parseInt(str[4]), Boolean.parseBoolean(str[5])));

}

}

System.out.println(list);

myReader.close();

return true ;

} catch (FileNotFoundException e) {

System.out.println("An error occurred.");

e.printStackTrace();

return false;

}

}

public void findMedia(String title) {

for(Media m : list) {

if(m.getTitle().equals(title))

System.out.print(m.toString());

}

}

public void rentMedia(int id) {

for(Media m : list ) {

if(m.getId()==id) {

if(m.isAvailable())

System.out.println("media successfully rented out ");

else

System.out.println("Media with id="+id+" is not available for rent ");

}

}

}

}

public class MediaRentalSystem {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

while (Menu()) {

int choice = 0;

System.out.println("Enter choice");

choice = sc.nextInt();

Manager m = new Manager();

switch (choice) {

case 1:

//String path = "C:\\Users\\Admin\\Documents\\workspace-spring-tool-suite-4-4.9.0.RELEASE\\Core-Java\\src\\media.txt";

System.out.println("Enter file path load media ");

String path=sc.next();

m.LoadMedia(path);

break;

case 2:

System.out.println("Enter media title ");

String title=sc.next();

m.findMedia(title);

break;

case 3:

System.out.println("Enter media id :");

int id =sc.nextInt();

m.rentMedia(id);

break;

case 9:

System.exit(0);

break;

default:

System.out.println("Enter valid choice ");

break;

}

}

sc.close();

}

private static boolean Menu() {

System.out.println("Welcome to media rental system");

System.out.println("1: Load Media objects ");

System.out.println("2: Find Media objects ");

System.out.println("3: Rent Media objects ");

System.out.println("9: exit ");

return true;

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!