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..
Measures of Dispersion and Variability: Range, QD, AD and SD
Question- Write the Java code below in IDE ECLIPSE enviroment and prov.docx
1. 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
2. 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() {
3. 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;
}
4. 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 + "]n";
}
}
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() {
7. 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");
8. choice = sc.nextInt();
Manager m = new Manager();
switch (choice) {
case 1:
//String path = "C:UsersAdminDocumentsworkspace-spring-tool-suite-4-
4.9.0.RELEASECore-Javasrcmedia.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:
9. 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;
}
}