Question Index

Given a Java Bean, write a program to create the getters and setters method content. Note that you need to use reflection api to do this. The fields should be sorted by name. If it is boolean datatype, you need to use 'is' instead of 'get'.

Input (Object) Output (String)
new Student() public boolean isGender(){return gender;}
public void setGender(boolean gender){this.gender = gender;}
public int getId(){return id;}
public void setId(int id){ = id;}
public int getMarks(){return marks;}
public void setMarks(int marks){this.marks = marks;}
public String getName(){return name;}
public void setName(String name){ = name;}
public double getPercentage(){return percentage;}
public void setPercentage(double percentage){this.percentage = percentage;}
public char getSection(){return section;}
public void setSection(char section){this.section = section;}
new Employee() public String getDesignation(){return designation;}
public void setDesignation(String designation){this.designation = designation;}
public boolean isGender(){return gender;}
public void setGender(boolean gender){this.gender = gender;}
public String getName(){return name;}
public void setName(String name){ = name;}
public double getSalary(){return salary;}
public void setSalary(double salary){this.salary = salary;}
new Mobile() public String getCompanyName(){return companyName;}
public void setCompanyName(String companyName){this.companyName = companyName;}
public float getPixel(){return pixel;}
public void setPixel(float pixel){this.pixel = pixel;}
public double getPrice(){return price;}
public void setPrice(double price){this.price = price;}
public int getResolution(){return resolution;}
public void setResolution(int resolution){this.resolution = resolution;}
new College() public String getAddress(){return address;}
public void setAddress(String address){this.address = address;}
public String getCollegeCode(){return collegeCode;}
public void setCollegeCode(String collegeCode){this.collegeCode = collegeCode;}
public String getCollegeName(){return collegeName;}
public void setCollegeName(String collegeName){this.collegeName = collegeName;}
public int getStudents(){return students;}
public void setStudents(int students){this.students = students;}

class CreateGettersAndSettersWithMethodContent

{    public static void main(String s[])
        Student student = new Student();
        String result = createSettersAndGetters(student);


public static String createSettersAndGetters(Object object) {
//Write code here to create getters and setters method content

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

String name;
boolean gender;
int marks;
double percentage;
char section;
int id;

class Employee {

double salary;
String name;
String designation;
boolean gender;

class Mobile {

String companyName;
double price;
float pixel;
int resolution;

class College {

int students;
String collegeCode;
String address;
String collegeName;



Topic: Java Regular Expression

Read this topic
Take test on this topic

Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App