0% found this document useful (0 votes)
116 views4 pages

Java Solutions for TCS Assessment

The document contains code for two Java programs. The first program takes a string as input and prints every other character. The second program defines a SimCard class with attributes like ID, name, balance etc. and reads input to create SimCard objects, then finds and prints the IDs of objects matching a given circle and rate. It sorts the matching objects by balance before returning and printing the results.
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)
116 views4 pages

Java Solutions for TCS Assessment

The document contains code for two Java programs. The first program takes a string as input and prints every other character. The second program defines a SimCard class with attributes like ID, name, balance etc. and reads input to create SimCard objects, then finds and prints the IDs of objects matching a given circle and rate. It sorts the matching objects by balance before returning and printing the results.
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

TCS 15 January Proctored Assessment Java Solutions

(Email Id: abhishinde141@[Link])

Program 1:
import [Link];

public class Solution {

public static void main(String[] args) {


Scanner sc = new Scanner([Link]);
String str = [Link]();
for (int i = 0; i < [Link](); i+=2) {
[Link]([Link](i));
}
[Link]();
}

Output:
Example 1:
Matrix
Mti

Example 2:
Hi how are you?
H o r o?

Program 2:
import [Link];

public class SimCard {

public static void main(String[] args) {


Scanner sc = new Scanner([Link]);
Sim[] sim = new Sim[4];
for (int i = 0; i < [Link]; i++) {
int simId = [Link]();
[Link]();
String name = [Link]();
double balance = [Link]();
[Link]();
double ratePersecond = [Link]();
[Link]();
String circle = [Link]();
sim[i] = new Sim(simId, name, balance, ratePersecond,
circle);
}
String circle1 = [Link]();
double ratePerSecond1 = [Link]();
Sim[] result = find(sim, circle1, ratePerSecond1);
for (int i = 0; i < [Link]; i++) {
[Link](result[i].getSimId());
}
[Link]();

public static Sim[] find(Sim[] sim, String circle1, double


ratePerSecond1) {
Sim[] temp;
int j = 0;
for (int i = 0; i < [Link]; i++) {
if (sim[i].getCircle().equals(circle1) &&
sim[i].getRatePersecond() < ratePerSecond1) {
j++;
}
}
temp = new Sim[j];
j=0;
for (int i = 0; i < [Link]; i++) {
if (sim[i].getCircle().equals(circle1) &&
sim[i].getRatePersecond() < ratePerSecond1) {
temp[j++] = sim[i];
}
}
for (int i = 0; i < j - 1; i++) {
for (int k = 0; k < j - 1; k++) {
if (temp[k].getBalance() < temp[k +
1].getBalance()) {
Sim a = temp[k];
temp[k] = temp[k + 1];
temp[k + 1] = a;
}
}
}
return temp;
}

class Sim {
private int simId;
private String name;
private double balance;
private double ratePersecond;
private String circle;

public Sim(int simId, String name, double balance, double


ratePersecond, String circle) {
[Link] = simId;
[Link] = name;
[Link] = balance;
[Link] = ratePersecond;
[Link] = circle;
}

public int getSimId() {


return simId;
}

public void setSimId(int simId) {


[Link] = simId;
}

public String getName() {


return name;
}

public void setName(String name) {


[Link] = name;
}

public double getBalance() {


return balance;
}

public void setBalance(double balance) {


[Link] = balance;
}

public double getRatePersecond() {


return ratePersecond;
}

public void setRatePersecond(double ratePersecond) {


[Link] = ratePersecond;
}

public String getCircle() {


return circle;
}

public void setCircle(String circle) {


[Link] = circle;
}

Output:
1
jio
430
1.32
mumbai
2
idea
320
2.26
mumbai
3
airtel
500
2.54
mumbai
4
vodafone
640
3.21
mumbai
mumbai
3.4
4
3
1
2

You might also like