// DVD.java
public class DVD extends MediaItem
{
private String director;
private String rating;
private int runtime;
public DVD()
{
this("",0,"","",0);
}
public DVD(String title, int year, String director,
String rating, int runtime)
{
super(title, year);
this.director = director;
this.rating = rating;
this.runtime = runtime;
}
public DVD(DVD copy)
{
this(copy.getTitle(),
copy.getYear(), copy.director, copy.rating, copy.runtime);
}
public String getDirector()
{
return director;
}
public String getRating()
{
return rating;
}
public int getRuntime()
{
return runtime;
}
public void setRating(String rating)
{
this.rating = rating;
}
public boolean equals(DVD test)
{
return super.equals(test)
&& director.equalsIgnoreCase(test.director)
&& rating.equalsIgnoreCase(test.rating)
&& runtime == test.runtime;
}
public String toString()
{
return super.toString()+"\nDirector
: "+director+"\nRating : "+rating+"\nRuntime : "+runtime+"
minutes";
}
}
//end of DVD.java
// ForeignDVD.java
public class ForeignDVD extends DVD
{
private String language;
private boolean hasSubTitles;
public ForeignDVD()
{
this("",0,"","",0,"",false);
}
public ForeignDVD(String title, int year, String
director, String rating, int runtime, String language, boolean
hasSubTitles)
{
super(title, year, director,
rating, runtime);
this.language = language;
this.hasSubTitles =
hasSubTitles;
}
public ForeignDVD(ForeignDVD copy)
{
this(copy.getTitle(),
copy.getYear(), copy.getDirector(), copy.getRating(),
copy.getRuntime(), copy.language, copy.hasSubTitles);
}
public String getLanguage()
{
return language;
}
public boolean subTitlesAvailable()
{
return hasSubTitles;
}
public boolean equals(ForeignDVD test)
{
return super.equals(test)
&& language.equalsIgnoreCase(test.language) &&
hasSubTitles == test.hasSubTitles;
}
public String toString()
{
return super.toString()+"\nLanguage
: "+language+"\nHas Subtitles : "+hasSubTitles;
}
}
//end of ForeignDVD.java
// MediaItemDriver.java
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
public class MediaItemDriver {
// method to display menu
private static void menu()
{
System.out.println("1. Display all
DVD objects");
System.out.println("2. Display all
Foreign DVD objects");
System.out.println("3. Display all
MediaItem objects");
System.out.println("4. Calculate
and display the total runtime for all DVDs");
System.out.println("5. Search for
items with a specific rating");
System.out.println("6. Search for
item by title");
System.out.println("7. Search for
items that have subtitles");
System.out.println("8. Display DVD
with the longest runtime");
System.out.println("9.
Exit");
}
// method to display all dvd
private static void
displayAllDVD(ArrayList<MediaItem> items)
{
for(int
i=0;i<items.size();i++)
{
if(items.get(i)
instanceof DVD)
{
System.out.println(items.get(i));
System.out.println();
}
}
}
// method to display all foreign dvd
private static void
displayAllForeignDVD(ArrayList<MediaItem> items)
{
for(int
i=0;i<items.size();i++)
{
if(items.get(i)
instanceof ForeignDVD)
{
System.out.println(items.get(i));
System.out.println();
}
}
}
// method to display all media item
private static void
displayAllMediaItem(ArrayList<MediaItem> items)
{
for(int
i=0;i<items.size();i++)
{
System.out.println(items.get(i));
System.out.println();
}
}
//method to calculate and display total run time
private static void
displayTotalRuntime(ArrayList<MediaItem> items)
{
int totalRuntime = 0;
for(int
i=0;i<items.size();i++)
{
if(items.get(i)
instanceof DVD)
totalRuntime +=
((DVD)items.get(i)).getRuntime();
}
System.out.println("Total runtime :
"+totalRuntime+" minutes");
}
// method to search the items by rating
private static void
searchByRating(ArrayList<MediaItem> items, Scanner
scan)
{
String rating;
// if more ratings are present,add
to the list
System.out.print("Enter the type of
rating(NR/R/PG/PG-13): ");
rating = scan.nextLine();
for(int
i=0;i<items.size();i++)
{
if(items.get(i)
instanceof DVD)
{
if(((DVD)items.get(i)).getRating().equalsIgnoreCase(rating))
{
System.out.println(items.get(i));
System.out.println();
}
}
}
}
// method ot search the items by title
private static void
searchByTitle(ArrayList<MediaItem> items, Scanner scan)
{
String title;
System.out.print("Enter the title:
");
title = scan.nextLine();
for(int
i=0;i<items.size();i++)
{
if(items.get(i).getTitle().equalsIgnoreCase(title))
{
System.out.println(items.get(i));
System.out.println();
}
}
}
// method to display all items that have sub
titles
private static void
searchWithSubtitles(ArrayList<MediaItem> items)
{
for(int
i=0;i<items.size();i++)
{
if(items.get(i)
instanceof ForeignDVD)
{
if(((ForeignDVD)items.get(i)).subTitlesAvailable())
{
System.out.println(items.get(i));
System.out.println();
}
}
}
}
// method to determine and display the dvd with
longest runtime
private static void
longestRuntimeDVD(ArrayList<MediaItem> items)
{
DVD result = null;
for(int
i=0;i<items.size();i++)
{
if(items.get(i)
instanceof DVD)
{
if(result == null ||
(((DVD)items.get(i)).getRuntime()) > result.getRuntime())
result =
(DVD)items.get(i);
}
}
if(result == null)
System.out.println("No DVD in the list");
else
System.out.println(result);
}
public static void main(String[] args) throws
FileNotFoundException {
ArrayList<MediaItem> items
= new ArrayList<MediaItem>();
Scanner fileScan = new Scanner(new
File("dvdData.txt"));
String line;
MediaItem item;
// read till the end of file
while(fileScan.hasNextLine())
{
// Assuming
delimiter in file is comma(,)
line =
fileScan.nextLine();
String fields[]
= line.split(",");
if(fields[0].equalsIgnoreCase("d"))
{
item = new
DVD(fields[1].trim(),Integer.parseInt(fields[2].trim()),
fields[3].trim(), fields[4].trim(),
Integer.parseInt(fields[5].trim()));
}else
if(fields[0].equalsIgnoreCase("fd"))
{
item = new
ForeignDVD(fields[1].trim(),Integer.parseInt(fields[2].trim()),
fields[3].trim(),
fields[4].trim(),
Integer.parseInt(fields[5].trim()), fields[6].trim(),
Boolean.parseBoolean(fields[7].trim()));
}else
{
item = new MediaItem(fields[1].trim(),
Integer.parseInt(fields[1].trim()));
}
items.add(item);
}
fileScan.close();
int choice;
Scanner scan = new
Scanner(System.in);
// loop that continues till the
user wants
do
{
menu();
// input of
choice
System.out.print("Enter your choice: ");
choice =
scan.nextInt();
scan.nextLine();
//based on input
perform the operation
if(choice ==
1)
{
displayAllDVD(items);
}
else if(choice
== 2)
{
displayAllForeignDVD(items);
}
else if(choice
== 3)
{
displayAllMediaItem(items);
}
else if(choice
== 4)
{
displayTotalRuntime(items);
}
else if(choice
== 5)
{
searchByRating(items, scan);
}
else if(choice
== 6)
{
searchByTitle(items, scan);
}
else if(choice
== 7)
{
searchWithSubtitles(items);
}
else if(choice
== 8)
{
longestRuntimeDVD(items);
}
else if(choice
!= 9)
{
System.out.println("Invalid choice");
}
System.out.println();
}while(choice != 9);
}
}
//end of MediaItemDriver.java
Output:
Input file:
Output:
no buffered reader. no try catch statements. java code please. And using this super class: Medialtemjava...
Please help me with this code. Thank you Implement the following Java class: Vehicle Class should contain next instance variables: Integer numberOfWheels; Double engineCapacity; Boolean isElectric, String manufacturer; Array of integers productionYears; Supply your class with: Default constructor (which sets all variables to their respective default values) Constructor which accepts all the variables All the appropriate getters and setters (you may skip comments for this methods. Also, make sure that for engineCapacity setter method you check first if the vehicle...
this needs to be in Java:
use a comparator class which
is passed into the sort method that is available on the
ArrayList.
import java.util.Scanner;
public class Assign1{
public static
void main(String[] args){
Scanner reader = new Scanner (System.in);
MyDate todayDate = new MyDate();
int choice = 0;
Library library = new Library();
while (choice != 6){
displayMainMenu();
if (reader.hasNextInt()){
choice = reader.nextInt();
switch(choice){
case 1:
library.inputResource(reader, todayDate);
break;
case 2:
System.out.println(library.resourcesOverDue(todayDate));
break;
case 3:
System.out.println(library.toString());
break;
case 4:
library.deleteResource(reader,...
In Java, Write a class encapsulating a restaurant,which inherits from Store. A restaurant has the following additional attributes: how many people are served every year and the average price per person. code the constructor, accessors, mutators, toString and equals method of the new subclass; also code a method returning the average taxes per year. You also need to include a client class to test your code for both the parent class and the subclass. Code for Store below(Super class aka...
using CSCI300 java Given the following UML Class Diagram Club_Card # card_num : String # name : String # age: int # year: int + Club_Card (all parameters) + Setters & Getters + toString() : String + equals(x: Object): boolean [10 pts] Define the class Club_Card, which contains: 1. All arguments constructor which accepts all required arguments from the main and instantiate a Club_Card object. 2. Set & get method for each data attribute. 3. A toString() method which returns...
Hello. I need help writing the following Java Program. Thank you Develop a class encapsulating the concept of a college course, assuming that a course has following attributers: code (for instance COSC1337), a description, and a number of credits (for instance 3). Include a constructor, the accessors, mutators and methods ‘toString’, ‘equals’, and ‘finalize’. Write a client class to test the behavior of the class and its methods. The outline of the class is given as follows: public class Course...
CONVERT THIS JAVA CODE WITH THE JAVA DOC GUIDELINES WHERE APPROPRIATE. DO NOT CHANGE THE CODE. SAME CODE SHOULD BE USED FOR THE DOCUMENTATION PURPOSES. ONLY INSERT THE JAVA DOC. //Vehicle.java public class Vehicle { private String manufacturer; private int seat; private String drivetrain; private float enginesize; private float weight; //create getters for the attributes public String getmanufacturer() { return manufacturer; } public String getdrivetrain() { return drivetrain;...
please write down both java and output. Thank you!
Chip - colour String Chip (e: String): + get/set methods for all the attributes + equals (e : Chip) : boolean + Chip (c: String): + toString () : String Board - rows: int - cols: int - boardllI: Chip +Board (r: int, c: int): + get methods for all the attributes + isEmpty (r : int, c: int): boolean + add (r : int, c : int, chip : Chip):...
In Java programming language Please write code for the 6 methods below: Assume that Student class has name, age, gpa, and major, constructor to initialize all data, method toString() to return string reresentation of student objects, getter methods to get age, major, and gpa, setter method to set age to given input, and method isHonors that returns boolean value true for honors students and false otherwise. 1) Write a method that accepts an array of student objects, and n, the...
Explain this java code, please. import java.util.Scanner; public class Program11 { public static void main(String[] args) { Scanner stdIn = new Scanner(System.in); final int maxSize = 128; String[] titles = new String[maxSize]; int[] lengths = new int[maxSize]; int numDVDs = 0; String op; op = menu(stdIn); System.out.println(); while (!op.equalsIgnoreCase("q")) { if (op.equalsIgnoreCase("a")) { if (numDVDs < maxSize) numDVDs = addDVD(titles, lengths, numDVDs, stdIn); } else if (op.equalsIgnoreCase("t")) searchByTitle(titles, lengths, numDVDs, stdIn); else if (op.equalsIgnoreCase("l")) searchByLength(titles, lengths, numDVDs, stdIn); System.out.println('\n');...
JAVA This PoD, builds off the Book class that you created on Monday (you may copy your previously used code). For today’s problem, you will add a new method to the class called lastName() that will print the last name of the author (you can assume there are only two names in the author name – first and last). You can use the String spilt (“\s”) method that will split the String by the space and will return an array...