Class MediaMerger
This class is meant to host the main method used to test all the other classes in our project.
We reccomend that you work on implementing the main
method in this class progressively, as you add features to the
other classes of this project. Do not attempt to implement all
requirements for the main method before the other classes are able
to be used in that manner. Work progressively, as demonstrated
during the live coding videos in the lectures.
Start by creating two separate ArrayList objects that will be
referenced by the following variables:
• allVideos, referring to a list of objects of class Video
• allBooks, referring to a list of objects of class Book
You will then create 3 objects of class Video and 3 objects of
Class Book, representing videos and books of your choice, and add
them to their respective list.
When the list have been populated, you will iterate on
each list, one after the other, and display what the toString
method returns for each object therein
Once you got the above working and therefore added the necessary
ode to all classes, proceed with adding a 3rd ArrayList as follows;
Declare a reference variable named everything and create a new
object of class ArrayList that will allow us to store references of
class medium in the new list. As described in the remainder of
these requirements, this new class Medium will be the superclass of
both the classes Video & Book.
You will then iterate on each of the first two lists you created and add every Video or Book objects they reference to the list by everything.
You will then iterate on the list referenced by everything to display the information about every object that has just been added to it.
the programming language is java
import java.util.ArrayList;
public class MediaMerger {
public static void main(String[] args) {
ArrayList<Video> allVideos =
new ArrayList<>(); // ArrayList of video class
ArrayList<Book> allBooks =
new ArrayList<>(); // ArrayList of book class
Video video1 = new Video("7
rings"); // Making the video objects.
Video video2 = new Video("See you
Again");
Video video3 = new
Video("Filhaal");
allVideos.add(video1); // Adding
the video object in the allVideos arraylist.
allVideos.add(video2);
allVideos.add(video3);
Book book1=new Book("In Search of
Lost Time"); // Making the book objects.
Book book2=new
Book("Ulysses");
Book book3=new Book("Don
Quixote");
allBooks.add(book1); // Adding the
video object in the allBooks arraylist.
allBooks.add(book2);
allBooks.add(book3);
for(int
i=0;i<allVideos.size();i++) { // Iterating on allVideos
arraylist
System.out.println(allVideos.get(i).toString()); // Using
toString() method.
}
for(int
i=0;i<allBooks.size();i++) { // Iterating on allBooks
arraylist
System.out.println(allBooks.get(i).toString()); // Using toString()
method.
}
ArrayList<Medium>
everything=new ArrayList<>(); // Making the arraylist for
medium objects
for(int
i=0;i<allVideos.size();i++) { //Iterating on the allVideos
arraylist.
everything.add(allVideos.get(i)); // Adding the allVideos arraylist
objects in everything arraylist.
}
for(int
i=0;i<allBooks.size();i++) { //Iterating on the allBooks
arraylist.
everything.add(allBooks.get(i)); // Adding the allBooks arraylist
objects in everything arraylist.
}
for(int
i=0;i<everything.size();i++) { //Iterating on the everything
arraylist.
System.out.println(everything.get(i).name);
}
}
private static class Medium { // Medium Class is
made
String name;
private Medium(String str) {
//Parametrized Constructor taking input as String.
name=str;
}
}
private static class Video extends Medium { //
Video class extending Medium class
String name;
private Video(String str) { //
Parametrized Constructor taking input as String.
super(str);
name=str; //
Setting name of video as an input String
}
}
private static class Book extends Medium { // Book
class extending Medium class
String name;
private Book(String str) { //
Parametrized Constructor taking input as String.
super(str);
name=str; //
Setting name of book as an input String
}
}
}
Output:-
Class MediaMerger This class is meant to host the main method used to test all the...
(The interface class-like) Assume you have the Edible interface with its abstract method. Design a class named Animal and its two subclasses named Mammal and Dairy. Make Sheep and Bear as subclasses of Mammal and make implement the Edible interface. howToEat() and sound() are the main two methods for all edible classes while sound() is the main method for the non-edible classes. 1. Draw the UML diagram for the classes and the interface 2. Use Arraylist class to create an...
Exercise 8 (The interface class-like) Assume you have the Edible interface with its abstract method Design a class named Animal and its two subclasses named Mammal and Dairy. Make Sheep and Bear as subclasses of Mammal and make Chicken and Cow as subclasses of Dairy. The Sheep and Dairy classes implement the Edible interface. howToEat) and sound() are the main two methods for all edible classes while sound() is the main method for the non-edible classes. 1. Draw the UML...
ONLY NEED THE DRIVER CLASS PLEASE!!! Domain & Comparator Classes: 0.) Design a hierarchy of classes, where the Media superclass has the artistName and the mediaName as the common attributes. Create a subclass called CDMedia that has the additional arrayList of String objects containing the songs per album. Create another subclass called DVDMedia that has the additional year the movie came out, and an arrayList of co-stars for the movie. 1.) The superclass Media will implement Comparable, and will define...
1. Do the following a. Write a class Student that has the following attributes: - name: String, the student's name ("Last, First" format) - enrollment date (a Date object) The Student class provides a constructor that saves the student's name and enrollment date. Student(String name, Date whenEnrolled) The Student class provides accessors for the name and enrollment date. Make sure the class is immutable. Be careful with that Date field -- remember what to do when sharing mutable instance variables...
In this next example, we'll build two classes that implement the Cloneable Interface. The QuizTracker class contains an ArrayList of QuizScore objects, and it's up to us to build these two classes so that we can make deep copies of QuizTrackers (and share no internal aliases). The key idea here is that to make deep copies of compound objects (or lists of objects), we need to copy (using clone) every object in every list, and even make copies of the...
I am suppose to have my array before the main class but I am getting the error 7 errors found: File: C:\Users\diego\OneDrive\Desktop\school\Spring 2020 classes\How to program java (Late Objects)\PO1\Test_ResidencePolicy.java [line: 60] Error: non-static variable objectArray cannot be referenced from a static context File: C:\Users\diego\OneDrive\Desktop\school\Spring 2020 classes\How to program java (Late Objects)\PO1\Test_ResidencePolicy.java [line: 61] Error: non-static variable objectArray cannot be referenced from a static context File: C:\Users\diego\OneDrive\Desktop\school\Spring 2020 classes\How to program java (Late Objects)\PO1\Test_ResidencePolicy.java [line: 67] Error: non-static variable objectArray cannot...
Project 2 Tasks: Create a Coin.java class that includes the following: Takes in a coin name as part of the constructor and stores it in a private string Has a method that returns the coins name Has an abstract getvalue method Create four children classes of Coin.java with the names Penny, Nickle, Dime, and Quarter that includes the following: A constructor that passes the coins name to the parent A private variable that defines the...
Java: Create a main method for your class, and then add another method to your class (above the main method) named fallingDistance. This method accepts an integer into its parameter t, which is the amount of time, in seconds, that an object has been falling. This method returns the distance, in meters, that the object has fallen during the time interval. When an object s falling because of gravity, we use the following formula to determine the distance the object...
need help in Java Now we’ll continue our project by writing a Facebook class that contains an ArrayList of Facebook user objects. The Facebook class should have methods to list all of the users (i.e. print out their usernames), add a user,delete a user, and get the password hint for a user You will also need to create a driver program. The driver should create an instance of the Facebook class and display a menu containing five options: list users...
In a new file located in the same package as the class Main, create a public Java class to represent a photograph that consists of a linear (not 2D) array of pixels. Each pixel is stored as an integer. The photograph class must have: (a) Two private fields to represent the information stored about the photograph. These are the array of integers and the date the photograph was taken (stored as a String). The values in the array must be...