Skip to main content

Institution

 Problem Statement

Create a class Institution with below attributes:

institutionId - int institutionName - String noOfStudentsPlaced - String noOfStudentsCleared- int location - String grade - String

Write getters, setters for the above attributes. Create constructor which takes parameter in the above sequence except grade.

Create class Solution with main method. Implement two static methods - findNumClearancedByLoc and updateInstitutionGrade in Solution class.

findNumClearancedByLoc method: This method will take two input parameters - array of Institution objects and string parameter location. The method will return the sum of the noOfStudentsCleared attribute from institution objects for the location passed as parameter. If no institution with the given location is present in the array of institution objects, then the method should return 0.

updateInstitutionGrade method: This method will take a String parameter institutionName, along with the array of Institution objects. The method will return the institution object, if the input String parameter matches with the institutionName attribute of the institution object. Before returning the object, the grade should be arrived based on the rating calculation mentioned below. This grade value should be assigned to the object.If any of the above conditions are not met, then the method should return null.

The grade attribute should be calculated as follows: rating=(noOfStudentsPlaced * 100)/noOfStudentsCleared If the rating &gt= 80 , then grade should be 'A'. Else, then grade should be 'B'

Note: No institution object would have the same value for institutionName attribute. All institution object would have the noOfStudentsPlaced value lesser than noOfStudentsCleared value. All the searches should be case insensitive.

The above mentioned static methods should be called from the main method.

For findNumClearancedByLoc method - The main method should print the noOfClearance as it is, if the returned value is greater than 0, or it should print "There are no cleared students in this particular location".

For updateInstitutionGrade method - The main method should print the institutionName and grade of the returned Institution object. The instituationName and grade should be concatinated with :: while printing. eg:- TCS::A, where TCS is the institution name and A is the grade. If the returned value is nullthen it should print "No Institute is available with the specified name".

Before calling these static methods in main, use Scanner object to read the values of four Phone objects referring attributes in the above mentioned attribute sequence (except grade attribute). Next, read the value for location and institutionName.
Input

111
Amrita
5000
10000
Chennai
222
Karunya
16000
20000
Coimbatore
333
AppleTech
10000
12000
Chennai
444
Aruna
6000
10000
Vellore
Chennai
Karunya

Output

22000
Karunya::A

Starter Code

import java.util.Scanner
public class Solution
{

public static void main(String[] args)
{
//code to read values
//code to call required method
//code to display the result
}

public static int findNumClearancedByLoc(Institution[] instArray, String location)
{
//method logic
}

public static Institution updateInstitutionGrade(Institution[] instArray, String instName)
{
//method logic
}
}
class Institution
{
//code to build Institution class
}



code:

 

import java.util.Scanner;
public class Solution {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Institution[] instArray = new Institution[4];
        for(int i=0;i<4;i++){
            int institutionId = sc.nextInt();
            sc.nextLine();
            String institutionName = sc.nextLine();
            String noOfStudentsPlaced = sc.nextLine();
            int noOfStudentsCleared = sc.nextInt();
            sc.nextLine();
            String location= sc.nextLine();
            instArray[i] = new Institution(institutionId,institutionName,noOfStudentsPlaced,noOfStudentsCleared,location);
        }
        String location = sc.nextLine();
        String institutionName = sc.nextLine();
        sc.close();
        int noOfClearance = findNumClearancedByLoc(instArray, location);
        if(noOfClearance!=0) System.out.println(noOfClearance);
        else System.out.println("There are no cleared students in this particular location");
        
        Institution updated = updateInstitutionGrade(instArray, institutionName);
        if(updated!=null) System.out.println(updated.getInstitutionName()+"::"+updated.getGrade());
        else System.out.println("No Institute is available with the specified name");
    }
    
    public static int findNumClearancedByLoc(Institution[] instArray, String location)
    {
        int noOfClearance = 0;
        for(int i=0;i<instArray.length;i++){
            if(instArray[i].getLocation().equalsIgnoreCase(location)){
                noOfClearance += instArray[i].getNoOfStudentsCleared();
            }
        }
        return noOfClearance;
    }

    public static Institution updateInstitutionGrade(Institution[] instArray, String instName)
    {
        for(int i=0;i<instArray.length;i++){
            if(instArray[i].getInstitutionName().equalsIgnoreCase(instName)){
                int rating = ((Integer.parseInt(instArray[i].getNoOfStudentsPlaced())*100)/instArray[i].getNoOfStudentsCleared());
                if(rating>=80) instArray[i].setGrade("A");
                else instArray[i].setGrade("B");
                return instArray[i];
            }
        }
        return null;
  }
}

