0% found this document useful (0 votes)
57 views3 pages

Core Java Set-1 PDF

The document contains code for a movie booking application that defines classes like Screen, Inventory, and interfaces like ShowMaker. It implements the ShowMaker interface in the BookMyShow class to provide methods like getAllScreenLocation(), getAllScreenMovieName(), getScreensByLocation(), getScreensByMovieName(), and getMovieNameVsScreens() that retrieve screening information from the Inventory class. The MovieWatcherTest class tests these methods by printing their output.

Uploaded by

Neeti Lakhotia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views3 pages

Core Java Set-1 PDF

The document contains code for a movie booking application that defines classes like Screen, Inventory, and interfaces like ShowMaker. It implements the ShowMaker interface in the BookMyShow class to provide methods like getAllScreenLocation(), getAllScreenMovieName(), getScreensByLocation(), getScreensByMovieName(), and getMovieNameVsScreens() that retrieve screening information from the Inventory class. The MovieWatcherTest class tests these methods by printing their output.

Uploaded by

Neeti Lakhotia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Core Java Set-1 ​ ​Note - Write the answer on this sheet only Time: 20 Minutes

1. Is this program correct? if not, correct it-


class ​Employee{
Integer ​id​;
String ​name​;

​public ​Employee(Integer id, String name) {


​this​.​id ​= id;
​this​.​name ​= name;
}
}

public class ​EmployeeTest {


​public static void ​main(String[] args) {
Set<Employee> employees = ​new ​HashSet<>();
employees.add(​new ​Employee(​1​, ​"A"​));
employees.add(​new ​Employee(​2​, ​"B"​));
employees.add(​new ​Employee(​1​, ​"A"​));
System.​out​.println(employees.size());
}
}

2. What will be the output of the programs, explain with reason in one sentence.
public class ​TestEmployee {
​public static void ​main(String[] args) {
Employee e = ​new ​Employee(​1​,​"A"​);
​modifyEmployee​(e);
System.​out​.println(e.​name​);
}

​private static void ​modifyEmployee(Employee e){


e.​name ​= ​"B"​;
e = ​null​;
}
}

3. Is this program correct? if not, correct it-


class ​A{
​void ​m() {
}
}

class ​B ​extends ​A{


​@Override
​void ​m() ​throws ​IOException{
}
}
4. Fill in the blank(inside ​BookMyShow​)

class ​Screen {
​private ​String ​location​;
​private ​String ​name​;
​private ​String ​movieName​;
​private ​String ​language​;

​public ​Screen(String location, String name, String movieName, String language) {


​this​.​location ​= location;
​this​.​name ​= name;
​this​.​movieName ​= movieName;
​this​.​language ​= language;
}

​public ​String getLocation() {​return ​location​;}


​public ​String getName() {​return ​name​;}
​public ​String getMovieName() {​return ​movieName​;}
​public ​String getLanguage() {​return ​language​;}

​@Override
​public ​String toString() {
​return ​"Screen{" ​+ ​"location='" ​+ ​location ​+ ​'​\'​' ​+ ​", name='" ​+ ​name ​+ ​'​\'​' ​+
​", movieName='" ​+ ​movieName ​+ ​'​\'​' ​+ ​", language='" ​+ ​language ​+ ​'​\'​' ​+ ​'}'​;
}
}

class ​Inventory{
​public static ​List<Screen> getScreens() {
List<Screen> screens = ​new ​LinkedList<>();
screens.add(​new ​Screen(​"orion-mall"​, ​"pvr-screen-3"​, ​"the little lion king"​, ​"english"​));
screens.add(​new ​Screen(​"forum-mall"​, ​"imax-screen-1"​, ​"war"​, ​"hindi"​));
screens.add(​new ​Screen(​"forum-mall"​, ​"pvr-screen-4"​, ​"dream girl"​, ​"hindi"​));
screens.add(​new ​Screen(​"central-mall"​, ​"pvr-screen-1"​, ​"war"​, ​"hindi"​));
screens.add(​new ​Screen(​"mantri-square"​, ​"pvr-screen-2"​, ​"joker"​, ​"english"​));
screens.add(​new ​Screen(​"garuda-mall"​, ​"imax-screen-1"​, ​"Mission Mangal"​, ​"hindi"​));
screens.add(​new ​Screen(​"forum-mall"​, ​"imax-screen-3"​, ​"dream girl"​, ​"hindi"​));
screens.add(​new ​Screen(​"mantri-square"​, ​"pvr-screen-1"​, ​"the lion king"​, ​"english"​));
​return ​screens;
}
}

