Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
SRV college wants to recognize the department which has succeeded in getting the maximum number of placements for this academic year. The departments that have participated in the recruitment drive are CSE,ECE, MECH. Help the college find the department getting maximum placements. Check for all the possible output given in the sample snapshot

Note : If any input is negative, the output should be "Input is Invalid".  If all department has equal number of placements, the output should be "None of the department has got the highest placement".

Sample Input 1:

Enter the no of students placed in CSE:90
Enter the no of students placed in ECE:45
Enter the no of students placed in MECH:70
Sample Output 1:
Highest placement
CSE

Sample Input 2:
Enter the no of students placed in CSE:55
Enter the no of students placed in ECE:85
Enter the no of students placed in MECH:85
Sample Output 2:
Highest placement
ECE
MECH

Sample Input 3:
Enter the no of students placed in CSE:0
Enter the no of students placed in ECE:0
Enter the no of students placed in MECH:0
Sample Output 3:
None of the department has got the highest placement


Sample Input 4:
Enter the no of students placed in CSE:10
Enter the no of students placed in ECE:-50
Enter the no of students placed in MECH:40
Sample Output 3:
Input is Invalid 


What I have tried:

import java.util.*;
class Placement{
	public static void main(String args[]){
		String a="CSE";
		String b="ECE";
		String c="MECH";
		int p,q,r;
		Scanner obj=new Scanner(System.in);
		System.out.print("Enter the no of students placed in CSE:");
		p=obj.nextInt();
		System.out.print("Enter the no of students placed in ECE:");
		q=obj.nextInt();
		System.out.print("Enter the no of students placed in MECH:");
		r=obj.nextInt();
		if(p<0 || q<0 || r<0){
			System.out.println("Input is Invalid");
		}
		else if(p==q && q==r){
			System.out.println("None of the department has got the highest placement");
		}
		else if(p==q){
		    System.out.println("Highest placement");
			System.out.println(a);
			System.out.println(b);
			
		}
		else if(q==r){
		    System.out.println("Highest placement");
			System.out.println(b);
			System.out.println(c);
			
		}
		else if(r==p){
		    System.out.println("Highest placement");
			System.out.println(a);
			System.out.println(c);
			
		}
		else if(p > q && p > r)
        {
            System.out.println("Highest placement");
			System.out.println(a);
        }
        else if(q > r && q>p)
        {
            System.out.println("Highest placement");
			System.out.println(b);
        }
        else if(r>p && r>q)
        {
            System.out.println("Highest placement");
			System.out.println(c);
        }
 
    }
		
}


I have written this code for the question but one hidden test case is not passing.It's showing "Check given condition". I'm getting 85.71 out of 100.
Posted
Updated 2-Feb-21 0:39am
Comments
Richard MacCutchan 2-Feb-21 5:45am    
It's showing "Check given condition".
What is showing it, where is it showing?
LearningGeek 2-Feb-21 6:08am    
I'm using an online compiler
It is showing the error in evaluation results
failed tests:
Test 5: Check given condition
7 tests run / 6 tests passed
CHill60 2-Feb-21 6:25am    
You have only shown us 4 tests - where did the other 3 come from?
And as that error is being generated by an online compiler (and presumably a test manager too) you also need to tell us which one.
I'm using the Online Java8 Compiler from CodingGround and all your given examples return the expected results.
LearningGeek 2-Feb-21 6:09am    
Is there any way to improve the code so that all test cases pass?

1 solution

Test it yourself.
It's not complicated: put that code in a method that accepts three parameters p, q, and r, and add code to print the parameters to it.

Then set up a set of nested loops to check it:
for (int i = 0; i < 3; i++)
    {
    for (int j = 0; j < 3; j++)
        {
        for (int k = 0; k < 3; k++)
            {
            check(i, j, k);
            }
        }
    }

Look at the outputs, and see which set is failing a test.
Hint: look at values where p is greater than both q and r, which are identical.
 
Share this answer
 
v2
Comments
LearningGeek 2-Feb-21 7:10am    
Thank you so much for the hint. It worked.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900