The Programming Project

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;
       }
                   

ISC COMPUTER SCIENCE PRACTICAL 2018 QUESTION 2 : (MATRIX ROW SORT)

/*
 Write a program to declare a matrix A[ ] [ ] of order (M xN) where ‘M’ is the number of rows and ‘N’ is the number of columns such that the values of both ‘M’
 and ‘N’ must be greater than 2 and less than 10.
 Allow the user to input integers into this matrix. Perform the following tasks on the matrix:
(a) Display the original matrix.
(b) Sort each row of the matrix in ascending order using any standard sorting technique.
(c) Display the changed matrix after sorting each row. Test your program for the following data and some random data:
 */
JAVA SOURCE CODE


import java.util.*;
public class ISC2018Q2 {
       public static void main(String[] args) {
             int N,M;
             Scanner in = new Scanner(System.in);
             System.out.println("Enter the ORDER of the matrix (MXN):");
             M = in.nextInt();
             N = in.nextInt();
             while( M <=2 || M >= 10 || N <=2 || N >= 10 ) {
                    System.out.println("INVALID INPUT:");
                    System.out.println("Enter the ORDER of the matrix (MXN):");
                    M = in.nextInt();
                    N = in.nextInt();
                    }
             Matrix obj = new Matrix(M,N);
             obj.inputElements();
             System.out.println("ORIGINAL MATRIX:");
             obj.displayMatrix();
             obj.SortMatrix();
             System.out.println("Changed Matrix (after sorting row):");
             obj.displayMatrix();
             in.close();
             }
       }
      
class Matrix{
       Matrix(int M,int N){
             row=M;
             coloumn=N;
             Mat = new int[row][coloumn];
       }
      
       public void SortMatrix() {
             for (int k =0;k<row;k++) {
                    int temp;
                    for (int i =0;i<coloumn;i++) {
                          for(int j=i;j<coloumn;j++) {
                                 if(Mat[k][i]>Mat[k][j]) {
                                       temp = Mat[k][j];
                                       Mat[k][j]=Mat[k][i];
                                       Mat[k][i]=temp;
                                 }
                          }
                    }
                    //Arrays.sort(Mat[i]); you can use these library function
                    // to avoid writing the bubble sort unless the question specify, which the case is in this problem
             }
       }
      
       public void displayMatrix() {
             for(int i = 0; i < row; i++) {
                    for(int j = 0; j < coloumn; j++) {
                          System.out.print(Mat[i][j]+"  ");
                    }
                    System.out.println();
             }
       }
      
       public void inputElements() {
             Scanner in = new Scanner(System.in);
             System.out.println("Enter the elements of the matrix");
             for(int i = 0; i < row; i++) {
                    for(int j = 0; j < coloumn; j++) {
                          Mat[i][j]= in.nextInt();
                    }
             }
            
       }
       private int[][] Mat;
       private int row;
       private int coloumn;
       }