class Institution {
    int institutionId;
    String institutionName;
    String noOfStudentsPlaced;
    int noOfStudentsCleared;
    String location;
    String grade;

    Institution(int institutionId,String institutionName,String noOfStudentsPlaced,int noOfStudentsCleared,String location){
        this.institutionId = institutionId;
        this.institutionName = institutionName;
        this.noOfStudentsPlaced = noOfStudentsPlaced;
        this.noOfStudentsCleared = noOfStudentsCleared;
        this.location = location;
    }

    int getInstitutionId(){
        return institutionId;
    }

    String getInstitutionName(){
        return institutionName;
    }

    String getNoOfStudentsPlaced(){
        return noOfStudentsPlaced;
    }

    int getNoOfStudentsCleared(){
        return noOfStudentsCleared;
    }

    String getLocation(){
        return location;
    }

    String getGrade(){
        return grade;
    }


    void setInstitutionId(int institutionId){
        this.institutionId = institutionId;
    }

    void setInstitutionName(String institutionName){
        this.institutionName = institutionName;
    }

    void setNoOfStudentsPlaced(String noOfStudentsPlaced){
        this.noOfStudentsPlaced = noOfStudentsPlaced;
    }

    void setNoOfStudentsCleared(int noOfStudentsCleared){
        this.noOfStudentsCleared = noOfStudentsCleared;
    }

    void setLocation(String location){
        this.location = location;
    }

    void setGrade(String grade){
        this.grade = grade;
    }
}


Comments

Popular posts from this blog

How to Introduce Yourself to project team and client when you join a new project as fresher in service based company ?

Question:     How to Introduce Yourself to project team /client  when you join a new project as fresher ? Answer:  Hii Everyone,    Today I will be talking about how we can introduce ourselves to a team  when we join a new project in any servicebased company as a fresher.     After I completed my Engineering ,I got placed into TCS.I got allocated  into a project.I introduced myself to a team.So I will be telling about how   exactly I introduced myself to the team.The impressive introduction is  necessary if you want team members to treat you better in this work from  home period.If you fail to impress team members ,If your introduction is not  impressive ,then probably your team members will ignore you.    Before I tell you about how exactly I introduced myself,I would like  to talk about the points that you should remember before giving your  introduction. .start your introduction with Hii Ev...

Automating Infrastructure on Google Cloud with Terraform: Challenge Lab

As more and more organizations move to the cloud, the need for powerful infrastructure automation tools has never been greater. That's where Terraform comes in, a cutting-edge tool that allows you to automate the deployment, management, and scaling of your infrastructure with ease. With Terraform, you can define your entire infrastructure as code, making it easy to maintain, version, and reproduce. Whether you're deploying infrastructure to AWS, Google Cloud, or another cloud provider, Terraform provides a powerful and flexible platform for automating your workflows. In this blog post, we'll take a look at how to automate infrastructure on google cloud with terraform. Task A. Create the configuration files  Task B. Import infrastructure  Task C.Configure a remote backend  Task D. Modify and update infrastructure  Task E.Destroy resources  Task F. Use a module from the Registry  Task G. Configure a firewall ......................................................

TCS IRA 13 DECEMBER JAVA CODING QUESTION SOLUTION.

Create a class newspaper with below attributes. regNo-int name-String publicationYear-int price-int Write parametrised constructor as required. Create class Solution with main method. Implement 2 static methods findTotalPriceByPublicationYear and  searchNewspaperByName in solution class. findTotalPriceByPublicationYear method:    This method will take array of the Newspaper objects and int parameter type.This method will return the total price of newspapers from array of  Newspaper objects,If the publication year attribute matches with the int  parameter passed .If no Newspaper with the given publication year is present  in the array ,then the method should return 0. The main method should print total price if the returned value is greater  than 0.Else it should print "No Newspaper found with the mentioned attribute". searchNewspaperByName method :    This method will take the array of the Newspaper objects and the String  parameter type...