1: Declare a constructor in the Student class and then create a new object named s1 (name - karan | roll number - 1056 | cgpa - 8.8) and call method displayProfile( ) below. Also, print details of percentage of s1 using findPercentage( ) method.
The findPercentage() method should be used in printing as 'Percentage of s1 is 88.0'.
2: Create two objects s1 & s2 of 'Square' class given below. Assign them the side-length of 10f and 20f respectively, and print their areas in separate lines.
3: et’s say you have two variables, a and b:
a is an int variable initialized to 6 and
b is a double variable initialized to 5.5
Now you want to add these two variables and print their sum, but you’re not interested in the decimal part of a + b.
Write a code that computes a + b and prints out only the whole number part of the result.
Create an object of the given Person class with parameterized constructor initializing the name variable to ‘Ankit’, and then to print the value of ‘name’ variable using getter method.
Create an object of the given Person class and initialise that object by assigning 'Ankit' to the 'name' variable using the setter method
Sample Solution