Menu
Question Index
...


Write a program to convert the given object into a string. Note that you need to use reflection api to do this. If present, the id field should be placed at the beginning and the rest of fields should be sorted. If the field contains capital letter then add one space before and make first letter as capital. If field contains any number then add one space before and equals to the field value with spaces as shown in below.

Input (Object) Output (String)
College object
------------------
numberOfStudents=75896
numberOfBranches=6
numberOfFaculty=1200
numberOfStudentsScoredMoreThanPercent80=65200
grade='A'
collegeCode="RITA"
collegeAddress="B K Samudram Mandal-Anantapur"
nameOfTheCollege="Srinivasa Ramanujan Institute of Technology"
College Address = "B K Samudram Mandal-Anantapur"
College Code = "RITA"
Grade = 'A'
Name Of The College = "Srinivasa Ramanujan Institute of Technology"
Number Of Branches = 6
Number Of Faculty = 1200
Number Of Students = 75896
Number Of Students Scored More Than Percent 80 = 65200
Student object
------------------
nameOfPerson="Mahesh Babu"
genderOfPerson=true
marksObtained=550
percentageGot=91.6
belongsToSection='A'
studentId=516
Student Id = 516
Belongs To Section = 'A'
Gender Of Person = true
Marks Obtained = 550
Name Of Person = "Mahesh Babu"
Percentage Got = 91.6
Employee object
------------------
salaryPerMonth=200000
nameOfEmployee="Oleti Kiran Kumar"
designationInCompany="Software Engineer"
employeeId=516
genderOfEmployee=true
Employee Id = 516
Designation In Company = "Software Engineer"
Gender Of Employee = true
Name Of Employee = "Oleti Kiran Kumar"
Salary Per Month = 200000.0
Company object
------------------
nameOfTheCompany="Infosys Technologies"
numberOfEmployees=3000
totalWorkingDaysPer1Year=200
turnOverPer01Years=1000000.0
companyId=3546
companyLocationInIndia="Plot No. 44, Hosur Road, Electronics City, Bengaluru, Karnataka, 560100"
chairPersonName="Kiran Kumar"
numberOfDepartments=25
Company Id = 3546
Chair Person Name = "Kiran Kumar"
Company Location In India = "Plot No. 44, Hosur Road, Electronics City, Bengaluru, Karnataka, 560100"
Name Of The Company = "Infosys Technologies"
Number Of Departments = 25
Number Of Employees = 3000
Total Working Days Per 1 Year = 200
Turn Over Per 01 Years = 1000000.0

class ConvertObjectToString

{    public static void main(String s[])
    {
        College college = new College();
        college.numberOfStudents = 75896;
        college.numberOfBranches = 6;
        college.numberOfFaculty = 1200;
        college.collegeCode = "RITA";
        college.grade = 'A';
        college.numberOfStudentsScoredMoreThanPercent80 = 65200;
        college.collegeAddress = "B K Samudram Mandal-Anantapur";
        college.nameOfTheCollege = "Srinivasa Ramanujan Institute of Technology";
        String query = convertObjectToString(college);
        System.out.println(query);

    }


public static String convertObjectToString(Object object) {
String result = null;
//Write code here to convert the given object to string
return result;
}

//If required write any additional methods here
}
class Student {

String nameOfPerson;
boolean genderOfPerson;
int marksObtained;
double percentageGot;
char belongsToSection;
int studentId;
}

class Employee {

double salaryPerMonth;
String nameOfEmployee;
String designationInCompany;
int employeeId;
boolean genderOfEmployee;
}

class Company {

String nameOfTheCompany;
int numberOfEmployees;
int totalWorkingDaysPer1Year;
double turnOverPer01Years;
int companyId;
String companyLocationInIndia;
String chairPersonName;
int numberOfDepartments;
}

class Mobile {

String companyName;
String modelName;
double mobilePrice;
double memoryCapacity;
float cameraPixel;
String screenResolution;
}

class College {

int numberOfStudents;
int numberOfBranches;
int numberOfFaculty;
int numberOfStudentsScoredMoreThanPercent80;
char grade;
String collegeCode;
String collegeAddress;
String nameOfTheCollege;
}

class Hotel {

String hotelName;
int numberOfChairsAndTables;
int numberOfWorkers;
String hotelTimings;
String hotelLocationWithDoorNumber;
long landLineNumberStartsWithAreaCode8554;
}

Doubts

Problems

Topic: Other Advanced Topics In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App