/******************************************************************************
Online Java Compiler.
Code, Compile, Run and Debug java program online.
Write your code in this editor and press "Run" button to execute it.
*******************************************************************************/
public class Main
{
public static void main(String[] args) {
System.out.println("Hello World");
}
}
/**
* The add operation runs in amortized constant time,
* that is, adding n elements requires O(n) time. All
* of the other operations run in linear time (roughly speaking).
* The constant factor is low compared to that for the LinkedList
* implementation. The order of elements added to an ArrayList
* are preserved.
*/
import java.util.ArrayList;
public class UseArrayList {
ArrayList<Movie> al = new ArrayList<>();
public void addMovie(Movie movie){
al.add(movie);
}
}
/**
* LinkedList is based on a doubly linked list.
* Operations that index into the list will traverse the
* list from the beginning or the end, whichever is closer
* to the specified index. Has a variant called as a
* singly-LinkedList, which is normally referred to as a
* linked list. Common method calls (get(); add(); remove();
* etc.,) are actually N/2 operations and not even linear.
*/
import java.util.LinkedList;
public class UseLinkedList {
LinkedList<Movie> ll = new LinkedList<>();
public void addMovie(Movie movie){
ll.add(movie);
}
}
/**
* Models both FIFO & LIFO. Can be used as both
* a Queue as well as a stack. Methods such as
* remove(); shifts elements in O(n) time. Has
* linear time complexity and it only gets bad
* with a large number of elements because we
* have more and more element shifts.
*/
import java.util.ArrayDeque;
public class UseArrayDeque {
ArrayDeque<Movie> ad = new ArrayDeque<>();
public void addMovie(Movie movie){
ad.add(movie);
}
}
public class Movie {
private String title;
private String theatre;
private String location;
private String showTime;
private int seats;
private int purchased;
private double price;
public Movie(String name, String theatre, String location, String showTime, int seats) {
this.title = title;
this.theatre = theatre;
this.location = location;
this.showTime = showTime;
this.seats = seats;
purchased = seats;
price = seats * 9.50;
}
public String getName() {
return name;
}
public String getTheatre() {
return theatre;
}
public String getLocation() {
return location;
}
public String getShowTime() {
return showTime;
}
public int getSeats() {
return seats;
}
public double getPrice() {
return price;
}
public int getPerchased(){
return perchased;
}
public void incrementPerchased(){
perchased++;
}
public void decrementSeats(){
seats--;
}
@Override
public String toString(){
return "Movie details:\nMovie Name " + name + "\nTheatre: " + theatre +
"\nTheatre Location: " + location + "\nShowtime: " + showTime +
"\nNumber of seats: " + seats + "\nPrice: " + price;
}
}