info@meritcampus.com    +91-85006-22255
...

Write a program to find the time slots the owner of an auditorium should choose such that he gets maximum revenue. The time slots in which multiple companies are interested are given. The start time, end time and the amount they are ready to pay are given. If two combinations give same amount, then the owner should choose the option where the auditorium is used for less time.
NOTE: While returning the name of the company should be returned.

Input (List) Output (List)
{[8:30, 12:30, 3000, Dell], [12:30, 1:30, 10000, Oracle], [1:30, 4:30, 6000, Cerone]} {[Dell, Oracle, Cerone]}
{[6:30, 12:30, 4000, Dell], [11:30, 12:30, 5000, Oracle], [12:30, 12:40, 2000, Cerone], [12:35, 12:45, 2001, HCL]} {[Oracle, HCL]}
{[6:29, 12:01, 2000, Dell], [06:30, 12:02, 1050, Oracle], [12:01, 12:40, 600, Cerone], [12:35, 12:45, 3000, HCL]} {[Dell, HCL]}
{[6:30, 12:01, 4000, Dell], [06:30, 10:30, 4000, Oracle], [12:01, 12:40, 6000, Cerone], [12:40, 12:45, 3000, HCL]} {[Oracle, Cerone, HCL]}

``` class FindBestSlots {    public static void main(String s[])    {        List input = new ArrayList();        input.add(new Slot("09:00", "09:30", 2000, "Dell"));        input.add(new Slot("09:30", "10:45", 1050, "Oracle"));        input.add(new Slot("10:44", "13:40", 700, "Cerone"));        input.add(new Slot("14:10", "14:50", 3000, "HCL"));        System.out.println("The best slots are : " + findBestSlots(input));    } public static List<String> findBestSlots(List<Slot> input) { //Write code here find the best slots in order to maximise the revenue } //Use this for writing additional methods if required } class Slot { double amount; Date start; Date end; String name; public String getName() { return name; } public double getAmount() { return amount; } public Date getStart() { return start; } public Date getEnd() { return end; } public Slot(String startTime, String endTime, double amount, String name) { try { DateFormat f = new SimpleDateFormat("HH:mm"); start = f.parse(startTime); end = f.parse(endTime); } catch (Exception e) { } this.amount = amount; this.name = name; } @Override public boolean equals(Object obj) { return name.equals(((Slot) obj).name); } } ```

Topic: Java Date Class

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.