interface ​ShowMaker{
Set<String> getAllScreenLocation();
Set<String> getAllScreenMovieName();
List<Screen> getScreensByLocation(String location);
List<Screen> getScreensByMovieName(String movieName);
Map<String, List<Screen>> getMovieNameVsScreens();
}
class ​BookMyShow ​implements ​ShowMaker{
​@Override
​public ​Set<String> getAllScreenLocation() {​//do not write more than one line of code

​return ​----------------------------------------------------------------------------------------------------------------------------- ;
}

​@Override
​public ​Set<String> getAllScreenMovieName() {​//do not write more than one line of code

​return ​----------------------------------------------------------------------------------------------------------------------------- ;
}

​@Override
​public ​List<Screen> getScreensByLocation(String location) {​//do not write more than one line of code

​return ​----------------------------------------------------------------------------------------------------------------------------- ;
}

​@Override
​public ​List<Screen> getScreensByMovieName(String movieName) {​//do not write more than one line of code

​return ​----------------------------------------------------------------------------------------------------------------------------- ;
}

​@Override
​public ​Map<String, List<Screen>> getMovieNameVsScreens() {​//do not write more than one line of code

​return -​----------------------------------------------------------------------------------------------------------------------------- ;
}
}

class ​MovieWatcherTest {
​public static void ​main(String[] args) {
ShowMaker showMaker = ​new ​BookMyShow();
System.​out​.println(showMaker.getAllScreenLocation());
​//output-[mantri-square, garuda-mall, forum-mall, orion-mall]

​System.​out​.println(showMaker.getAllScreenMovieName());
​//output-[the lion king, war, dream girl, joker, Mission Mangal, the little lion king]

​System.​out​.println(showMaker.getScreensByLocation(​"forum-mall"​));
​//output-[Screen{location='forum-mall', name='imax-screen-1', movieName='war', language='hindi'},
// Screen{location='forum-mall', name='pvr-screen-4', movieName='dream girl', language='hindi'},
// Screen{location='forum-mall', name='imax-screen-3', movieName='dream girl', language='hindi'}]

​System.​out​.println(showMaker.getScreensByMovieName(​"war"​));
​//output-[Screen{location='forum-mall', name='imax-screen-1', movieName='war', language='hindi'},
// Screen{location='central-mall', name='pvr-screen-1', movieName='war', language='hindi'}]

​System.​out​.println(showMaker.getMovieNameVsScreens());
​//output-{the lion king=[Screen{location='mantri-square', name='pvr-screen-1', movieName='the lion king', language='english'}],
// dream girl=[Screen{location='forum-mall', name='pvr-screen-4', movieName='dream girl', language='hindi'},
// Screen{location='forum-mall', name='imax-screen-3', movieName='dream girl', language='hindi'}],
// war=[Screen{location='forum-mall', name='imax-screen-1', movieName='war', language='hindi'},
// Screen{location='central-mall', name='pvr-screen-1', movieName='war', language='hindi'}],
// joker=[Screen{location='mantri-square', name='pvr-screen-2', movieName='joker', language='english'}],
// Mission Mangal=[Screen{location='garuda-mall', name='imax-screen-1', movieName='Mission Mangal', language='hindi'}],
// the little lion king=[Screen{location='orion-mall', name='pvr-screen-3', movieName='the little lion king', language='english'}]}
}​
}

You might also like