TCS NQT Previous Year Solve | Day 3 | Slot 1 (V) | Codewindow.in

Coding

Question 1:

FULLY AUTOMATIC VENDING MACHINE dispenses your cuppa on just the press of button. A vending machine can serve range of products as follows:

Coffee
1. Espresso Coffee
2. Cappuccino Coffee
3. Latte Coffee

Tea
1. Plain Tea
2. Assam Tea
3. Ginger Tea
4. Cardamom Tea
5. Masala Tea
6. Lemon Tea
7. Green Tea
8. Organic Darjeeling Tea

Soups
1. Hot and Sour Soup
2. Veg Corn Soup
3. Tomato Soup
4. Spicy Tomato Soup

Beverages
1. Hot Chocolate Drink
2. Badam Drink
3. Badam-Pista Drink

Write a program to take input for main menu & sub menu and display the name of sub menu selected in following format (enter the first letter to select main menu):
Welcome to CCD
Enjoy your <name of sub menu>

Example 1:

Input:
c
1

Output:
Welcome to CCD!
Enjoy your Espresso Coffee!

Example 2:

Input:
t
9

Output:
INVALID OPTION!

Solution: In Java

import java.util.*;
import java.lang.*;
import java.io.*;

class Question
{
	public static void main (String[] args) throws Exception
	{
		String[] c = {"Espresso Coffee", "Cappuccino Coffee", "Latte Coffee"};
		String[] t = {"Plain Tea", "Assam Tea", "Ginger Tea", "Cardamom Tea", "Masala Tea", "Lemon Tea", "Green Tea", "Organic Darjeeling Tea"};
		String[] s = {"Hot and Sour Soup", "Veg Corn Soup", "Tomato Soup", "Spicy Tomato Soup"};
		String[] b = {"Hot Chocolate Drink", "Badam Drink", "Badam-Pista Drink"};
		String str = "Welcome to CCD!\nEnjoy your ";
		Scanner sc = new Scanner(System.in);
		char ch = sc.next().charAt(0);
		int item = sc.nextInt();
		if(ch != 'C' &amp;&amp; ch != 'c' &amp;&amp; ch != 'T' &amp;&amp; ch != 't' &amp;&amp; ch != 'B' &amp;&amp; ch != 'b' &amp;&amp; ch != 'S' &amp;&amp; ch != 's')
		    System.out.println("INVALID OPTION!");
	    else if(ch == 'C' || ch == 'c') {
	        if(item  3)
	            System.out.println("INVALID OPTION!");
	        else {
	            System.out.println(str + c[item-1] + "!");
	        }
	    }
	    else if(ch == 'T' || ch == 't') {
	        if(item  8)
	            System.out.println("INVALID OPTION!");
	        else {
	            System.out.println(str + t[item-1] + "!");
	        }
	    }
	    else if(ch == 'S' || ch == 's') {
	        if(item  4)
	            System.out.println("INVALID OPTION!");
	        else {
	            System.out.println(str + s[item-1] + "!");
	        }
	    }
	    else if(ch == 'B' || ch == 'b') {
	        if(item  3)
	            System.out.println("INVALID OPTION!");
	        else {
	            System.out.println(str + b[item-1] + "!");
	        }
	    }
	}
}__

Question 2:

At an exam center, M number of students are allocated for one classroom as per the University Rules. The Examination staff has made sitting arrangements where the classroom contains N number of benches arranged in columns separated by a suitable distance occupying room space from the left to the right wall. Given, M = 10 , N=5

Students from class “TY” can sit one after the other from the 1st bench starting at the left wall in the order of their Roll Numbers. And students from class “SY” are allowed to sit beside the students from class ‘TY” in the order of their Roll Numbers one after the other. All students enter the classroom in a random order as input in String Array Students[ ]. Few students may remain absent. Assume the Roll Numbers are in continuous range with no drop, and Class Name(“TY”,”SY”) should be prefixed for every Roll Number. For example, you can pass Input
with values like:
Students = [“TY01”, “TY02”, “SY01”, “SY05”, “SY04”, “TY03”, “SY02”, “TY04”, “SY03”, “TY05”]

Display the sitting arrangement status at the exam time. “ABSENT” should be marked at the place of the Roll Numbers of missing or absent students.

Example 1:

Input Values(Input format should be same as below)
TY01
TY02
SY01
SY05
SY04
TY03
SY02
TY04
SY03

Output Values
[TY01][SY01]
[TY02][SY02]
[TY03][SY03]
[TY04][SY04]
[ABSENT][SY05]

Note: Output should be in the format given in above example. If input values are more than M, display INVALID INPUT. If input value contains other than class SY or TY display INVALID INPUT.

Solution: In Java

import java.util.*;
import java.lang.*;
import java.io.*;

class Question
{
	public static void main (String[] args) throws Exception
	{
		// your code goes here
		Scanner sc = new Scanner(System.in);
		String[][] arr = new String[5][2];
		for(int i=0; i&lt;5; i++)
		    for(int j=0; j5) {
		        System.out.println("INVALID INPUT");
		        return;
		    }
		    if(s.charAt(0) != 'T' &amp;&amp; s.charAt(0) != 'S'){
		        System.out.println("INVALID INPUT");
		        return;
		    }
		    r = s.charAt(3) - '1';
		    if(s.charAt(0) == 'T')
		        c = 0;
		    else
		        c = 1;
		    arr[r] = s;
		    try {
		    s = sc.nextLine();
		    } catch(Exception e) {
		        break;
		    }
		}
		for(int i=0; i&lt;5; i++)
		    System.out.println(&quot;[&quot; + arr[i][0]+ &quot;][&quot;+arr[i][1]+&quot;]&quot;);
	}
}

Also Checkout

Recent Posts

Leave a Comment

Your email address will not be published. Required fields are marked *