Question: code for part1 is: class firstClass{ //each object of this class represent a person String name,gender; int age; public firstClass() { //default constructor System.out.println(Inside default
code for part1 is:
class firstClass{ //each object of this class represent a person String name,gender; int age; public firstClass() { //default constructor System.out.println("Inside default constructor"); } public firstClass(String n,String g, int a) { //constructor with argments name=n; gender=g; age=a; } //getter and setter functions public String getName() { return name; } public void setName(String name) { this.name = name; } public String getGender() { return gender; } public void setGender(String gender) { this.gender = gender; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } //methods which perform some operation on data void fiveYearsLater() { age+=5; //add 5 years to age } void display() { //display person details System.out.println("Name of the person is: "+name); System.out.println("Age of the person is: "+age); System.out.println("Gender of ther person is: "+gender); } } public class testClass { public static void main(String[] args) { firstClass object1=new firstClass(); //created using default constructor firstClass object2=new firstClass("david", "male", 21); //created using parametrized constructor object1.setName("Sharma"); //set values for object1 using setter functions object1.setGender("male"); object1.setAge(25); object1.display(); object1.fiveYearsLater(); object1.display(); //observe the age changes here object2.display(); } } -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Part 3 (Abstract Class and Interface) (6 marks)
Consider the Class that you designed in Part#1 of this project and do the following:
- Implement the Comparable and Cloneable interface for your class.
- The Test class should create 5 instances (objects) of your class.
- Store these instances in Array and ArrayList
- Show the demo of sorting these objects stored in Array and ArrayList
Include the below in your project report:
- Screenshot of relevant (Comparable and Cloneable) outputs.
- Code for all classes.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
