You are on page 1of 4

08.

15 11:50 AM
Mock assessment
C# challenge:

using System;
using System.Collections.Generic;
class Investment {
public string InvestmentType { get; set; }
public int InvestmentRisk { get; set; }
public double InvestmentReturns { get; set; } public double InvestmentInstallment {
get; set; } public Investment(string investmentType, int investmentRisk, double
investmentReturns, double investmentInstallment) {
InvestmentType = investmentType; InvestmentRisk = investmentRisk; InvestmentReturns
= investmentReturns; InvestmentInstallment = investmentInstallment;
}
}
class Portfolio {
public List InvestmentOptions { get; set; }
public Portfolio(List investmentOptions) { InvestmentOptions = investmentOptions; }
public List RecommendInvestment(double annualIncome, int tolerableRisk, double
expectedReturns) {
List recommendedInvestments = new List(); foreach (Investment investment in
InvestmentOptions) { if (investment.InvestmentInstallment = expectedReturns) {
recommendedInvestments.Add(investment);
}
}
return recommendedInvestments.Count > 0 ? recommendedInvestments : null;
}
}
class Program {
static void Main(string[] args) {
int numberOfInvestments = int.Parse(Console.ReadLine());
List investmentList = new List();
for (int i = 0; i < numberOfInvestments; i++) {
string investmentType = Console.ReadLine();
int investmentRisk = int.Parse(Console.ReadLine());
double investmentReturns = double.Parse(Console.ReadLine());
double investmentInstallment = double.Parse(Console.ReadLine());
Investment investment = new Investment(investmentType,
investmentRisk, investmentReturns, investmentInstallment);
investmentList.Add(investment);
}
Portfolio portfolio = new Portfolio(investmentList);
double annualIncome = double.Parse(Console.ReadLine());
int tolerableRisk = int.Parse(Console.ReadLine());
double expectedReturns = double.Parse(Console.ReadLine());
List recommendedInvestments = portfolio.RecommendInvestment(annualIncome,
tolerableRisk, expectedReturns);
if (recommendedInvestments == null) {
Console.WriteLine("No investment plans are available.");
} else {
foreach (Investment investment in recommendedInvestments) {
Console.WriteLine($"Investment:{
investment.InvestmentType}"); Console.WriteLine($"Investment Returns:
{investment.InvestmentReturns:F2}");
}
}
}
}
Java challenge:

import java.util.Scanner;
class PackersAndMovers {
private int invoiceNo;
private String fromCity;
private String toCity;
private String orderDate;
private String deliveryDate;
private double price;
public PackersAndMovers(int invoiceNo, String fromCity, String toCity, String
orderDate, String deliveryDate, double price) {
this.invoiceNo = invoiceNo;
this.fromCity = fromCity;
this.toCity = toCity;
this.orderDate = orderDate;
this.deliveryDate = deliveryDate;
this.price = price;
}
public int getInvoiceNo() {
return invoiceNo;
}
public String getFromCity() {
return fromCity;
} public String getToCity() {
return toCity;
} public String getOrderDate() {
return orderDate;
} public String getDeliveryDate() {
return deliveryDate;
}
public double getPrice() {
return price;
}
} public class MyClass {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in); PackersAndMovers[] orders = new
PackersAndMovers[4];
for (int i = 0; i < 4; i++) {
int invoiceNo = scanner.nextInt(); scanner.nextLine();
character String fromCity = scanner.nextLine(); String toCity = scanner.nextLine();
String orderDate = scanner.nextLine();
String deliveryDate = scanner.nextLine(); double price = scanner.nextDouble();
scanner.nextLine();
character orders[i] = new PackersAndMovers(invoiceNo, fromCity, toCity, orderDate,
deliveryDate, price);
}
String givenCity = scanner.nextLine(); scanner.close();
int count = countOrdersDeliveredInAWeek(orders, givenCity);
if (count > 0) {
System.out.println(count);
} else {
System.out.println("No PackersAndMovers delivered within a week from the given
city.");
}
}
public static int countOrdersDeliveredInAWeek(PackersAndMovers[] orders, String
givenCity) {
int count = 0;
for (PackersAndMovers order : orders) {
if (order.getFromCity().equalsIgnoreCase(givenCity)) {
int orderDay = Integer.parseInt(order.getOrderDate().split("-")[0]);
int deliveryDay = Integer.parseInt(order.getDeliveryDate().split("-")[0]);
if (deliveryDay - orderDay <= 7) {
count++;
}
}
}
return count;
}
}

Python Challenge:

class Player: def __init__(self, playerName, team, playerType, isCaptain, runs,


wickets): self.playerName = playerName
self.team = team
self.playerType = playerType
self.isCaptain = isCaptain
self.runs = runs
self.wickets = wickets
def calculatePoints(self):
points = self.runs + self.wickets * 10
if self.isCaptain.lower() == "true":
points *= 2
return points
class Tournament:
def __init__(self, playerList):
self.playerList = playerList
def getPlayerList(self, playerType, points):
result = []
for player in self.playerList:
if player.playerType.lower() == playerType.lower() and player.calculatePoints() >
points: result.append(player)
return result if result else None
def findPlayerPoints(self, team, points):
result = {}
for player in self.playerList:
if player.team.lower() == team.lower() and player.calculatePoints() > points:
result[player.playerName] = player.calculatePoints()
return result if result else None
if __name__ == "__main__":
numPlayers = int(input())
playerList = []
for _ in range(numPlayers):
playerName = input()
team = input()
playerType = input()
isCaptain = input()
runs = int(input())
wickets = int(input())
player = Player(playerName, team, playerType, isCaptain, runs, wickets)
playerList.append(player)
tournament = Tournament(playerList) playerType = input()
points = int(input())
selectedPlayers = tournament.getPlayerList(playerType, points)
if selectedPlayers:
for player in selectedPlayers: print(player.playerName)
print(player.runs)
print(player.wickets)
else:
print("Player Not Found.")
team = input()
points = int(input())
playerPoints = tournament.findPlayerPoints(team, points)
if playerPoints:
for playerName, points in playerPoints.items(): print(playerName, points)
else:
print("Player Not Found.")

You might also like