Python,C,C++ and JAVA programs for CBSE, ISC, B.Tech and I.T Computer Science and MCA students

The Programming Project: ISC COMPUTER SCIENCE PRACTIACL 2018 QUESTION 3 TEAM BANNER STRING

Tuesday, March 12, 2019

ISC COMPUTER SCIENCE PRACTIACL 2018 QUESTION 3 TEAM BANNER STRING

/*
The names of the teams participating in a competition should be displayed on a banner vertically, to accommodate as many teams as possible in a single banner.
Design a program to accept the names of N teams, where 2 < N < 9 and display them in vertical order, side by side with a horizontal tab (i.e. eight spaces).
Test your program for the following data and some random data:
Example 1:
INPUT: N = 3
Team 1: Emus
Team 2: Road Rols
Team 3: Coyote

OUTPUT:
E        R        C     

m        o        o     

u        a         y     

s        d         o     

                     t     

         R         e     

         o               

         l               

         s               


Example 2:
Enter the number of participating teams:
5
Enter name of Team1
England
Enter name of Team2
South Africa
Enter name of Team3
India
Enter name of Team4
Australia
Enter name of Team5
Sri lanka

OUTPUT:

E        S        I        A        S     

n        o        n        u        r     

g        u        d        s        i     

l        t          i        t               

a        h        a        r        l     

n                          a        a     

d        A                 l        n     

         f                 i        k     

         r                 a        a     

         i                                 

         c                                 

         a   
 */


import java.util.*;
       public class ISC2015Q1 {
             public static void main(String[] args) {
                    int N;
                    Scanner in = new Scanner(System.in);
                    System.out.println("Enter the number of participating teams:");
                    N = in.nextInt();
                    while( N<=2 || N>=9) {
                          System.out.println("Invalid input, try again:");
                          N = in.nextInt();
                    }
                    TeamName obj = new TeamName(N);
                    obj.InputTeamNames();
                    obj.TeamNameDisplay();
                    in.close();
             }
       }
       class TeamName{
             public void TeamNameDisplay() {
                    int i,max=0,k,j;
                    // finding the maximum name length among the given teams   Word_Storage[i] = new String(ch);
                    for(i=0;i<number_of_teams;i++) {
                          if(max<team_names[i].length())
                                 max = team_names[i].length();
                    }
                    // Adding blank Spaces to each name to make the length uniform
                    char[] temp;
                    for(k=0;k<number_of_teams;k++) {
                          temp = new char[max-team_names[k].length()];
                          for( j=0;j<max-team_names[k].length();j++)
                                 temp[j] +=' ';
                          String s;
                          s = new String(temp);
                          team_names[k] +=s;
                    }
                   
                    // displaying the name is required fashion
                    for(i=0;i<max;i++) {
                          for( j=0;j<number_of_teams;j++) {
                                 System.out.print(team_names[j].charAt(i)+"        ");
                          }
                          System.out.println();
                          System.out.println();
                    }
             }
             public void InputTeamNames() {
                    Scanner in = new Scanner(System.in);
                    for(int i=0;i<number_of_teams;i++) {
                          System.out.println("Enter name of Team"+(i+1));
                          team_names[i]=in.nextLine();
                    }
                    in.close();
             }
             TeamName(int N){
                    number_of_teams = N;
                    team_names = new String[number_of_teams];
             }
             private String[] team_names;
             private int number_of_teams;
       }
                   

No comments:

Post a Comment