Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, Can someone help me explain the purpose of EVERY LINE in this code? And the time complexity and algorithm, and possibly the pseudocode of

Hello, Can someone help me explain the purpose of EVERY LINE in this code? And the time complexity and algorithm, and possibly the pseudocode of it? Thanks! Will give thumbs up

image text in transcribed

import java.util.*;

import java.io.*;

public class BankQ{

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

int sum = 0;

while(scanner.hasNextLine()){

String input = scanner.nextLine();

String[] separate = input.split(" ");

int N = Integer.parseInt(separate[0]);

int T = Integer.parseInt(separate[1]);

int amount;

int timeLeft;

Customer[] customer = new Customer[N];

for(int i = 0; i

input = scanner.nextLine();

separate = input.split(" ");

amount = Integer.parseInt(separate[0]);

timeLeft = Integer.parseInt(separate[1]);

customer[i] = new Customer(amount, timeLeft);

}

Arrays.sort(customer);

boolean[] taken = new boolean[47];

for( Customer cust: customer) {

int closeTime = cust.timeLeft;

while (closeTime >= 0) {

if(!taken[closeTime]){

sum += cust.amount;

taken[closeTime] = true;

break;

}

closeTime--;

}

}

System.out.println(sum);

}

scanner.close();

}

}

class Customer implements Comparable{

int amount, timeLeft;

public Customer( int amount, int timeLeft){

this.amount = amount;

this.timeLeft = timeLeft;

}

@Override public int compareTo(Customer customer){

return customer.amount - amount;

}

}

AND here is the prompt to the code if it helps.

image text in transcribed

1 import java.util.; 2 import java.io.*; 4 public class BankQ 5 public static void main(String[] args) f Scanner scannernew Scanner (System.in); int sum e 8 while(scanner.hasNextLine()) string input = scanner.nextLine(); string[] separate nput. Split(" "); int N = Integer.parseInt(separate [e]); int T- Integer.parseInt (separate[1]); 1e 12 13 int amount; int timeLeft; Customer[] customer = new Customer[n]; 15 16 17 18 19 20 21 for(int i-e; it int amount, timeLeft; 56 57 58 59 60 61 62 63 64 65 public Customer( int amount, int timeLeft)( this.amount amount; this.timeLeft timeLeft; @Override public int compareTo (Customer customer)f return customer.amount amount; Bank Queue Oliver is a manager of a bank near KTH and wants to close soon. There are many people standing in the queue wanting to put cash into their accounts after they heard that the bank increased the interest rates by 42% (from 0.01% per year to 0.0142% per year). However, there are too many people and only one counter is open which can serve one person per minute. Greedy as Oliver is, he would like to select some people in the queue, so that the total amount of cash stored by these people is as big as possible and that money then can work for the bank overnight. There is a problem, though. Some people don't have the time to wait until the bank closes because they have to run somewhere else, so they have to be served before a certain time, after which they just leave. Oliver also turned off the infrared door sensor outside the bank, so that no more people can enter, because it's already too crowded in the hall Task Help Oliver calculate how much cash he can get from the people currently standing in the queue before the bank closes by serving at most one person per minute Input The first line of input contains two integers N (1SN<><>

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional SQL Server 2000 Database Design

Authors: Louis Davidson

1st Edition

1861004761, 978-1861004765

More Books

Students also viewed these Databases questions