The learning outcomes of this assignment include: Knowledge of the Ant build too
ID: 3662596 • Letter: T
Question
The learning outcomes of this assignment include:
Knowledge of the Ant build tool to create/modify/manage a project that consists of both Java and C++ source code.
Ability to use Java and C++ to create a program in each language that includes multiple classes.
Ability to work with both Java and C++ programming languages from the command line.
You should be able to complete this assignment, after you complete the unit of the Ser321 Schedule titled: Build Tools Ant and Make.
You are to build an Ant build-able project that contains both Java and C++ programs. The project folder should be Assign2 and its structure should be the same as you created in Assign1. Your Ant build file should contain the following targets:
build.java This target compiles the Java source code to create class files in the Assign2/classes folder.
execute.java This target depends on build.java and causes your java sample program to be execute. See the sample screen shot below to see sample output from the program.
build.cpp This target compiles the C++ source code to create an executable image in the Assign2/bin folder. Use the cpptasks cc task to compile with g++.
execute.cpp Similar to execute.java, but for the C++ program.
clean This target removes the Assign2/bin and Assign2/classes folders.
prepare This target creates the Assign2/bin and Assign2/classes folders.
You may want to use javaFraction.jar, and cppFraction.jar as a basis for creating each program. Extract each with:
jar xvf cppFraction.jar
from a folder in which you'll place Ser321 example programs, such as: ~/Ser321/Examples/. You may also want to create the folder ~/Ser321/Assigns/Assign2) for building this assignment solution.
Program Description Both the Java and C++ programs have the same functionality, as described below. The Java solution will require at least two files: MediaDescription.java and MediaLibrary.java. The C++solution should consist of five files: MediaLibrary.hpp, MediaLibrary.cpp, MediaDescription.hpp, MediaDescription.cpp, and main.cpp.
MediaDescription is a class that wraps the properties of a music or video file. Place the following properties in your MediaDescription class.
mediaType Its value should either Music, or Video.
title The title of the song or the video/movie.
author The artist of a song or the leading actor/actress of video.
album Unused for videos, but is used to group related songs.
genre Used to group videos.
filename The file name in whic the media is stored. Most commonly the is title.mp3 or title.mp4
Provide constructors accessor and getter methods as appropriate. Provide a toString() method for a MediaDescription object which returns a string suitable for printing.
The MediaLibrary class should provide storage and management for a collection of media. The library is used to store MediaDescription objects. In future assignments, the MediaLibrary will become a server running on the Raspberry Pi. Clients will connect to the server and use the methods provided by the MediaLibrary to create a user-interface for browsing and playing media. You may assume that all titles stored in a library object are unique. Your MediaLibrary class should provide the following methods.
public boolean add(MediaDescription aClip); A method to add a new song or video the library. True is returned when the request is successful.
public boolean remove(String aTitle); A method to remove the named MediaDescription from the library.
public MediaDescription get(String aTitle); Returns the media description with title aTitle.
public String[] getTitles(); Returns an array of strings, which are all of the titles in the library.
public String[] getMusicTitles(); Returns an array of strings, which are all of the music titles in the library.
public String[] getVideoTitles(); Returns an array of strings, which are all of the video titles in the library.
For your C++ version of MediaLibrary you may find it easier to return a std::vector<string> rather than an array of strings. Thus the signature of getTitles would be:
std::vector<string> getTitles(); //returns a vector of strings of all media titles in the library
You should provide a simple main program for both the Java and C++ media libraries. The program should demonstrate that all methods in the library work. For example your code in the Java main may initialize a library with code like:
After initializing a MediaLibrary object, the main should demonstrate that all methods work --> not a thorough test, but demonstrate all of the library methods. For example, here is a screen shot of the instructors Java solution. Note that you do not need to print out the Json representation of each MediaDescription, just convert it to a string, which distinguishes each of the fields.
Explanation / Answer
Please submit the screenshot for The JSON part. Here are the other files.
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class MediaLibrary {
List<MediaDescription> list=new ArrayList<MediaDescription>();
public boolean add(MediaDescription aClip) {
list.add(aClip);
return true;
}
public boolean remove(String aTitle) {
for(int i=0;i<list.size();i++)
{
String title=list.get(i).getTitle();
if(title.equals(aTitle))
list.remove(i);
return true;
}
return false;
}
public MediaDescription get(String aTitle) {
for(int i=0;i<list.size();i++)
{
String title=list.get(i).getTitle();
if(title.equals(aTitle))
return list.get(i);
}
return null;
}
public List<String> getTitles() {
List<String> listTitles=new ArrayList<String>();
for(int i=0;i<list.size();i++)
{
String title=list.get(i).getTitle();
listTitles.add(title);
}
return listTitles;
}
public List<String> getMusicTitles() {
List<String> listTitles=new ArrayList<String>();
for(int i=0;i<list.size();i++)
{
String mediaType=list.get(i).getMediaType();
if(mediaType.equals("music"))
{
String title=list.get(i).getTitle();
listTitles.add(title);
}
}
return listTitles;
}
public List<String> getVideoTitles() {
List<String> listTitles=new ArrayList<String>();
for(int i=0;i<list.size();i++)
{
String mediaType=list.get(i).getMediaType();
if(mediaType.equals("video"))
{
String title=list.get(i).getTitle();
listTitles.add(title);
}
}
return listTitles;
}
}
public class MediaDescription
{
public String mediaType;
public String title;
public String author;
public String album;
public String genre;
public String filename;
public MediaDescription(String mediaType,String title,String author,String album,String genre,String filename)
{
System.out.println("Constructor initialised");
}
public String getMediaType() {
return mediaType;
}
public void setMediaType(String mediaType) {
this.mediaType = mediaType;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getAlbum() {
return album;
}
public void setAlbum(String album) {
this.album = album;
}
public String getGenre() {
return genre;
}
public void setGenre(String genre) {
this.genre = genre;
}
public String getFilename() {
return filename;
}
public void setFilename(String filename) {
this.filename = filename;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.