This media is not supported in your browser
VIEW IN TELEGRAM
Share our channel screenshot in large groups ✅✅✅✅✅
For coding answers 🏃🏃🏃🏃
For coding answers 🏃🏃🏃🏃
👍2
import java.util.*;
import java.util.stream.Collectors;
public class AnalyticsSystem {
private final AnalyticsStore analyticsStore;
private final int K;
private Queue<ActionEnum> actionsQueue;
private Map<ActionEnum, Integer> actionCount;
public AnalyticsSystem(AnalyticsStore analyticsStore, int K) {
this.analyticsStore = analyticsStore;
this.K = K;
this.actionsQueue = new LinkedList<>();
this.actionCount = new HashMap<>();
}
public void registerAction(ActionEnum action) {
actionsQueue.add(action);
actionCount.put(action, actionCount.getOrDefault(action, 0) + 1);
if (actionsQueue.size() == K) {
analyticsStore.storeActions(new LinkedList<>(actionsQueue));
actionsQueue.clear();
}
}
public int getNumberOfActionsRegisteredButNotSentToAnalyticsStore() {
return actionsQueue.size();
}
public int getTotalNumberOfLoggedActions() {
return actionCount.values().stream().mapToInt(Integer::intValue).sum();
}
public List<ActionEnum> getMostFrequentlyUsedActions() {
List<ActionEnum> mostFrequentActions = actionCount.entrySet().stream()
.sorted(Map.Entry.comparingByKey(Comparator.comparing(Enum::name)))
.sorted(Map.Entry.<ActionEnum, Integer>comparingByValue().reversed())
.map(Map.Entry::getKey)
.collect(Collectors.toList());
return mostFrequentActions;
}
}
import java.util.stream.Collectors;
public class AnalyticsSystem {
private final AnalyticsStore analyticsStore;
private final int K;
private Queue<ActionEnum> actionsQueue;
private Map<ActionEnum, Integer> actionCount;
public AnalyticsSystem(AnalyticsStore analyticsStore, int K) {
this.analyticsStore = analyticsStore;
this.K = K;
this.actionsQueue = new LinkedList<>();
this.actionCount = new HashMap<>();
}
public void registerAction(ActionEnum action) {
actionsQueue.add(action);
actionCount.put(action, actionCount.getOrDefault(action, 0) + 1);
if (actionsQueue.size() == K) {
analyticsStore.storeActions(new LinkedList<>(actionsQueue));
actionsQueue.clear();
}
}
public int getNumberOfActionsRegisteredButNotSentToAnalyticsStore() {
return actionsQueue.size();
}
public int getTotalNumberOfLoggedActions() {
return actionCount.values().stream().mapToInt(Integer::intValue).sum();
}
public List<ActionEnum> getMostFrequentlyUsedActions() {
List<ActionEnum> mostFrequentActions = actionCount.entrySet().stream()
.sorted(Map.Entry.comparingByKey(Comparator.comparing(Enum::name)))
.sorted(Map.Entry.<ActionEnum, Integer>comparingByValue().reversed())
.map(Map.Entry::getKey)
.collect(Collectors.toList());
return mostFrequentActions;
}
}
👍1🔥1
This media is not supported in your browser
VIEW IN TELEGRAM
Nobody sharing our grp😢🥹
❤1
All MCQ Answers sent💯💯
👍1
Share our channel screenshot in large groups ✅✅✅✅✅
For coding answers & Sql 🏃🏃🏃🏃
For coding answers & Sql 🏃🏃🏃🏃
👍2
import java.util.Scanner;
public class BankOperations implements IBankAccountOperation {
private int initialBalance = 0;
public static void main(String[] args) {
BankOperations bankOperations = new BankOperations();
bankOperations.showBalance();
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the amount to deposit: ");
int depositAmount = scanner.nextInt();
bankOperations.depositFunds(depositAmount);
System.out.print("Enter the amount to withdraw: ");
int withdrawAmount = scanner.nextInt();
bankOperations.withdrawFunds(withdrawAmount);
scanner.close();
}
@Override
public void showBalance() {
System.out.println("Your current balance is: " + initialBalance);
}
@Override
public void depositFunds(int amount) {
initialBalance += amount;
System.out.println("You have deposited " + amount + ". Your current balance is: " + initialBalance);
}
@Override
public void withdrawFunds(int amount) {
if (amount > initialBalance) {
System.out.println("Insufficient balance. Withdrawal canceled.");
} else {
initialBalance -= amount;
System.out.println("You have withdrawn " + amount + ". Your current balance is: " + initialBalance);
}
}
}
public class BankOperations implements IBankAccountOperation {
private int initialBalance = 0;
public static void main(String[] args) {
BankOperations bankOperations = new BankOperations();
bankOperations.showBalance();
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the amount to deposit: ");
int depositAmount = scanner.nextInt();
bankOperations.depositFunds(depositAmount);
System.out.print("Enter the amount to withdraw: ");
int withdrawAmount = scanner.nextInt();
bankOperations.withdrawFunds(withdrawAmount);
scanner.close();
}
@Override
public void showBalance() {
System.out.println("Your current balance is: " + initialBalance);
}
@Override
public void depositFunds(int amount) {
initialBalance += amount;
System.out.println("You have deposited " + amount + ". Your current balance is: " + initialBalance);
}
@Override
public void withdrawFunds(int amount) {
if (amount > initialBalance) {
System.out.println("Insufficient balance. Withdrawal canceled.");
} else {
initialBalance -= amount;
System.out.println("You have withdrawn " + amount + ". Your current balance is: " + initialBalance);
}
}
}
❤1👍1🔥1