Java Proctored Assessment Programming Solution 17th December
Java Proctored Assessment Programming Solution 17th December
Question 1
Solution:
import java.util.Scanner;
public class Solution4 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
double k = sc.nextInt();
k = Math.sqrt(k);
if((int)k == k)
System.out.println("TRUE");
else
System.out.println("FALSE");
}
}
Question 2
Input
Alex
101
Java
15
Albert
102
Unix
20
Alferd
103
Testing
13
Alfa
104
Java
15
Almas
105
Java
29
Java // Given technology
Output
101
104
Solution:
import java.util.ArrayList;
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
// TODO Auto-generated method stub
int id ,exp;
String name,tech;
As[] ass = new As[5];
Scanner sc=new Scanner(System.in);
for(int i = 0;i<5;i++) {
System.out.println("id = ");
id = sc.nextInt();
System.out.println("name = ");
name = sc.next();
System.out.println("tech = ");
tech = sc.next();
System.out.println("exp = ");
exp = sc.nextInt();
ass[i] = new As(id, name, tech, exp);
}
String techa;
System.out.println("Enter tech = ");
techa = sc.next();
ArrayList<As> Os = getTech(ass,techa);
for(int i=0;i<Os.size();i++)
System.out.println(Os.get(i).getId()+" "+Os.get(i).getName()+"
"+Os.get(i).getTech()+" "+Os.get(i).getExp());
}
public static ArrayList<As> getTech(As[] d, String th) {
ArrayList<As> bs = new ArrayList<As>();
for(int i=0;i<d.length;i++) {
if(d[i].getTech().equals(th) && d[i].getExp()%5==0)
bs.add(d[i]);
}
return bs;
}
}
class As{
private int id;
private String name;
private String tech;
private int exp;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getTech() {
return tech;
}
public void setTech(String tech) {
this.tech = tech;
}
public int getExp() {
return exp;
}
public void setExp(int exp) {
this.exp = exp;
}
public As(int id, String name, String tech, int exp) {
this.id = id;
this.name = name;
this.tech = tech;
this.exp = exp;
}
}
Java Proctored Assessment Programming
solution 28th December
Question 1.
Solution:
import java.util.Scanner;
public class Solution {
public static void main(String [] args) {
Scanner in = new Scanner(System.in);
int space_count=0,char_count=0;
String str=in.nextLine();
for(int i=0;i<str.length();i++) {
if(str.charAt(i) == ' ') {
space_count++;
}
else {
char_count++;
}
}
System.out.println("No of Spaces : "+space_count+" and
characters :
"+char_count);
in.close();
}
}
Question 2.
input :
aaa
Arka
Action
250000000
bbbb
GeethaArts
Comedy
25000000
ccc
Marvel
Art
2000000
ddd
Mythri
Action
300000000
Action
Output:
High Budget Movie
High Budget Movie
Solution:
import java.util.Scanner;
class Movie {
private String movieName;
private String company;
private String genre;
private int budget;
public String getMovieName() {
return movieName;
}
public void setMovieName(String movieName) {
this.movieName = movieName;
}
public String getCompany() {
return company;
}
public void setCompany(String company) {
this.company = company;
}
public String getGenre() {
return genre;
}
public void setGenre(String genre) {
this.genre = genre;
}
public int getBudget() {
return budget;
}
public void setBudget(int budget) {
this.budget = budget;
}
Movie (String movieName, String company, String genre, int
budget) {
this.movieName = movieName;
this.company = company;
this.genre = genre;
this.budget = budget;
}
}
public class Solution {
public static void getMovieByGenre(Movie[] obj,String key) {
for(int i =0;i<4;i++) {
if(obj[i].getGenre().equals(key) && obj[i].getBudget() >
80000000){
System.out.println("High Budget Movie");
}
else if(obj[i].getGenre().equals(key) && obj[i].getBudget() <
80000000) {
System.out.println("Low Budget Movie");
}
}
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
Movie[] arr = new Movie[4];
for(int i =0;i<4;i++) {
String name=in.nextLine();
String company=in.nextLine();
String genre=in.nextLine();
int budget=in.nextInt();
in.nextLine();
arr[i]=new Movie(name,company,genre,budget);
}
String search =in.nextLine();
getMovieByGenre(arr,search);
in.close();
}
}
Java Proctored Assessment Programming
solution 15th January
Question 1.
input: Matrix
output : Mti
Solution:
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
for (int i = 0; i < str.length(); i+=2) {
System.out.print(str.charAt(i));
}
sc.close();
}
}
Output:
Example 1:
Matrix
Mti
Example 2:
Hi how are you?
H o r o?
Question 2.
input:
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
output:
4
3
1
2
Solution:
import java.util.Scanner;
public class SimCard {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Sim[] sim = new Sim[4];
for (int i = 0; i < sim.length; i++) {
int simId = sc.nextInt();sc.nextLine();
String name = sc.nextLine();
double balance = sc.nextDouble();sc.nextLine();
double ratePersecond = sc.nextDouble();sc.nextLine();
String circle = sc.nextLine();
sim[i] = new Sim(simId, name, balance, ratePersecond,
circle);
}
String circle1 = sc.nextLine();
double ratePerSecond1 = sc.nextDouble();
Sim[] result = find(sim, circle1, ratePerSecond1);
for (int i = 0; i < result.length; i++) {
System.out.println(result[i].getSimId());
}
sc.close();
}
public static Sim[] find(Sim[] sim, String circle1, double
ratePerSecond1) {
Sim[] temp;
int j = 0;
for (int i = 0; i < sim.length; i++) {
if (sim[i].getCircle().equals(circle1) &&
sim[i].getRatePersecond() < ratePerSecond1) {
j++;
}
}
temp = new Sim[j];
j=0;
for (int i = 0; i < sim.length; 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) {
this.simId = simId;
this.name = name;
this.balance = balance;
this.ratePersecond = ratePersecond;
this.circle = circle;
}
public int getSimId() {
return simId;
}
public void setSimId(int simId) {
this.simId = simId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getBalance() {
return balance;
}
public void setBalance(double balance) {
this.balance = balance;
}
public double getRatePersecond() {
return ratePersecond;
}
public void setRatePersecond(double ratePersecond) {
this.ratePersecond = ratePersecond;
}
public String getCircle() {
return circle;
}
public void setCircle(String circle) {
this.circle = circle;
}
}
________________________________________________
Question 1.
Example:
Input:
Hi tcs
Output:
is
Solution:
import java.util.Scanner;
public class LastCharOfWord {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
String[] words = str.split(" ");
for (int i = 0; i < words.length; i++) {
System.out.print((words[i].charAt(words[i].length()-1)));
}
sc.close();
}
}
Example 1:
Input: welcome home buddY
Output: eeY
Example 2:
Input: Hi how are you ?
Output: iweu?
Question 2.
Take a class name inventory and its 4 object into array and
implement a method replenish where it will take array objects
and a limit as a parameter and it will display the id along with
fillings where filling if greater than 75 it will be critical filling
and if it is between 74 and 50 then moderate filling else non-
critical filling
Input:
1
100
50
50
2
200
60
40
3
150
35
45
4
80
45
40
45
Output:
2 Non-Critical Filling
3 Non-Critical Filling
4 Non-Critical Filling
Solution:
import java.util.Scanner;
public class InventorySolution {
public static void main(String[] args) {
// TODO Auto-generated method stub
Inventory[] in = new Inventory[4];
Scanner sc = new Scanner(System.in);
for (int i = 0; i < in.length; i++) {
String a = sc.nextLine();
int b = sc.nextInt();
sc.nextLine();
int c = sc.nextInt();
sc.nextLine();
int d = sc.nextInt();
sc.nextLine();
in[i] = new Inventory(a, b, c, d);
}
int limit = sc.nextInt();
Inventory[] result = replenish(limit, in);
for (int i = 0; i < result.length; i++) {
if (result[i].getThreshold() >= 75) {
System.out.println(result[i].getInventoryId() + "
Critical Filling");
}
else if (result[i].getThreshold() >= 50 &&
result[i].getThreshold() <= 74) {
System.out.println(result[i].getInventoryId() + "
Moderate Filling");
}
else {
System.out.println(result[i].getInventoryId() + "
Non-Critical Filling");
}
}
sc.close();
}
public static Inventory[] replenish(int limit, Inventory[] in) {
// TODO Auto-generated method stub
Inventory[] temp;
int j = 0;
for (int i = 0; i < in.length; i++) {
if (in[i].getThreshold() <= limit) {
j++;
}
}
temp = new Inventory[j];
j = 0;
for (int i = 0; i < in.length; i++) {
if (in[i].getThreshold() <= limit) {
temp[j++] = in[i];
}
}
return temp;
}
}
class Inventory {
String inventoryId;
int maximumQuantity;
int currentQuantity;
int threshold;
public Inventory(String inventoryId, int maximumQuantity, int
currentQuantity, int threshold) {
this.inventoryId = inventoryId;
this.maximumQuantity = maximumQuantity;
this.currentQuantity = currentQuantity;
this.threshold = threshold;
}
public String getInventoryId() {
return inventoryId;
}
public void setInventoryId(String inventoryId) {
this.inventoryId = inventoryId;
}
public int getMaximumQuantity() {
return maximumQuantity;
}
public void setMaximumQuantity(int maximumQuantity) {
this.maximumQuantity = maximumQuantity;
}
public int getCurrentQuantity() {
return currentQuantity;
}
public void setCurrentQuantity(int currentQuantity) {
this.currentQuantity = currentQuantity;
}
public int getThreshold() {
return threshold;
}
public void setThreshold(int threshold) {
this.threshold = threshold;
}
}
Question 1.
Input:
Hello World!
Output:
Vowels count - 3
Consonants count - 7
Solution:
import java.util.*;
import java.lang.*;
public class Main
{
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
String str = s.nextLine();
str = str.toLowerCase();
int vowelCount = 0, consonantCount = 0;
for(int i=0;i<str.length();i++){
if(str.charAt(i)>='a' && str.charAt(i)<='z'){
if(str.charAt(i)=='a' || str.charAt(i)=='e' ||
str.charAt(i)=='i' || str.charAt(i)=='o' || str.charAt(i)=='u')
vowelCount += 1;
else
consonantCount += 1;
}
}
System.out.println("Vowels count - "+vowelCount);
System.out.println("Consonant Count
- "+consonantCount);
}
}
Question 2.
Input:
100
Sachin
5
150
13000
101
Sehwag
4
120
10000
103
Dhoni
7
110
7000
104
Kohli
15
57
4400
100
Output:
Grade A
Grade A
Grade B
Solution:
import java.util.Scanner;
public class feb10tcsxplore {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
Players []players=new Players[4];
for(int i=0;i<players.length;i++)
{
int playerid=sc.nextInt();sc.nextLine();
String playername=sc.nextLine();
int iccrank =sc.nextInt();sc.nextLine();
int matchplayed=sc.nextInt();sc.nextLine();
int runscored=sc.nextInt();sc.nextLine();
players[i]=new
Players(playerid,playername,iccrank,matchplayed,runscored)
;
}
int target=sc.nextInt();
double avgrunrate[]=findavgofruns(players,target);
for(int i=0;i<avgrunrate.length;i++)
{
if(avgrunrate[i]>=80&& avgrunrate[i]<=100)
System.out.println("Grade A");
else if(avgrunrate[i]>=50&& avgrunrate[i]<=79)
System.out.println("Grade B");
else
System.out.println("Grade C");
}
}
public static double[] findavgofruns(Players[] ob, int target) {
// TODO Auto-generated method stub
double temp[];
int j=0;
for(int i=0;i<ob.length;i++)
{
if(ob[i].getmatchplayed()>=target)
j++;
}
temp=new double[j];
j=0;
for(int i=0;i<ob.length;i++)
{
if(ob[i].getmatchplayed()>=target)
{
temp[i]=(double)
(ob[i].getrunscored()/ob[i].getmatchplayed());
}
}
return temp;
}
}
class Players
{
int id;
String name;
int iccrank;
int matchplayed;
int runscored;
public Players(int id,String name,int iccrank,int
matchplayed,int runscored)
{
this.id=id;
this.name=name;
this.iccrank=iccrank;
this.matchplayed=matchplayed;
this.runscored=runscored;
}
public int getid()
{
return id;
}
public String getname()
{
return name;
}
public int geticcrank()
{
return iccrank;
}
public int getmatchplayed()
{
return matchplayed;
}
public int getrunscored()
{
return runscored;
}
}
Java Proctored Assessment Programming
solution 13th February
Question 1.
input:
matrix
output:
a
Solution:
import java.lang.*;
import java.util.*;
import java.io.*;
import java.math.*;
public class Main
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String s=sc.nextLine();
s=s.toLowerCase();
int n=s.length();
int c=0;
char[] ch=s.toCharArray();
for(int i=0;i<n;i++)
{
if(s.charAt(i)=='a' || s.charAt(i)=='e' || s.charAt(i)=='i' ||
s.charAt(i)=='o' || s.charAt(i)=='u')
{
c++;
}
}
char[] c1=new char[c];
int k=0;
for(int i=0;i<n;i++)
{
if(s.charAt(i)=='a' || s.charAt(i)=='e' || s.charAt(i)=='i' ||
s.charAt(i)=='o' || s.charAt(i)=='u')
{
c1[k++]=ch[i];
}
}
Arrays.sort(c1);
System.out.println(c1[0]);
}
}
Question 2.
Input:
1
raju
130
1.32
mum
2
sachin
120
2.26
ahd
3
ram
200
2.54
kol
4
shubham
640
3.21
ahd
5
kalpesh
150
1.8
ahd
ahd
kol
Output:
Solution:
import java.util.Scanner;
public class SimSolution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Sim1[] sim = new Sim1[5];
for (int i = 0; i < sim.length; i++) {
int simId = sc.nextInt();
sc.nextLine();
String name = sc.nextLine();
double balance = sc.nextDouble();
double ratePersecond = sc.nextDouble();
sc.nextLine();
String circle = sc.nextLine();
sim[i] = new Sim1(simId, name, balance,
ratePersecond, circle);
}
String circle1 = sc.nextLine();
String circle2 = sc.nextLine();
Sim1[] result = transferCircle(sim, circle1, circle2);
for (int i = 0; i < result.length; i++) {
System.out.println(result[i].getSimId() + " " +
result[i].getName() + " " + result[i].getCircle() + " "
+ result[i].getRatePersecond());
}
sc.close();
}
public static Sim1[] transferCircle(Sim1[] sim, String
circle1, String circle2) {
Sim1[] temp;
int j = 0;
for (int i = 0; i < sim.length; i++) {
if (sim[i].getCircle().equals(circle1)) {
j++;
}
}
temp = new Sim1[j];
j = 0;
for (int i = 0; i < sim.length; i++) {
if (sim[i].getCircle().equals(circle1)) {
temp[j] = sim[i];
temp[j++].setCircle(circle2);
}
}
for (int i = 0; i < j - 1; i++) {
for (int k = 0; k < j - 1; k++) {
if (temp[k].getRatePersecond() < temp[k +
1].getRatePersecond()) {
Sim1 a = temp[k];
temp[k] = temp[k + 1];
temp[k + 1] = a;
}
}
}
return temp;
}
}
class Sim1 {
private int simId;
private String name;
private double balance;
private double ratePersecond;
private String circle;
public Sim1(int simId, String name, double balance, double
ratePersecond, String circle) {
this.simId = simId;
this.name = name;
this.balance = balance;
this.ratePersecond = ratePersecond;
this.circle = circle;
}
public int getSimId() {
return simId;
}
public void setSimId(int simId) {
this.simId = simId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getBalance() {
return balance;
}
public void setBalance(double balance) {
this.balance = balance;
}
public double getRatePersecond() {
return ratePersecond;
}
public void setRatePersecond(double ratePersecond) {
this.ratePersecond = ratePersecond;
}
public String getCircle() {
return circle;
}
public void setCircle(String circle) {
this.circle = circle;
}
}
________________________________________________
Question 1.
INPUT
12345
OUTPUT
Solution:
import java.util.Scanner;
public class Solution1000 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
StringBuffer sb = new
StringBuffer(sc.nextLine());
System.out.println("Reverse of the number is
"+sb.reverse());
}
}
Question 2.
INPUT :
dolo650
batch1
fever
100
dolo990
batch2
headache
101
paracetemol
batch3
bodypains
102
almox500
batch4
fever
103
fever
OUTPUT :
100
103
Solution
import java.util.Arrays;
import java.util.Scanner;
public class Solution{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Medicine[] m = new Medicine[4];
for(int i =0;i<m.length;i++) {
String a = sc.nextLine();
String b = sc.nextLine();
String c = sc.nextLine();
int d = sc.nextInt();sc.nextLine();
m[i] = new Medicine(a,b,c,d);
}
String e = sc.nextLine();
Integer[] f = sortAccordingtoPrices(m,e);
for(Integer g : f) {
System.out.println(g);
}
}
public static Integer[] sortAccordingtoPrices(Medicine[] m,
String e) {
int count =0 ;
for(int i=0;i<m.length;i++) {
if(m[i].getDisease().equals(e)) {
count++;
}
}
Integer[] j = new Integer[count];
int k = 0;
for(int i=0;i<m.length;i++) {
if(m[i].getDisease().equalsIgnoreCase(e)) {
j[k++] = m[i].getPrice();
}
}
Arrays.sort(j);
return j;
}
}
class Medicine{
private String MedicineName;
private String batch;
private String disease;
private int price;
public String getMedicineName() {
return MedicineName;
}
public void setMedicineName(String medicineName) {
MedicineName = medicineName;
}
public String getBatch() {
return batch;
}
public void setBatch(String batch) {
this.batch = batch;
}
public String getDisease() {
return disease;
}
public void setDisease(String disease) {
this.disease = disease;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public Medicine(String medicineName, String batch, String
disease, int price) {
this.MedicineName = medicineName;
this.batch = batch;
this.disease = disease;
this.price = price;
}
}